diff options
| author | bringert <bringert@cs.chalmers.se> | 2006-01-05 17:46:30 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2006-01-05 17:46:30 +0000 |
| commit | ca84f92302438de357793f2548bf56dc9a5d43b2 (patch) | |
| tree | dde069726a6653623f63f9d7353d1e91a8e0c97d /src/GF/Speech/CFGToFiniteState.hs | |
| parent | bffc7df07e2345b19ade6ce2e9718aa3b1bf6a23 (diff) | |
Remove unused sub-networks when generating multiple FAs.
Diffstat (limited to 'src/GF/Speech/CFGToFiniteState.hs')
| -rw-r--r-- | src/GF/Speech/CFGToFiniteState.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/GF/Speech/CFGToFiniteState.hs b/src/GF/Speech/CFGToFiniteState.hs index 855bc8091..aad85b703 100644 --- a/src/GF/Speech/CFGToFiniteState.hs +++ b/src/GF/Speech/CFGToFiniteState.hs @@ -150,11 +150,11 @@ data MFALabel a = MFASym a | MFASub String data MFA a = MFA (DFA (MFALabel a)) [(String,DFA (MFALabel a))] -- --- * Compile strongly regular grammars to multiple DFAs +-- * Compile a strongly regular grammar to a DFA with sub-automata -- cfgToMFA :: Options -> CGrammar -> MFA String -cfgToMFA opts g = MFA startFA [(c, toMFA (minimize fa)) | (c,fa) <- fas] +cfgToMFA opts g = removeUnusedSubLats mfa where start = getStartCat opts startFA = let (fa,s,f) = newFA_ in newTransition s f (MFASub start) fa @@ -162,6 +162,16 @@ cfgToMFA opts g = MFA startFA [(c, toMFA (minimize fa)) | (c,fa) <- fas] mkMFALabel (Cat c) = MFASub c mkMFALabel (Tok t) = MFASym t toMFA = mapTransitions mkMFALabel + mfa = MFA startFA [(c, toMFA (minimize fa)) | (c,fa) <- fas] + +removeUnusedSubLats :: MFA a -> MFA a +removeUnusedSubLats (MFA main subs) = MFA main [(c,s) | (c,s) <- subs, isUsed c] + where + usedMap = Map.fromList [(c,usedSubLats n) | (c,n) <- subs] + used = growUsedSet (usedSubLats main) + isUsed c = c `Set.member` used + growUsedSet = fix (\s -> foldl Set.union s $ mapMaybe (flip Map.lookup usedMap) $ Set.toList s) + usedSubLats fa = Set.fromList [s | (_,_,MFASub s) <- transitions fa] -- | Convert a strongly regular grammar to a number of finite automata, -- one for each non-terminal. |
