summaryrefslogtreecommitdiff
path: root/src/server/PGFService.hs
diff options
context:
space:
mode:
authorjohn.j.camilleri <john.j.camilleri@chalmers.se>2014-07-15 09:33:22 +0000
committerjohn.j.camilleri <john.j.camilleri@chalmers.se>2014-07-15 09:33:22 +0000
commit37a35734a57f6bcdbeb38398f2cf3980f1e100b9 (patch)
treefce7bbb893eba09aa07c72c0153b3b3dfed4b903 /src/server/PGFService.hs
parent9b496084512ca94ca7fb96fd606e749d02022aad (diff)
PGF Web Service: include entire completion in full mode
When using full=yes in the web service 'complete' command, you now get an additional field 'seq' with the longest possible completion. So, given: lin f1 = ss "the" ; f2 = ss ("the red house" | "the real deal") ; and trying to complete on input "th", you get: [ { "from": "TestCnc", "brackets": { "cat": "_", "fid": 0, "index": 0, "fun": "_", "children": [] }, "text": "th", "completions": [ { "token": "the", "funs": [ { "fun": "f1", "hyps": [], "cat": "C", "seq": "the" }, { "fun": "f2", "hyps": [], "cat": "C", "seq": "the red house" }, { "fun": "f2", "hyps": [], "cat": "C", "seq": "the real deal" } ] } ] } ]
Diffstat (limited to 'src/server/PGFService.hs')
-rw-r--r--src/server/PGFService.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index 854f70936..509591ba2 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -30,7 +30,7 @@ import Control.Monad
import Control.Monad.State(State,evalState,get,put)
import Data.Char
import Data.Function (on)
-import Data.List (sortBy,intersperse,mapAccumL,nub,isSuffixOf)
+import Data.List (sortBy,intersperse,mapAccumL,nub,isSuffixOf,nubBy)
import qualified Data.Map as Map
import Data.Maybe
import System.Random
@@ -594,18 +594,19 @@ completionInfo :: PGF -> PGF.Token -> PGF.ParseState -> JSValue
completionInfo pgf token pstate =
makeObj
["token".= token
- ,"funs" .= (nub (map mkFun funs))
+ ,"funs" .= (map mkFun (nubBy ignoreFunIds funs))
]
where
contInfo = PGF.getContinuationInfo pstate
- funs = snd . head $ Map.toList contInfo -- always get [([],_)] ; funs :: [(fid,cid)]
- mkFun (funid,cid) = case PGF.functionType pgf cid of
+ funs = snd . head $ Map.toList contInfo -- always get [([],_)] ; funs :: [(fid,cid,seq)]
+ ignoreFunIds (_,cid1,seq1) (_,cid2,seq2) = (cid1,seq1) == (cid2,seq2)
+ mkFun (funid,cid,seq) = case PGF.functionType pgf cid of
Just typ ->
- makeObj [ "fid".=funid, "fun".=cid, "hyps".=hyps', "cat".=cat ]
+ makeObj [ {-"fid".=funid,-} "fun".=cid, "hyps".=hyps', "cat".=cat, "seq".=seq ]
where
(hyps,cat,es) = PGF.unType typ
hyps' = [ PGF.showType [] typ | (_,_,typ) <- hyps ]
- Nothing -> makeObj [] -- shouldn't happen
+ Nothing -> makeObj [ "error".=("Function "++show cid++" not found") ] -- shouldn't happen
doLinearize :: PGF -> PGF.Tree -> To -> JSValue
doLinearize pgf tree (tos,unlex) = showJSON