mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Functions merge trees into tries in the GF Shell and the PGF web service
* In the shell, the new command tt (to_trie) merges a list of trees into a trie and prints it in a readable way, where unique subtrees are marked with a "*" and alternative subtrees are marked with numbers. * In the PGF web service, adding the parameter trie=yes to the parse and translate commands augments the JSON output with a trie. Example to try in the shell: Phrasebook> p -lang=Eng "your son waits for you" | tt
This commit is contained in:
@@ -687,6 +687,12 @@ allCommands = Map.fromList [
|
||||
("to", "forward-apply transliteration defined in this file")
|
||||
]
|
||||
}),
|
||||
("tt", emptyCommandInfo {
|
||||
longname = "to_trie",
|
||||
syntax = "to_trie",
|
||||
synopsis = "combine a list of trees into a trie",
|
||||
exec = \ _ _ -> return . fromString . trie
|
||||
}),
|
||||
("pt", emptyCommandInfo {
|
||||
longname = "put_tree",
|
||||
syntax = "pt OPT? TREE",
|
||||
@@ -1407,3 +1413,18 @@ execToktok (pgf, _) opts exprs = do
|
||||
getLang [] = Nothing
|
||||
getLang (OFlag "lang" (VId l):_) = readLanguage l
|
||||
getLang (_:os) = getLang os
|
||||
|
||||
|
||||
|
||||
trie = render . pptss . toTrie . map toATree
|
||||
where
|
||||
pptss [ts] = text "*"<+>nest 2 (ppts ts)
|
||||
pptss tss = vcat [int i<+>nest 2 (ppts ts)|(i,ts)<-zip [1..] tss]
|
||||
|
||||
ppts = vcat . map ppt
|
||||
|
||||
ppt t =
|
||||
case t of
|
||||
Oth e -> text (showExpr [] e)
|
||||
Ap f [[]] -> text (showCId f)
|
||||
Ap f tss -> text (showCId f) $$ nest 2 (pptss tss)
|
||||
|
||||
Reference in New Issue
Block a user