summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-03-18 20:12:26 +0000
committerhallgren <hallgren@chalmers.se>2012-03-18 20:12:26 +0000
commit07af8988d3e42bf7e18c06cf8c9dabaa34c60578 (patch)
tree165108cebfa23228f3483eb2dc0c9534c5d4c078 /src/server
parent771c1a0ad7a58e3d4832a93609958a8b3a44f84c (diff)
PGF run-time library: function names in BracketedString (experimental)
+ Make room for function names in the BracketedString data structure. + Fill in function names when linearizing an abstract syntax tree to a BracketedString. + Fill in wildCId when it is not obvious what the function is. + Function bracketedLinearize: for compatibility with the other linearization functions, return Leaf "" instead of error "cannot linearize". + Export flattenBracketedString from module PGF. + PGFServce: make function names available in the JSON representation of BracketedString.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/PGFService.hs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index d291974d0..0c05b4e57 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -169,8 +169,8 @@ doTranslate pgf input mcat mfrom mto =
["translations".=
[makeObj ["tree".=tree,
"linearizations".=
- [makeObj ["to".=to, "text".=output]
- | (to,output) <- linearizeAndBind pgf mto tree]]
+ [makeObj ["to".=to, "text".=text, "brackets".=bs]
+ | (to,text,bs)<- linearizeAndBind pgf mto tree]]
| tree <- trees]]
PGF.ParseIncomplete -> ["incomplete".=True]
PGF.ParseFailed n -> ["parseFailed".=n]
@@ -197,7 +197,7 @@ doTranslateGroup pgf input mcat mfrom mto =
where
groupResults = Map.toList . foldr more Map.empty . start . collect
where
- collect tls = [(t,(l,s)) | (t,ls) <- tls, (l,s) <- ls, notDisamb l]
+ collect tls = [(t,(l,s)) | (t,ls) <- tls, (l,s,_) <- ls, notDisamb l]
start ls = [(l,[([t],s)]) | (t,(l,s)) <- ls]
more (l,s) = Map.insertWith (\ [([t],x)] xs -> insertAlt t x xs) l s
@@ -260,8 +260,8 @@ doComplete pgf input mcat mfrom mlimit = showJSON
doLinearize :: PGF -> PGF.Tree -> Maybe PGF.Language -> JSValue
doLinearize pgf tree mto = showJSON
- [makeObj ["to".=PGF.showLanguage to, "text".=text]
- | (to,text) <- linearize' pgf mto tree]
+ [makeObj ["to".=to, "text".=text,"brackets".=bs]
+ | (to,text,bs) <- linearize' pgf mto tree]
doLinearizes :: PGF -> PGF.Tree -> Maybe PGF.Language -> JSValue
doLinearizes pgf tree mto = showJSON
@@ -275,8 +275,8 @@ doRandom pgf mcat mdepth mlimit mto =
return $ showJSON
[makeObj ["tree".=PGF.showExpr [] tree,
"linearizations".=
- [makeObj ["to".=PGF.showLanguage to, "text".=text]
- | (to,text) <- linearize' pgf mto tree]]
+ [makeObj ["to".=to, "text".=text]
+ | (to,text,bs) <- linearize' pgf mto tree]]
| tree <- limit trees]
where cat = fromMaybe (PGF.startCat pgf) mcat
limit = take (fromMaybe 1 mlimit)
@@ -286,8 +286,8 @@ doGenerate :: PGF -> Maybe PGF.Type -> Maybe Int -> Maybe Int -> Maybe PGF.Langu
doGenerate pgf mcat mdepth mlimit mto =
showJSON [makeObj ["tree".=PGF.showExpr [] tree,
"linearizations".=
- [makeObj ["to".=PGF.showLanguage to, "text".=text]
- | (to,text) <- linearize' pgf mto tree]]
+ [makeObj ["to".=to, "text".=text]
+ | (to,text,bs) <- linearize' pgf mto tree]]
| tree <- limit trees]
where
trees = PGF.generateAllDepth pgf cat (Just depth)
@@ -455,8 +455,8 @@ instance JSON PGF.Expr where
instance JSON PGF.BracketedString where
readJSON x = return (PGF.Leaf "")
- showJSON (PGF.Bracket cat fid index _ bs) =
- makeObj ["cat".=cat, "fid".=fid, "index".=index, "children".=bs]
+ showJSON (PGF.Bracket cat fid index fun _ bs) =
+ makeObj ["cat".=cat, "fid".=fid, "index".=index, "fun".=fun, "children".=bs]
showJSON (PGF.Leaf s) = makeObj ["token".=s]
-- * PGF utilities
@@ -494,9 +494,11 @@ complete' pgf from typ mlimit input =
Left es -> (ps,w:ws)
Right ps -> loop ps ws
-linearize' :: PGF -> Maybe PGF.Language -> PGF.Tree -> [(PGF.Language,String)]
+linearize' :: PGF -> Maybe PGF.Language -> PGF.Tree -> [(PGF.Language,String,PGF.BracketedString)]
linearize' pgf mto tree =
- [(to,PGF.linearize pgf to (transfer to tree)) | to<-langs]
+ [(to,s,bs) | to<-langs,
+ let bs = PGF.bracketedLinearize pgf to (transfer to tree)
+ s = unwords $ PGF.flattenBracketedString bs]
where
langs = maybe (PGF.languages pgf) (:[]) mto
@@ -512,7 +514,8 @@ linearizes' pgf mto tree =
langs = maybe (PGF.languages pgf) (:[]) mto
lins to = nub . concatMap (map snd) . PGF.tabularLinearizes pgf to
-linearizeAndBind pgf mto t = [(la, binds s) | (la,s) <- linearize' pgf mto t]
+linearizeAndBind pgf mto t =
+ [(la, binds s,bs) | (la,s,bs) <- linearize' pgf mto t]
where
binds = unwords . bs . words
bs ws = case ws of