forked from GitHub/gf-core
allow spaces between command options; option -treebank in linearize
This commit is contained in:
@@ -133,16 +133,12 @@ allCommands pgf = Map.fromList [
|
|||||||
("l", emptyCommandInfo {
|
("l", emptyCommandInfo {
|
||||||
longname = "linearize",
|
longname = "linearize",
|
||||||
synopsis = "convert an abstract syntax expression to string",
|
synopsis = "convert an abstract syntax expression to string",
|
||||||
explanation = "Shows all linearization forms of Tree by the actual grammar\n"++
|
explanation = unlines [
|
||||||
"(which is overridden by the -lang flag).\n"++
|
"Shows the linearization of a Tree by the actual grammar",
|
||||||
"The pattern list has the form [P, ... ,Q] where P,...,Q follow GF\n"++
|
"(which is overridden by the -lang flag)."
|
||||||
"syntax for patterns. All those forms are generated that match with the\n"++
|
],
|
||||||
"pattern list. Too short lists are filled with variables in the end.\n"++
|
|
||||||
"Only the -table flag is available if a pattern list is specified.\n"++
|
|
||||||
"HINT: see GF language specification for the syntax of Pattern and Term.\n"++
|
|
||||||
"You can also copy and past parsing results.",
|
|
||||||
exec = \opts -> return . fromStrings . map (optLin opts),
|
exec = \opts -> return . fromStrings . map (optLin opts),
|
||||||
options = ["all","record","table","term"],
|
options = ["all","record","table","term", "treebank"],
|
||||||
flags = ["lang"]
|
flags = ["lang"]
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -207,7 +203,11 @@ allCommands pgf = Map.fromList [
|
|||||||
lin opts t = unlines [linearize pgf lang t | lang <- optLangs opts]
|
lin opts t = unlines [linearize pgf lang t | lang <- optLangs opts]
|
||||||
par opts s = concat [parse pgf lang (optCat opts) s | lang <- optLangs opts]
|
par opts s = concat [parse pgf lang (optCat opts) s | lang <- optLangs opts]
|
||||||
|
|
||||||
optLin opts t = unlines [linea lang t | lang <- optLangs opts] where
|
optLin opts t = case opts of
|
||||||
|
_ | isOpt "treebank" opts -> unlines $ (abstractName pgf ++ ": " ++ showExp t) :
|
||||||
|
[lang ++ ": " ++ linea lang t | lang <- optLangs opts]
|
||||||
|
_ -> unlines [linea lang t | lang <- optLangs opts]
|
||||||
|
where
|
||||||
linea lang = case opts of
|
linea lang = case opts of
|
||||||
_ | isOpt "all" opts -> allLinearize pgf (mkCId lang)
|
_ | isOpt "all" opts -> allLinearize pgf (mkCId lang)
|
||||||
_ | isOpt "table" opts -> tableLinearize pgf (mkCId lang)
|
_ | isOpt "table" opts -> tableLinearize pgf (mkCId lang)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ interpret env trees0 comm = case lookCommand co comms of
|
|||||||
comms = commands env
|
comms = commands env
|
||||||
checkOpts info =
|
checkOpts info =
|
||||||
case
|
case
|
||||||
[o | OOpt o <- opts, notElem o (options info)] ++
|
[o | OOpt o <- opts, notElem o ("tr" : options info)] ++
|
||||||
[o | OFlag o _ <- opts, notElem o (flags info)]
|
[o | OFlag o _ <- opts, notElem o (flags info)]
|
||||||
of
|
of
|
||||||
[] -> return ()
|
[] -> return ()
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ pPipe = RP.sepBy (RP.skipSpaces >> pCommand) (RP.skipSpaces >> RP.char '|')
|
|||||||
pCommand = do
|
pCommand = do
|
||||||
cmd <- pIdent
|
cmd <- pIdent
|
||||||
RP.skipSpaces
|
RP.skipSpaces
|
||||||
opts <- RP.many pOption
|
opts <- RP.sepBy pOption RP.skipSpaces
|
||||||
|
-- opts <- RP.many pOption
|
||||||
arg <- RP.option ANoArg (fmap AExp (pExp False))
|
arg <- RP.option ANoArg (fmap AExp (pExp False))
|
||||||
return (Command cmd opts arg)
|
return (Command cmd opts arg)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module PGF.Morphology where
|
module PGF.Morphology where
|
||||||
|
|
||||||
import PGF.ShowLinearize
|
import PGF.ShowLinearize (collectWords)
|
||||||
import PGF.Data
|
import PGF.Data
|
||||||
import PGF.CId
|
import PGF.CId
|
||||||
|
|
||||||
@@ -30,17 +30,3 @@ type Analysis = String
|
|||||||
noAnalysis :: [(Lemma,Analysis)]
|
noAnalysis :: [(Lemma,Analysis)]
|
||||||
noAnalysis = []
|
noAnalysis = []
|
||||||
|
|
||||||
collectWords :: PGF -> CId -> [(String, [(Lemma,Analysis)])]
|
|
||||||
collectWords pgf lang =
|
|
||||||
concatMap collOne
|
|
||||||
[(f,c,0) | (f,(DTyp [] c _,_)) <- Map.toList $ funs $ abstract pgf]
|
|
||||||
where
|
|
||||||
collOne (f,c,i) =
|
|
||||||
fromRec f [prCId c] (recLinearize pgf lang (EApp f (replicate i (EMeta 888))))
|
|
||||||
fromRec f v r = case r of
|
|
||||||
RR rs -> concat [fromRec f v t | (_,t) <- rs]
|
|
||||||
RT rs -> concat [fromRec f (p:v) t | (p,t) <- rs]
|
|
||||||
RFV rs -> concatMap (fromRec f v) rs
|
|
||||||
RS s -> [(s,[(prCId f,unwords (reverse v))])]
|
|
||||||
RCon c -> [] ---- inherent
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module PGF.ShowLinearize (
|
module PGF.ShowLinearize (
|
||||||
Record (..), recLinearize, --- used in PGF.Morphology
|
collectWords,
|
||||||
tableLinearize,
|
tableLinearize,
|
||||||
recordLinearize,
|
recordLinearize,
|
||||||
termLinearize,
|
termLinearize,
|
||||||
@@ -13,6 +13,7 @@ import PGF.Linearize
|
|||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import Data.List
|
import Data.List
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
-- printing linearizations in different ways with source parameters
|
-- printing linearizations in different ways with source parameters
|
||||||
|
|
||||||
@@ -85,3 +86,18 @@ termLinearize :: PGF -> CId -> Exp -> String
|
|||||||
termLinearize pgf lang = show . linExp pgf lang
|
termLinearize pgf lang = show . linExp pgf lang
|
||||||
|
|
||||||
|
|
||||||
|
-- for Morphology: word, lemma, tags
|
||||||
|
collectWords :: PGF -> CId -> [(String, [(String,String)])]
|
||||||
|
collectWords pgf lang =
|
||||||
|
concatMap collOne
|
||||||
|
[(f,c,0) | (f,(DTyp [] c _,_)) <- Map.toList $ funs $ abstract pgf]
|
||||||
|
where
|
||||||
|
collOne (f,c,i) =
|
||||||
|
fromRec f [prCId c] (recLinearize pgf lang (EApp f (replicate i (EMeta 888))))
|
||||||
|
fromRec f v r = case r of
|
||||||
|
RR rs -> concat [fromRec f v t | (_,t) <- rs]
|
||||||
|
RT rs -> concat [fromRec f (p:v) t | (p,t) <- rs]
|
||||||
|
RFV rs -> concatMap (fromRec f v) rs
|
||||||
|
RS s -> [(s,[(prCId f,unwords (reverse v))])]
|
||||||
|
RCon c -> [] ---- inherent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user