mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 03:09:33 -06:00
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)
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user