mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
tb -trees ; rl ; path in gfe ; removed spurious "file not found"
This commit is contained in:
@@ -14,6 +14,24 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
|
1/3 (AR) Added option <tt>-trees</tt> to the command <tt>tree_bank = tb</tt>.
|
||||||
|
By this option, the command just returns the trees in the treebank. It can be
|
||||||
|
used for producing new treebanks with the same trees:
|
||||||
|
<pre>
|
||||||
|
rf old.xml | tb -trees | tb -xml | wf new.xml
|
||||||
|
</pre>
|
||||||
|
Recall that only treebanks in the XML format can be read with the <tt>-trees</tt>
|
||||||
|
and <tt>-c</tt> flags.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
1/3 (AR) A <tt>.gfe</tt> file can have a <tt>--# -path=PATH</tt> on its
|
||||||
|
second line. The file given on the first line (<tt>--# -resource=FILE</tt>)
|
||||||
|
is then read w.r.t. this path. This is useful if the resource file has
|
||||||
|
no path itself, which happens when it is gfc-only.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
25/2 (AR) The flag <tt>preproc</tt> of the <tt>i</tt> command (and thereby
|
25/2 (AR) The flag <tt>preproc</tt> of the <tt>i</tt> command (and thereby
|
||||||
to <tt>gf</tt> itself) causes GF to apply a preprocessor to each sourcefile
|
to <tt>gf</tt> itself) causes GF to apply a preprocessor to each sourcefile
|
||||||
it reads.
|
it reads.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
-- File generated by GF from QuestionsI.gfe
|
-- File generated by GF from QuestionsI.gfe
|
||||||
--# -resource=../../lib/resource-1.0/english/LangEng.gf
|
--# -resource=../../lib/resource-1.0/english/LangEng.gf
|
||||||
|
--# -path=.:present:prelude
|
||||||
|
|
||||||
-- to compile: gf -examples QuestionsI.gfe
|
-- to compile: gf -examples QuestionsI.gfe
|
||||||
-- or use directly gf <mkAnimals.gfs
|
-- or use directly gf <mkAnimals.gfs
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
--# -resource=../../lib/resource-1.0/english/LangEng.gf
|
--# -resource=../../lib/resource-1.0/english/LangEng.gf
|
||||||
|
--# -path=.:present:prelude
|
||||||
|
|
||||||
-- to compile: gf -examples QuestionsI.gfe
|
-- to compile: gf -examples QuestionsI.gfe
|
||||||
-- or use directly gf <mkAnimals.gfs
|
-- or use directly gf <mkAnimals.gfs
|
||||||
|
|||||||
@@ -55,12 +55,13 @@ mkConcretes files = do
|
|||||||
ress <- mapM getResPath files
|
ress <- mapM getResPath files
|
||||||
let grps = groupBy (\a b -> fst a == fst b) $
|
let grps = groupBy (\a b -> fst a == fst b) $
|
||||||
sortBy (\a b -> compare (fst a) (fst b)) $ zip ress files
|
sortBy (\a b -> compare (fst a) (fst b)) $ zip ress files
|
||||||
mapM_ mkCncGroups [(r,map snd gs) | gs@((r,_):_) <- grps]
|
mapM_ mkCncGroups [(rp,map snd gs) | gs@((rp,_):_) <- grps]
|
||||||
|
|
||||||
mkCncGroups (res,files) = do
|
mkCncGroups ((res,path),files) = do
|
||||||
putStrLnFlush $ "Going to preprocess examples in " ++ unwords files
|
putStrLnFlush $ "Going to preprocess examples in " ++ unwords files
|
||||||
putStrLn $ "Compiling resource " ++ res
|
putStrLn $ "Compiling resource " ++ res
|
||||||
egr <- appIOE $ shellStateFromFiles (options [beSilent]) emptyShellState res
|
let opts = options [beSilent,pathList path]
|
||||||
|
egr <- appIOE $ shellStateFromFiles opts emptyShellState res
|
||||||
gr <- err (\s -> putStrLn s >> error "resource grammar rejected")
|
gr <- err (\s -> putStrLn s >> error "resource grammar rejected")
|
||||||
(return . firstStateGrammar) egr
|
(return . firstStateGrammar) egr
|
||||||
let parser cat =
|
let parser cat =
|
||||||
@@ -81,12 +82,18 @@ mkConcrete parser morpho file = do
|
|||||||
appendFile out "\n"
|
appendFile out "\n"
|
||||||
mapM_ (mkCnc out parser morpho) cont
|
mapM_ (mkCnc out parser morpho) cont
|
||||||
|
|
||||||
getResPath :: FilePath -> IO String
|
getResPath :: FilePath -> IO (String,String)
|
||||||
getResPath file = do
|
getResPath file = do
|
||||||
s <- liftM lines $ readFileIf file
|
s <- liftM lines $ readFileIf file
|
||||||
return $ case head (dropWhile (all isSpace) s) of
|
case filter (not . all isSpace) s of
|
||||||
'-':'-':'#':path -> reverse (takeWhile (not . (=='=')) (reverse path))
|
res:path:_ | is "resource" res && is "path" path -> return (val res, val path)
|
||||||
_ -> error "first line must be --# -resource=<PATH>"
|
res:_ | is "resource" res -> return (val res, "")
|
||||||
|
_ -> error "expected --# -resource=FILE and optional --# -path=PATH"
|
||||||
|
where
|
||||||
|
val = dropWhile (isSpace) . tail . dropWhile (not . (=='='))
|
||||||
|
is tag s = case words s of
|
||||||
|
"--#":w:_ -> isPrefixOf ('-':tag) w
|
||||||
|
_ -> False
|
||||||
|
|
||||||
getExLines :: String -> [Either String String]
|
getExLines :: String -> [Either String String]
|
||||||
getExLines = getl . lines where
|
getExLines = getl . lines where
|
||||||
|
|||||||
@@ -372,6 +372,10 @@ morphoOfLang st = stateMorpho . stateGrammarOfLang st
|
|||||||
probsOfLang st = stateProbs . stateGrammarOfLang st
|
probsOfLang st = stateProbs . stateGrammarOfLang st
|
||||||
optionsOfLang st = stateOptions . stateGrammarOfLang st
|
optionsOfLang st = stateOptions . stateGrammarOfLang st
|
||||||
|
|
||||||
|
removeLang :: Language -> ShellState -> ShellState
|
||||||
|
removeLang lang st = purgeShellState $ st{concretes = concs1} where
|
||||||
|
concs1 = filter ((/=lang) . snd . fst) $ concretes st
|
||||||
|
|
||||||
-- | the last introduced grammar, stored in options, is the default for operations
|
-- | the last introduced grammar, stored in options, is the default for operations
|
||||||
firstStateGrammar :: ShellState -> StateGrammar
|
firstStateGrammar :: ShellState -> StateGrammar
|
||||||
firstStateGrammar st = errVal (stateAbstractGrammar st) $ do
|
firstStateGrammar st = errVal (stateAbstractGrammar st) $ do
|
||||||
|
|||||||
@@ -256,7 +256,8 @@ showMulti = iOpt "multi"
|
|||||||
fromSource = iOpt "src"
|
fromSource = iOpt "src"
|
||||||
makeConcrete = iOpt "examples"
|
makeConcrete = iOpt "examples"
|
||||||
fromExamples = iOpt "ex"
|
fromExamples = iOpt "ex"
|
||||||
openEditor = iOpt "edit"
|
openEditor = iOpt "edit"
|
||||||
|
getTrees = iOpt "trees"
|
||||||
|
|
||||||
-- ** mainly for stand-alone
|
-- ** mainly for stand-alone
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,11 @@ isSep :: Char -> Bool
|
|||||||
isSep c = c == '/' || c == '\\'
|
isSep c = c == '/' || c == '\\'
|
||||||
|
|
||||||
getFilePath :: [FilePath] -> String -> IO (Maybe FilePath)
|
getFilePath :: [FilePath] -> String -> IO (Maybe FilePath)
|
||||||
getFilePath paths file = get paths where
|
getFilePath ps file = getFilePathMsg ("file" +++ file +++ "not found\n") ps file
|
||||||
get [] = putStrLnFlush ("file" +++ file +++ "not found") >> return Nothing
|
|
||||||
|
getFilePathMsg :: String -> [FilePath] -> String -> IO (Maybe FilePath)
|
||||||
|
getFilePathMsg msg paths file = get paths where
|
||||||
|
get [] = putStrFlush msg >> return Nothing
|
||||||
get (p:ps) = let pfile = prefixPathName p file in
|
get (p:ps) = let pfile = prefixPathName p file in
|
||||||
catch (readFile pfile >> return (Just pfile)) (\_ -> get ps)
|
catch (readFile pfile >> return (Just pfile)) (\_ -> get ps)
|
||||||
|
|
||||||
@@ -104,7 +107,7 @@ readFileIfPath paths file = do
|
|||||||
|
|
||||||
doesFileExistPath :: [FilePath] -> String -> IOE Bool
|
doesFileExistPath :: [FilePath] -> String -> IOE Bool
|
||||||
doesFileExistPath paths file = do
|
doesFileExistPath paths file = do
|
||||||
mpfile <- ioeIO $ getFilePath paths file
|
mpfile <- ioeIO $ getFilePathMsg "" paths file
|
||||||
return $ maybe False (const True) mpfile
|
return $ maybe False (const True) mpfile
|
||||||
|
|
||||||
-- | first var is lib prefix, second is like class path
|
-- | first var is lib prefix, second is like class path
|
||||||
|
|||||||
@@ -193,8 +193,8 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com
|
|||||||
CChangeMain ma -> changeStateErr (changeMain ma) sa
|
CChangeMain ma -> changeStateErr (changeMain ma) sa
|
||||||
CStripState -> changeState purgeShellState sa
|
CStripState -> changeState purgeShellState sa
|
||||||
|
|
||||||
|
CRemoveLanguage lan -> changeState (removeLang lan) sa
|
||||||
{-
|
{-
|
||||||
CRemoveLanguage lan -> changeState (removeLanguage lan) sa
|
|
||||||
CTransformGrammar file -> do
|
CTransformGrammar file -> do
|
||||||
s <- transformGrammarFile opts file
|
s <- transformGrammarFile opts file
|
||||||
returnArg (AString s) sa
|
returnArg (AString s) sa
|
||||||
@@ -293,6 +293,11 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com
|
|||||||
CTreeBank | oElem doCompute opts -> do -- -c
|
CTreeBank | oElem doCompute opts -> do -- -c
|
||||||
let bank = prCommandArg a
|
let bank = prCommandArg a
|
||||||
returnArg (AString $ unlines $ testTreebank opts st bank) sa
|
returnArg (AString $ unlines $ testTreebank opts st bank) sa
|
||||||
|
CTreeBank | oElem getTrees opts -> do -- -trees
|
||||||
|
let bank = prCommandArg a
|
||||||
|
tes = map (string2treeErr gro) $ treesTreebank opts bank
|
||||||
|
terms = [t | Ok t <- tes]
|
||||||
|
returnArg (ATrms terms) sa
|
||||||
CTreeBank -> do
|
CTreeBank -> do
|
||||||
let ts = strees $ s2t $ snd sa
|
let ts = strees $ s2t $ snd sa
|
||||||
comm = "command" ----
|
comm = "command" ----
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ txtHelpFile =
|
|||||||
"\n i English.gf -- ordinary import of Concrete" ++
|
"\n i English.gf -- ordinary import of Concrete" ++
|
||||||
"\n i -retain german/ParadigmsGer.gf -- import of Resource to test" ++
|
"\n i -retain german/ParadigmsGer.gf -- import of Resource to test" ++
|
||||||
"\n " ++
|
"\n " ++
|
||||||
"\n* rl, remove_language: rl Language" ++
|
"\nrl, remove_language: rl Language" ++
|
||||||
"\n Takes away the language from the state." ++
|
"\n Takes away the language from the state." ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"\ne, empty: e" ++
|
"\ne, empty: e" ++
|
||||||
@@ -236,10 +236,12 @@ txtHelpFile =
|
|||||||
"\n to an existing treebank." ++
|
"\n to an existing treebank." ++
|
||||||
"\n options:" ++
|
"\n options:" ++
|
||||||
"\n -c compare to existing xml-formatted treebank" ++
|
"\n -c compare to existing xml-formatted treebank" ++
|
||||||
|
"\n -trees return the trees of the treebank" ++
|
||||||
"\n -xml wrap the treebank (or comparison results) with XML tags" ++
|
"\n -xml wrap the treebank (or comparison results) with XML tags" ++
|
||||||
"\n examples:" ++
|
"\n examples:" ++
|
||||||
"\n gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file" ++
|
"\n gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file" ++
|
||||||
"\n rf tb.txt | tb -c -- read comparison treebank from file" ++
|
"\n rf tb.xml | tb -c -- compare-test treebank from file" ++
|
||||||
|
"\n rf old.xml | tb -trees | tb -xml -- create new treebank from old" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"\ntt, test_tokenizer: tt String" ++
|
"\ntt, test_tokenizer: tt String" ++
|
||||||
"\n Show the token list sent to the parser when String is parsed." ++
|
"\n Show the token list sent to the parser when String is parsed." ++
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ optionsOfCommand co = case co of
|
|||||||
CGenerateRandom -> both "cf prob" "cat lang number depth"
|
CGenerateRandom -> both "cf prob" "cat lang number depth"
|
||||||
CGenerateTrees -> both "metas" "atoms depth alts cat lang number"
|
CGenerateTrees -> both "metas" "atoms depth alts cat lang number"
|
||||||
CPutTerm -> flags "transform number"
|
CPutTerm -> flags "transform number"
|
||||||
CTreeBank -> opts "c xml"
|
CTreeBank -> opts "c xml trees"
|
||||||
CWrapTerm _ -> opts "c"
|
CWrapTerm _ -> opts "c"
|
||||||
CApplyTransfer _ -> flags "lang transfer"
|
CApplyTransfer _ -> flags "lang transfer"
|
||||||
CMorphoAnalyse -> both "short" "lang"
|
CMorphoAnalyse -> both "short" "lang"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
-- Purpose: to generate treebanks.
|
-- Purpose: to generate treebanks.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.UseGrammar.Treebank (mkTreebank,testTreebank) where
|
module GF.UseGrammar.Treebank (mkTreebank,testTreebank,treesTreebank) where
|
||||||
|
|
||||||
import GF.Compile.ShellState
|
import GF.Compile.ShellState
|
||||||
import GF.UseGrammar.Linear (linTree2string)
|
import GF.UseGrammar.Linear (linTree2string)
|
||||||
@@ -49,7 +49,9 @@ mkTreebank opts sh com trees = putInXML opts "treebank" comm (concatMap mkItem t
|
|||||||
tris = zip trees [1..]
|
tris = zip trees [1..]
|
||||||
|
|
||||||
testTreebank :: Options -> ShellState -> String -> Res
|
testTreebank :: Options -> ShellState -> String -> Res
|
||||||
testTreebank opts sh = putInXML opts "testtreebank" [] . concatMap testOne . getTreebank . lines
|
testTreebank opts sh = putInXML opts "testtreebank" [] .
|
||||||
|
concatMap testOne .
|
||||||
|
getTreebanks . lines
|
||||||
where
|
where
|
||||||
testOne (e,lang,str0) = do
|
testOne (e,lang,str0) = do
|
||||||
let tr = annot gr e
|
let tr = annot gr e
|
||||||
@@ -61,6 +63,10 @@ testTreebank opts sh = putInXML opts "testtreebank" [] . concatMap testOne . get
|
|||||||
]
|
]
|
||||||
gr = firstStateGrammar sh
|
gr = firstStateGrammar sh
|
||||||
|
|
||||||
|
treesTreebank :: Options -> String -> [String]
|
||||||
|
treesTreebank _ = terms . getTreebank . lines where
|
||||||
|
terms ts = [t | (t,_) <- ts]
|
||||||
|
|
||||||
-- string vs. IO
|
-- string vs. IO
|
||||||
type Res = [String] -- IO ()
|
type Res = [String] -- IO ()
|
||||||
puts :: String -> Res
|
puts :: String -> Res
|
||||||
@@ -68,18 +74,23 @@ puts = return -- putStrLn
|
|||||||
ret = [] -- return ()
|
ret = [] -- return ()
|
||||||
--
|
--
|
||||||
|
|
||||||
getTreebank :: [String] -> [(String,String,String)]
|
getTreebanks :: [String] -> [(String,String,String)]
|
||||||
|
getTreebanks = concatMap grps . getTreebank where
|
||||||
|
grps (t,lls) = [(t,x,y) | (x,y) <- lls]
|
||||||
|
|
||||||
|
getTreebank :: [String] -> [(String,[(String,String)])]
|
||||||
getTreebank ll = case ll of
|
getTreebank ll = case ll of
|
||||||
[] -> []
|
l:ls@(_:_:_) ->
|
||||||
l:ls ->
|
|
||||||
let (l1,l2) = getItem ls
|
let (l1,l2) = getItem ls
|
||||||
(tr,lins) = getTree l1
|
(tr,lins) = getTree l1
|
||||||
lglins = getLins lins
|
lglins = getLins lins
|
||||||
in [(tr,lang,str) | (lang,str) <- lglins] ++ getTreebank l2
|
in (tr,lglins) : getTreebank l2
|
||||||
|
_ -> []
|
||||||
where
|
where
|
||||||
getItem = span ((/="</item") . take 6)
|
getItem = span ((/="</item") . take 6)
|
||||||
|
|
||||||
getTree (_:ss) = let (t1,t2) = span ((/="</tree") . take 6) ss in (last t1, drop 1 t2)
|
getTree (_:ss) =
|
||||||
|
let (t1,t2) = span ((/="</tree") . take 6) ss in (last t1, drop 1 t2)
|
||||||
|
|
||||||
getLins (beg:str:end:ss) = (getLang beg, str):getLins ss
|
getLins (beg:str:end:ss) = (getLang beg, str):getLins ss
|
||||||
getLins _ = []
|
getLins _ = []
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ i, import: i File
|
|||||||
i English.gf -- ordinary import of Concrete
|
i English.gf -- ordinary import of Concrete
|
||||||
i -retain german/ParadigmsGer.gf -- import of Resource to test
|
i -retain german/ParadigmsGer.gf -- import of Resource to test
|
||||||
|
|
||||||
* rl, remove_language: rl Language
|
rl, remove_language: rl Language
|
||||||
Takes away the language from the state.
|
Takes away the language from the state.
|
||||||
|
|
||||||
e, empty: e
|
e, empty: e
|
||||||
@@ -207,10 +207,12 @@ tb, tree_bank: tb
|
|||||||
to an existing treebank.
|
to an existing treebank.
|
||||||
options:
|
options:
|
||||||
-c compare to existing xml-formatted treebank
|
-c compare to existing xml-formatted treebank
|
||||||
|
-trees return the trees of the treebank
|
||||||
-xml wrap the treebank (or comparison results) with XML tags
|
-xml wrap the treebank (or comparison results) with XML tags
|
||||||
examples:
|
examples:
|
||||||
gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file
|
gr -cat=S -number=100 | tb -xml | wf tb.xml -- random treebank into file
|
||||||
rf tb.txt | tb -c -- read comparison treebank from file
|
rf tb.xml | tb -c -- compare-test treebank from file
|
||||||
|
rf old.xml | tb -trees | tb -xml -- create new treebank from old
|
||||||
|
|
||||||
tt, test_tokenizer: tt String
|
tt, test_tokenizer: tt String
|
||||||
Show the token list sent to the parser when String is parsed.
|
Show the token list sent to the parser when String is parsed.
|
||||||
|
|||||||
Reference in New Issue
Block a user