diff options
| author | bringert <bringert@cs.chalmers.se> | 2006-12-20 20:10:15 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2006-12-20 20:10:15 +0000 |
| commit | f9621483a0caeb49512bf4d15420bd05ea57cb22 (patch) | |
| tree | 44e21f8e2fd66b9f53f9a312ddde52bdab0fc4df /src/GF/Speech/SRG.hs | |
| parent | c7df9f4167f7b554a93a216245a013e16cca420d (diff) | |
Use LCLR algorithm for eliminating left-recursion, with lambda terms in SISR for getting trees right.
Diffstat (limited to 'src/GF/Speech/SRG.hs')
| -rw-r--r-- | src/GF/Speech/SRG.hs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/GF/Speech/SRG.hs b/src/GF/Speech/SRG.hs index 84820be9f..64dbbea37 100644 --- a/src/GF/Speech/SRG.hs +++ b/src/GF/Speech/SRG.hs @@ -19,12 +19,12 @@ ----------------------------------------------------------------------------- module GF.Speech.SRG (SRG(..), SRGRule(..), SRGAlt(..), - SRGCat, SRGNT, + SRGCat, SRGNT, CFTerm, makeSimpleSRG, makeSRG , lookupFM_, prtS , topDownFilter, cfgCatToGFCat, srgTopCats - , EBnfSRGAlt(..), EBnfSRGItem - , ebnfSRGAlts + --, EBnfSRGAlt(..), EBnfSRGItem + --, ebnfSRGAlts ) where import GF.Data.Operations @@ -64,13 +64,13 @@ data SRGRule = SRGRule SRGCat String [SRGAlt] -- ^ SRG category name, original c deriving (Eq,Show) -- | maybe a probability, a rule name and a list of symbols -data SRGAlt = SRGAlt (Maybe Double) Name [Symbol SRGNT Token] +data SRGAlt = SRGAlt (Maybe Double) CFTerm [Symbol SRGNT Token] deriving (Eq,Show) type SRGCat = String --- | An SRG non-terminal. Category name and slots which it fills in. -type SRGNT = (SRGCat, [Int]) +-- | An SRG non-terminal. Category name and its number in the profile. +type SRGNT = (SRGCat, Int) -- | SRG category name and original name type CatName = (SRGCat,String) @@ -129,17 +129,13 @@ cfgRulesToSRGRule names probs rs@(r:_) = SRGRule cat origCat rhs origCat = lhsCat r cat = lookupFM_ names origCat rhs = nub $ map ruleToAlt rs - ruleToAlt r@(CFRule c ss n@(Name _ prs)) + ruleToAlt r@(CFRule c ss n) = SRGAlt (ruleProb probs r) n (mkSRGSymbols 0 ss) where mkSRGSymbols _ [] = [] - mkSRGSymbols i (Cat c:ss) = Cat (c',slots) : mkSRGSymbols (i+1) ss - where c' = lookupFM_ names c - slots = [x | x <- [0..length prs-1], inProfile i (prs!!x)] + mkSRGSymbols i (Cat c:ss) = Cat (renameCat c,0) : mkSRGSymbols (i+1) ss mkSRGSymbols i (Tok t:ss) = Tok t : mkSRGSymbols i ss - inProfile :: Int -> Profile a -> Bool - inProfile x (Unify xs) = x `elem` xs - inProfile _ (Constant _) = False + renameCat = lookupFM_ names ruleProb :: Maybe Probs -> CFRule_ -> Maybe Double ruleProb mp r = mp >>= \probs -> lookupProb probs (ruleFun r) @@ -182,6 +178,7 @@ srgTopCats srg = buildMultiMap [(oc, cat) | SRGRule cat origCat _ <- rules srg, -- * Size-optimized EBNF SRGs -- +{- data EBnfSRGAlt = EBnfSRGAlt (Maybe Double) Name EBnfSRGItem deriving (Eq,Show) @@ -204,6 +201,7 @@ addString xs fa = addFinalState (last sts0) $ newTransitions ts fa' sts0 = startState fa : sts1 sts1 = map fst ss ts = zip3 sts0 sts1 xs +-} -- -- * Utilities for building and printing SRGs |
