diff options
| author | bjorn <bjorn@bringert.net> | 2008-09-25 13:41:07 +0000 |
|---|---|---|
| committer | bjorn <bjorn@bringert.net> | 2008-09-25 13:41:07 +0000 |
| commit | b114cfda7736394a5a38f2c1bf731f08f1501eca (patch) | |
| tree | 6682094d8ce163583500569bde22fd949c472399 /src/GF/Speech | |
| parent | 13191ac15504efc3a45777fb28d594106582f827 (diff) | |
Added --output-format=nolr. Minor makeRegular refactoring.
Diffstat (limited to 'src/GF/Speech')
| -rw-r--r-- | src/GF/Speech/CFG.hs | 7 | ||||
| -rw-r--r-- | src/GF/Speech/PGFToCFG.hs | 13 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/GF/Speech/CFG.hs b/src/GF/Speech/CFG.hs index 5b2a0f2ca..b8857a288 100644 --- a/src/GF/Speech/CFG.hs +++ b/src/GF/Speech/CFG.hs @@ -190,14 +190,13 @@ makeSimpleRegular = makeRegular . topDownFilter . bottomUpFilter . removeCycles -- Use the transformation algorithm from \"Regular Approximation of Context-free -- Grammars through Approximation\", Mohri and Nederhof, 2000 --- to create an over-generating regular frammar for a context-free +-- to create an over-generating regular grammar for a context-free -- grammar makeRegular :: CFG -> CFG makeRegular g = g { cfgRules = groupProds $ concatMap trSet (mutRecCats True g) } where trSet cs | allXLinear cs rs = rs - | otherwise = concatMap handleCat csl - where csl = Set.toList cs - rs = catSetRules g cs + | otherwise = concatMap handleCat (Set.toList cs) + where rs = catSetRules g cs handleCat c = [CFRule c' [] (mkCFTerm (c++"-empty"))] -- introduce A' -> e ++ concatMap (makeRightLinearRules c) (catRules g c) where c' = newCat c diff --git a/src/GF/Speech/PGFToCFG.hs b/src/GF/Speech/PGFToCFG.hs index d52c8807c..6b834d1a4 100644 --- a/src/GF/Speech/PGFToCFG.hs +++ b/src/GF/Speech/PGFToCFG.hs @@ -4,7 +4,8 @@ -- -- Approximates PGF grammars with context-free grammars. ---------------------------------------------------------------------- -module GF.Speech.PGFToCFG (bnfPrinter, regularPrinter, fcfgPrinter, pgfToCFG) where +module GF.Speech.PGFToCFG (bnfPrinter, nonLeftRecursivePrinter, regularPrinter, + fcfgPrinter, pgfToCFG) where import PGF.CId import PGF.Data as PGF @@ -21,10 +22,16 @@ import Data.Set (Set) import qualified Data.Set as Set bnfPrinter :: PGF -> CId -> String -bnfPrinter pgf cnc = prCFG $ pgfToCFG pgf cnc +bnfPrinter = toBNF id + +nonLeftRecursivePrinter :: PGF -> CId -> String +nonLeftRecursivePrinter = toBNF removeLeftRecursion regularPrinter :: PGF -> CId -> String -regularPrinter pgf cnc = prCFG $ makeSimpleRegular $ pgfToCFG pgf cnc +regularPrinter = toBNF makeRegular + +toBNF :: (CFG -> CFG) -> PGF -> CId -> String +toBNF f pgf cnc = prCFG $ f $ pgfToCFG pgf cnc -- FIXME: move this somewhere else fcfgPrinter :: PGF -> CId -> String |
