summaryrefslogtreecommitdiff
path: root/src/GF/Speech
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2008-10-21 14:30:36 +0000
committerkrasimir <krasimir@chalmers.se>2008-10-21 14:30:36 +0000
commit0606de738e0d934b45f39f1bbe34ed1defde478a (patch)
treef75a8c0f06e4c750b51ba5048087ff56629d9e11 /src/GF/Speech
parent6633ae71f1be152bffad04004570bb4c3d348a81 (diff)
efficient and nicer implementation for literal categories
Diffstat (limited to 'src/GF/Speech')
-rw-r--r--src/GF/Speech/PGFToCFG.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/GF/Speech/PGFToCFG.hs b/src/GF/Speech/PGFToCFG.hs
index 37bc9c0e5..ef7f1f868 100644
--- a/src/GF/Speech/PGFToCFG.hs
+++ b/src/GF/Speech/PGFToCFG.hs
@@ -85,17 +85,24 @@ pgfToCFG pgf lang = mkCFG (prCId (lookStartCat pgf)) extCats (startRules ++ conc
mkRhs = map fsymbolToSymbol . Array.elems
containsLiterals :: Array FPointPos FSymbol -> Bool
- containsLiterals row = any isLiteralFCat [args!!n | FSymCat n _ <- Array.elems row]
+ containsLiterals row = any isLiteralFCat [args!!n | FSymCat n _ <- Array.elems row] ||
+ not (null [n | FSymLit n _ <- Array.elems row]) -- only this is needed for PMCFG.
+ -- The first line is for backward compat.
fsymbolToSymbol :: FSymbol -> CFSymbol
fsymbolToSymbol (FSymCat n l) = NonTerminal (fcatToCat (args!!n) l)
+ fsymbolToSymbol (FSymLit n l) = NonTerminal (fcatToCat (args!!n) l)
fsymbolToSymbol (FSymTok (KS t)) = Terminal t
fixProfile :: Array FPointPos FSymbol -> Profile -> Profile
fixProfile row = concatMap positions
where
- nts = zip [0..] [nt | nt@(FSymCat _ _) <- Array.elems row]
- positions i = [k | (k,FSymCat j _) <- nts, j == i]
+ nts = zip [0..] [j | nt <- Array.elems row, j <- getPos nt]
+ positions i = [k | (k,j) <- nts, j == i]
+
+ getPos (FSymCat j _) = [j]
+ getPos (FSymLit j _) = [j]
+ getPos _ = []
profilesToTerm :: [Profile] -> CFTerm
profilesToTerm ps = CFObj f (zipWith profileToTerm argTypes ps)