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:
hallgren
2013-10-24 17:29:02 +00:00
parent 2aa5736cb4
commit ad0e67530b
3 changed files with 91 additions and 21 deletions

View File

@@ -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)