From 9410c6b1411612658d5262cbfca903fd1927cd55 Mon Sep 17 00:00:00 2001 From: hallgren Date: Thu, 24 Oct 2013 17:29:02 +0000 Subject: 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 --- src/compiler/GF/Command/Commands.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/compiler/GF/Command') diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs index 8643f8a75..681b64f0d 100644 --- a/src/compiler/GF/Command/Commands.hs +++ b/src/compiler/GF/Command/Commands.hs @@ -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) -- cgit v1.2.3