diff options
| author | bringert <bringert@cs.chalmers.se> | 2007-01-05 14:34:20 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2007-01-05 14:34:20 +0000 |
| commit | 741dde5a2a00dc737e570a7005663c2534ea4f6d (patch) | |
| tree | 6aebd85fc4d9417a0bb3fbfb450fcf3ea72101b8 /src/GF/Speech/SRG.hs | |
| parent | 2b1c6763cc29857ba2890a12eb4330f6e03edd06 (diff) | |
Change input to the different SRG printers to be StateGrammar instead of CGrammar. This to allow looking at the types in SISR, and to reduce the number of argument passed from Custom.
Diffstat (limited to 'src/GF/Speech/SRG.hs')
| -rw-r--r-- | src/GF/Speech/SRG.hs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/GF/Speech/SRG.hs b/src/GF/Speech/SRG.hs index 2edca0368..e9081abab 100644 --- a/src/GF/Speech/SRG.hs +++ b/src/GF/Speech/SRG.hs @@ -42,6 +42,7 @@ import GF.Speech.FiniteState import GF.Speech.RegExp import GF.Infra.Option import GF.Probabilistic.Probabilistic (Probs) +import GF.Compile.ShellState (StateGrammar, stateProbs) import Data.List import Data.Maybe (fromMaybe, maybeToList) @@ -83,30 +84,30 @@ type CatNames = Map String String makeSimpleSRG :: Ident -- ^ Grammar name -> String -- ^ Start category -> Options -- ^ Grammar options - -> Maybe Probs -- ^ Probabilities - -> CGrammar -- ^ A context-free grammar + -> StateGrammar -> SRG -makeSimpleSRG i origStart opts probs = - makeSRG_ i origStart opts probs - . removeLeftRecursion origStart . removeIdenticalRules - . removeEmptyCats . removeCycles - . cfgToCFRules +makeSimpleSRG i origStart opts s = + makeSRG_ i origStart opts probs $ preprocess $ cfgToCFRules s + where preprocess = removeLeftRecursion origStart . removeIdenticalRules + . removeEmptyCats . removeCycles + probs = stateProbs s -- | Create a SRG preserving the names, profiles and probabilities of the -- input grammar. The returned grammar may be left-recursive. makeSRG :: Ident -- ^ Grammar name -> String -- ^ Start category -> Options -- ^ Grammar options - -> Maybe Probs -- ^ Probabilities - -> CGrammar -- ^ A context-free grammar + -> StateGrammar -> SRG -makeSRG i origStart opts probs = - makeSRG_ i origStart opts probs . removeEmptyCats . cfgToCFRules +makeSRG i origStart opts s = + makeSRG_ i origStart opts probs $ preprocess $ cfgToCFRules s + where preprocess = removeEmptyCats + probs = stateProbs s makeSRG_ :: Ident -- ^ Grammar name -> String -- ^ Start category -> Options -- ^ Grammar options - -> Maybe Probs -- ^ Probabilities + -> Probs -- ^ Probabilities -> CFRules -- ^ A context-free grammar -> SRG makeSRG_ i origStart opts probs gr = @@ -123,7 +124,7 @@ makeSRG_ i origStart opts probs gr = rs = map (cfgRulesToSRGRule names probs) cfgRules -- FIXME: merge alternatives with same rhs and profile but different probabilities -cfgRulesToSRGRule :: Map String String -> Maybe Probs -> [CFRule_] -> SRGRule +cfgRulesToSRGRule :: Map String String -> Probs -> [CFRule_] -> SRGRule cfgRulesToSRGRule names probs rs@(r:_) = SRGRule cat origCat rhs where origCat = lhsCat r @@ -137,8 +138,8 @@ cfgRulesToSRGRule names probs rs@(r:_) = SRGRule cat origCat rhs mkSRGSymbols i (Tok t:ss) = Tok t : mkSRGSymbols i ss renameCat = lookupFM_ names -ruleProb :: Maybe Probs -> CFRule_ -> Maybe Double -ruleProb mp r = mp >>= \probs -> lookupProb probs (ruleFun r) +ruleProb :: Probs -> CFRule_ -> Maybe Double +ruleProb probs r = lookupProb probs (ruleFun r) -- FIXME: move to GF.Probabilistic.Probabilistic? lookupProb :: Probs -> Ident -> Maybe Double |
