From 44ee072331424dae6a7918835bd15c51f56307e8 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 11 Feb 2014 16:43:29 +0000 Subject: Work on web api & apps based on the C run-time system + PGFService.hs: add command c-grammar, include probability in parse results + js/gftranslation.js: add start position and limit parameters, return more info to applications + Simple Translator: show two wide coverage translations + Wide coverage demo: show parse tree and probability (intended as grammar debugging aids) --- src/server/PGFService.hs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/server') diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index f4028b6d0..e6bcbdaba 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -89,21 +89,30 @@ cpgfMain command (pgf,pc) = "c-linearize" -> out =<< lin # tree % to "c-translate" -> out =<< join (trans # input % from % to % start % limit % trie) "c-flush" -> out =<< flush + "c-grammar" -> out grammar _ -> badRequest "Unknown command" command where flush = liftIO $ do modifyMVar_ pc $ const $ return Map.empty performGC return $ showJSON () + grammar = showJSON $ makeObj + ["name".=C.abstractName pgf, + "startcat".=C.startCat pgf, + "languages".=languages] + where + languages = [makeObj ["name".= l] | (l,_)<-Map.toList (C.languages pgf)] + parse input (from,concr) start mlimit trie = do trees <- parse' input (from,concr) start mlimit - return $ showJSON [makeObj ("from".=from:"trees".=trees :[])] + return $ showJSON [makeObj ("from".=from:"trees".=map tp trees :[])] -- :addTrie trie trees - where + + tp (tree,prob) = makeObj ["tree".=tree,"prob".=prob] parse' input (from,concr) start mlimit = liftIO $ do t <- getCurrentTime - (map fst . maybe id take mlimit . drop start) + (maybe id take mlimit . drop start) # modifyMVar pc (parse'' t) where key = (from,input) @@ -120,13 +129,14 @@ cpgfMain command (pgf,pc) = lin' tree tos = [makeObj ["to".=to,"text".=C.linearize c tree]|(to,c)<-tos] trans input (from,concr) tos start mlimit trie = - do trees <- parse' input (from,concr) start mlimit + do parses <- parse' input (from,concr) start mlimit return $ showJSON [ makeObj ["from".=from, "translations".= [makeObj ["tree".=tree, + "prob".=prob, "linearizations".=lin' tree tos] - | tree <- trees]]] + | (tree,prob) <- parses]]] from = maybe (missing "from") return =<< getLang "from" -- cgit v1.2.3