From f9621483a0caeb49512bf4d15420bd05ea57cb22 Mon Sep 17 00:00:00 2001 From: bringert Date: Wed, 20 Dec 2006 20:10:15 +0000 Subject: Use LCLR algorithm for eliminating left-recursion, with lambda terms in SISR for getting trees right. --- src/GF/Speech/SRG.hs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/GF/Speech/SRG.hs') 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 -- cgit v1.2.3