summaryrefslogtreecommitdiff
path: root/src/GF/Speech/TransformCFG.hs
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2007-03-19 18:03:19 +0000
committerbringert <bringert@cs.chalmers.se>2007-03-19 18:03:19 +0000
commit3dacf21a416511e88659d20bbcec284e70b85ec7 (patch)
tree7244b4903228dbe1468703b4b2f785e331142842 /src/GF/Speech/TransformCFG.hs
parent232c9cbb3729df3f78e7cd4e2119af30383c7e14 (diff)
Use makeSimpleSRG everywhere and remove makeSRG. Reimplemented top-down filtering in terms of CFRules instead of SRG. Do top-down filtering in makeSimpleSRG.
Diffstat (limited to 'src/GF/Speech/TransformCFG.hs')
-rw-r--r--src/GF/Speech/TransformCFG.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/GF/Speech/TransformCFG.hs b/src/GF/Speech/TransformCFG.hs
index 37d90fb52..63078ac5c 100644
--- a/src/GF/Speech/TransformCFG.hs
+++ b/src/GF/Speech/TransformCFG.hs
@@ -227,6 +227,15 @@ removeCycles :: CFRules -> CFRules
removeCycles = groupProds . removeCycles_ . ungroupProds
where removeCycles_ rs = [r | r@(CFRule c rhs _) <- rs, rhs /= [Cat c]]
+-- * Top-down filtering
+
+-- | Remove categories which are not reachable from the start category.
+topDownFilter :: Cat_ -> CFRules -> CFRules
+topDownFilter start rules = filter ((`Set.member` keep) . fst) rules
+ where
+ rhsCats = [ (c, c') | (c,rs) <- rules, r <- rs, c' <- filterCats (ruleRhs r) ]
+ uses = reflexiveClosure_ (allCats rules) $ transitiveClosure $ mkRel rhsCats
+ keep = allRelated uses start
-- | Get the sets of mutually recursive non-terminals for a grammar.
mutRecCats :: Bool -- ^ If true, all categories will be in some set.