diff options
| author | bringert <bringert@cs.chalmers.se> | 2006-12-21 16:48:46 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2006-12-21 16:48:46 +0000 |
| commit | a335b29c0a85ea81ee1017f18dd6f2595d2a5227 (patch) | |
| tree | e0b4d7356c3bf5cb82e9d7e11ff9e4d3e5f4e764 /src/GF/Speech | |
| parent | 51df5b8a8d562a3ac4b280b37e7ab04279e22d04 (diff) | |
Meta variables are now treated as functions with name ? in SISR, VoiceXML and JavaScript linearization. VoiceXML now returns the partial result when update() is false.
Diffstat (limited to 'src/GF/Speech')
| -rw-r--r-- | src/GF/Speech/GrammarToVoiceXML.hs | 10 | ||||
| -rw-r--r-- | src/GF/Speech/SISR.hs | 22 | ||||
| -rw-r--r-- | src/GF/Speech/TransformCFG.hs | 3 |
3 files changed, 15 insertions, 20 deletions
diff --git a/src/GF/Speech/GrammarToVoiceXML.hs b/src/GF/Speech/GrammarToVoiceXML.hs index 16bdb9c78..d7e916a72 100644 --- a/src/GF/Speech/GrammarToVoiceXML.hs +++ b/src/GF/Speech/GrammarToVoiceXML.hs @@ -119,22 +119,22 @@ catForms gr qs cat fs = cat2form :: String -> CatQuestions -> VIdent -> [(VIdent, [VIdent])] -> XML cat2form gr qs cat fs = form (catFormId cat) $ - [var "value" (Just "'?'"), + [var "value" (Just "{ name : '?' }"), var "update" Nothing, - blockCond "value != '?'" [assign (catFieldId cat) "value"], + blockCond "value.name != '?'" [assign (catFieldId cat) "value"], field (catFieldId cat) [] [promptString (getCatQuestion cat qs), grammar (gr++"#"++catFormId cat), nomatch [Data "I didn't understand you.", reprompt], help [Data ("help_"++cat)], - filled [] [if_else (catFieldId cat ++ " == '?'") [reprompt] feedback]] + filled [] [if_else (catFieldId cat ++ ".name == '?'") [reprompt] feedback]] ] ++ concatMap (uncurry (fun2sub gr cat)) fs ++ [block [return_ [catFieldId cat]]] - where feedback = [if_ ("typeof update != 'undefined' && !update("++string cat++","++ catFieldId cat ++ ")") [return_ []]] + where feedback = [if_ ("typeof update != 'undefined' && !update("++string cat++","++ catFieldId cat ++ ")") [return_ [catFieldId cat]]] fun2sub :: String -> VIdent -> VIdent -> [VIdent] -> [XML] -fun2sub gr cat fun args = comments [fun ++ " : " ++ cat] ++ ss +fun2sub gr cat fun args = comments [fun ++ " : (" ++ concat (intersperse ", " args) ++ ") " ++ cat] ++ ss where argNames = zip ["arg"++show n | n <- [0..]] args ss = map (uncurry mkSub) argNames diff --git a/src/GF/Speech/SISR.hs b/src/GF/Speech/SISR.hs index 372bbc7ea..731f01a3e 100644 --- a/src/GF/Speech/SISR.hs +++ b/src/GF/Speech/SISR.hs @@ -44,7 +44,7 @@ topCatSISR i c fmt = map JS.DExpr [field (fmtOut fmt) i `ass` fmtRef fmt c] profileInitSISR :: CFTerm -> SISRFormat -> SISRTag profileInitSISR t fmt | null (usedChildren t) = [] - | otherwise = [JS.Decl [JS.DInit children (JS.ENew (JS.Ident "Array") [])]] + | otherwise = [JS.Decl [JS.DInit children (JS.EArray [])]] usedChildren :: CFTerm -> [Int] usedChildren (CFObj _ ts) = foldr union [] (map usedChildren ts) @@ -60,24 +60,15 @@ catSISR t (c,i) fmt | otherwise = [] profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag -profileFinalSISR term fmt = map JS.DExpr $ g term +profileFinalSISR term fmt = [JS.DExpr $ fmtOut fmt `ass` f term] where - -- optimization for tokens - g (CFObj n []) = [field (fmtOut fmt) "name" `ass` JS.EStr (prIdent n)] - g t = [fmtOut fmt `ass` f t] - f (CFObj n ts) = - JS.ESeq $ [ret `ass` JS.ENew (JS.Ident "Object") [], - field ret "name" `ass` JS.EStr (prIdent n)] - ++ [field ret ("arg"++show i) `ass` f t - | (i,t) <- zip [0..] ts ] - ++ [ret] - where ret = JS.EVar (JS.Ident "ret") + f (CFObj n ts) = tree (prIdent n) (map f ts) f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)] f (CFApp x y) = JS.ECall (f x) [f y] f (CFRes i) = JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i)) f (CFVar v) = JS.EVar (var v) f (CFConst s) = JS.EStr s - + f CFMeta = tree "?" [] fmtOut SISROld = JS.EVar (JS.Ident "$") @@ -89,4 +80,7 @@ var v = JS.Ident ("x" ++ show v) field x y = JS.EMember x (JS.Ident y) -ass = JS.EAssign
\ No newline at end of file +ass = JS.EAssign + +tree n xs = JS.EObj $ [JS.Prop (JS.Ident "name") (JS.EStr n)] + ++ [JS.Prop (JS.Ident ("arg"++show i)) x | (i,x) <- zip [0..] xs]
\ No newline at end of file diff --git a/src/GF/Speech/TransformCFG.hs b/src/GF/Speech/TransformCFG.hs index 796382b7d..31017c61f 100644 --- a/src/GF/Speech/TransformCFG.hs +++ b/src/GF/Speech/TransformCFG.hs @@ -54,6 +54,7 @@ data CFTerm | CFRes Int | CFVar Int | CFConst String + | CFMeta deriving (Eq,Show) type Cat_ = String @@ -69,7 +70,7 @@ cfgToCFRules cfg = where symb = mapSymbol catToString id catToString = prt nameToTerm (Name f prs) = CFObj f (map profileToTerm prs) - profileToTerm (Unify []) = CFConst "?" + profileToTerm (Unify []) = CFMeta profileToTerm (Unify xs) = CFRes (last xs) -- FIXME: unify profileToTerm (Constant f) = CFConst (maybe "?" prIdent (forestName f)) |
