summaryrefslogtreecommitdiff
path: root/src/runtime
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/runtime
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/runtime')
-rw-r--r--src/runtime/haskell/PGF/Parse.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/runtime/haskell/PGF/Parse.hs b/src/runtime/haskell/PGF/Parse.hs
index ad31cc25f..40abb78fd 100644
--- a/src/runtime/haskell/PGF/Parse.hs
+++ b/src/runtime/haskell/PGF/Parse.hs
@@ -15,7 +15,7 @@ module PGF.Parse
import Data.Array.IArray
import Data.Array.Base (unsafeAt)
-import Data.List (isPrefixOf, foldl')
+import Data.List (isPrefixOf, foldl', intercalate)
import Data.Maybe (fromMaybe, maybeToList)
import qualified Data.Map as Map
import qualified PGF.TrieMap as TrieMap
@@ -506,14 +506,26 @@ type Continuation = TrieMap.TrieMap Token ActiveSet
-- | Return the Continuation of a Parsestate with exportable types
-- Used by PGFService
-getContinuationInfo :: ParseState -> Map.Map [Token] [(FunId, CId)]
+getContinuationInfo :: ParseState -> Map.Map [Token] [(FunId, CId, String)]
getContinuationInfo pstate = Map.map (map f . Set.toList) contMap
where
PState abstr concr chart cont = pstate
contMap = Map.fromList (TrieMap.toList cont) -- always get [([], _::ActiveSet)]
- f :: Active -> (FunId,CId)
- f (Active int dotpos funid seqid pargs ak) = (funid, cid)
- where CncFun cid _ = cncfuns concr ! funid
+ f :: Active -> (FunId,CId,String)
+ f (Active int dotpos funid seqid pargs ak) = (funid, cid, seq)
+ where
+ CncFun cid _ = cncfuns concr ! funid
+ seq = showSeq dotpos (sequences concr ! seqid)
+
+ showSeq :: DotPos -> Sequence -> String
+ showSeq pos seq = intercalate " " $ scan (drop (pos-1) (elems seq))
+ where
+ -- Scan left-to-right, stop at first non-token
+ scan :: [Symbol] -> [String]
+ scan [] = []
+ scan (sym:syms) = case sym of
+ SymKS token -> token : scan syms
+ _ -> []
----------------------------------------------------------------
-- Error State