summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-02-11 16:43:29 +0000
committerhallgren <hallgren@chalmers.se>2014-02-11 16:43:29 +0000
commit44ee072331424dae6a7918835bd15c51f56307e8 (patch)
tree3f71d0855d9cc26a7ab706e9adbfc7c9a10d887f /src/server
parent23dc22cea49b7dde812882cff8e77b27e1b6382f (diff)
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)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/PGFService.hs20
1 files changed, 15 insertions, 5 deletions
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"