mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
SRG generation: renameCats now gives new names to all cates used in the grammar, on RHS or LHS. This avoids a crash in non-recursive SRGS generation. The crash happend becase the bottom-up filter has not yet been done when renameCats is called.
This commit is contained in:
@@ -237,6 +237,13 @@ allRulesGrouped = Map.toList . Map.map Set.toList . cfgRules
|
|||||||
allCats :: CFG -> [Cat]
|
allCats :: CFG -> [Cat]
|
||||||
allCats = Map.keys . cfgRules
|
allCats = Map.keys . cfgRules
|
||||||
|
|
||||||
|
-- | Gets all categories which have rules or occur in a RHS.
|
||||||
|
allCats' :: CFG -> [Cat]
|
||||||
|
allCats' cfg = Set.toList (Map.keysSet (cfgRules cfg) `Set.union`
|
||||||
|
Set.fromList [c | rs <- Map.elems (cfgRules cfg),
|
||||||
|
r <- Set.toList rs,
|
||||||
|
NonTerminal c <- ruleRhs r])
|
||||||
|
|
||||||
-- | Gets all rules for the given category.
|
-- | Gets all rules for the given category.
|
||||||
catRules :: CFG -> Cat -> [CFRule]
|
catRules :: CFG -> Cat -> [CFRule]
|
||||||
catRules gr c = Set.toList $ Map.findWithDefault Set.empty c (cfgRules gr)
|
catRules gr c = Set.toList $ Map.findWithDefault Set.empty c (cfgRules gr)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ renameCats prefix cfg = mapCFGCats renameCat cfg
|
|||||||
where renameCat c | isExternal c = c ++ "_cat"
|
where renameCat c | isExternal c = c ++ "_cat"
|
||||||
| otherwise = Map.findWithDefault (badCat c) c names
|
| otherwise = Map.findWithDefault (badCat c) c names
|
||||||
isExternal c = c `Set.member` cfgExternalCats cfg
|
isExternal c = c `Set.member` cfgExternalCats cfg
|
||||||
catsByPrefix = buildMultiMap [(takeWhile (/='_') cat, cat) | cat <- allCats cfg, not (isExternal cat)]
|
catsByPrefix = buildMultiMap [(takeWhile (/='_') cat, cat) | cat <- allCats' cfg, not (isExternal cat)]
|
||||||
names = Map.fromList [(c,pref++"_"++show i) | (pref,cs) <- catsByPrefix, (c,i) <- zip cs [1..]]
|
names = Map.fromList [(c,pref++"_"++show i) | (pref,cs) <- catsByPrefix, (c,i) <- zip cs [1..]]
|
||||||
badCat c = error ("GF.Speech.SRG.renameCats: " ++ c ++ "\n" ++ prCFG cfg)
|
badCat c = error ("GF.Speech.SRG.renameCats: " ++ c ++ "\n" ++ prCFG cfg)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user