public SynthesisRewriteRule(Morpher morpher, RewriteRule rule) { _morpher = morpher; _rule = rule; var settings = new MatcherSettings <ShapeNode> { Direction = rule.Direction, Filter = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Boundary, HCFeatureSystem.Anchor) && !ann.IsDeleted(), UseDefaults = true }; var ruleSpec = new SynthesisRewriteRuleSpec(settings, rule.ApplicationMode == RewriteApplicationMode.Iterative, _rule.Lhs, _rule.Subrules); _patternRule = null; switch (rule.ApplicationMode) { case RewriteApplicationMode.Iterative: _patternRule = new IterativePhonologicalPatternRule(ruleSpec, settings); break; case RewriteApplicationMode.Simultaneous: _patternRule = new SimultaneousPhonologicalPatternRule(ruleSpec, settings); break; } }
public AnalysisRewriteRule(Morpher morpher, RewriteRule rule) { _morpher = morpher; _rule = rule; var settings = new MatcherSettings <ShapeNode> { Direction = rule.Direction == Direction.LeftToRight ? Direction.RightToLeft : Direction.LeftToRight, Filter = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Anchor), MatchingMethod = MatchingMethod.Unification, UseDefaults = true, // during analysis shape nodes can have features that are underspecified, so this must be non-deterministic Nondeterministic = true }; _rules = new List <Tuple <ReapplyType, PhonologicalPatternRule> >(); foreach (RewriteSubrule sr in _rule.Subrules) { IPhonologicalPatternRuleSpec ruleSpec = null; var mode = RewriteApplicationMode.Iterative; var reapplyType = ReapplyType.Normal; if (_rule.Lhs.Children.Count == sr.Rhs.Children.Count) { ruleSpec = new FeatureAnalysisRewriteRuleSpec(settings, rule.Lhs, sr); if (_rule.ApplicationMode == RewriteApplicationMode.Simultaneous) { foreach (Constraint <Word, ShapeNode> constraint in sr.Rhs.Children .Cast <Constraint <Word, ShapeNode> >()) { if (constraint.Type() == HCFeatureSystem.Segment) { if (!IsUnifiable(constraint, sr.LeftEnvironment) || !IsUnifiable(constraint, sr.RightEnvironment)) { reapplyType = ReapplyType.SelfOpaquing; break; } } } } } else if (_rule.Lhs.Children.Count > sr.Rhs.Children.Count) { ruleSpec = new NarrowAnalysisRewriteRuleSpec(settings, _rule.Lhs, sr); mode = RewriteApplicationMode.Simultaneous; reapplyType = ReapplyType.Deletion; } else if (_rule.Lhs.Children.Count == 0) { ruleSpec = new EpenthesisAnalysisRewriteRuleSpec(settings, sr); if (_rule.ApplicationMode == RewriteApplicationMode.Simultaneous) { reapplyType = ReapplyType.SelfOpaquing; } } Debug.Assert(ruleSpec != null); PhonologicalPatternRule patternRule = null; switch (mode) { case RewriteApplicationMode.Iterative: patternRule = new IterativePhonologicalPatternRule(ruleSpec, settings); break; case RewriteApplicationMode.Simultaneous: patternRule = new SimultaneousPhonologicalPatternRule(ruleSpec, settings); break; } _rules.Add(Tuple.Create(reapplyType, patternRule)); } }