public EpenthesisAnalysisRewriteRuleSpec(MatcherSettings <ShapeNode> matcherSettings, RewriteSubrule subrule)
            : base(false)
        {
            Pattern.Acceptable = IsUnapplicationNonvacuous;
            _targetCount       = subrule.Rhs.Children.Count;

            foreach (Constraint <Word, ShapeNode> constraint in subrule.Rhs.Children.Cast <Constraint <Word, ShapeNode> >())
            {
                Constraint <Word, ShapeNode> newConstraint = constraint.Clone();
                newConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean);
                Pattern.Children.Add(newConstraint);
            }
            Pattern.Freeze();

            SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(matcherSettings, subrule, Unapply));
        }
Esempio n. 2
0
        public SynthesisRewriteRuleSpec(MatcherSettings <ShapeNode> matcherSettings, bool isIterative,
                                        Pattern <Word, ShapeNode> lhs, IEnumerable <RewriteSubrule> subrules)
            : base(lhs.IsEmpty)
        {
            Pattern.Acceptable = match => CheckTarget(match, lhs);

            if (lhs.IsEmpty)
            {
                Pattern.Children.Add(new Constraint <Word, ShapeNode>(
                                         FeatureStruct.New().Symbol(HCFeatureSystem.Segment, HCFeatureSystem.Anchor).Value));
            }
            else
            {
                foreach (Constraint <Word, ShapeNode> constraint in lhs.Children.Cast <Constraint <Word, ShapeNode> >())
                {
                    var newConstraint = constraint.Clone();
                    if (isIterative)
                    {
                        newConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean);
                    }
                    Pattern.Children.Add(newConstraint);
                }
            }
            Pattern.Freeze();

            int i = 0;

            foreach (RewriteSubrule subrule in subrules)
            {
                if (lhs.Children.Count == subrule.Rhs.Children.Count)
                {
                    SubruleSpecs.Add(new FeatureSynthesisRewriteSubruleSpec(matcherSettings, isIterative, subrule, i));
                }
                else if (lhs.Children.Count > subrule.Rhs.Children.Count)
                {
                    SubruleSpecs.Add(new NarrowSynthesisRewriteSubruleSpec(matcherSettings, isIterative,
                                                                           lhs.Children.Count, subrule, i));
                }
                else if (lhs.Children.Count == 0)
                {
                    SubruleSpecs.Add(new EpenthesisSynthesisRewriteSubruleSpec(matcherSettings, isIterative, subrule,
                                                                               i));
                }
                i++;
            }
        }
        public FeatureAnalysisRewriteRuleSpec(MatcherSettings <ShapeNode> matcherSettings, Pattern <Word, ShapeNode> lhs,
                                              RewriteSubrule subrule)
            : base(false)
        {
            var rhsAntiFSs = new List <FeatureStruct>();

            foreach (Constraint <Word, ShapeNode> constraint in subrule.Rhs.Children
                     .OfType <Constraint <Word, ShapeNode> >().Where(c => c.Type() == HCFeatureSystem.Segment))
            {
                rhsAntiFSs.Add(constraint.FeatureStruct.AntiFeatureStruct());
            }

            Pattern.Acceptable = match => IsUnapplicationNonvacuous(match, rhsAntiFSs);

            _analysisRhs = new Pattern <Word, ShapeNode>();
            int i = 0;

            foreach (Tuple <PatternNode <Word, ShapeNode>, PatternNode <Word, ShapeNode> > tuple in lhs.Children
                     .Zip(subrule.Rhs.Children))
            {
                var lhsConstraint = (Constraint <Word, ShapeNode>)tuple.Item1;
                var rhsConstraint = (Constraint <Word, ShapeNode>)tuple.Item2;

                if (lhsConstraint.Type() == HCFeatureSystem.Segment && rhsConstraint.Type() == HCFeatureSystem.Segment)
                {
                    Constraint <Word, ShapeNode> targetConstraint = lhsConstraint.Clone();
                    targetConstraint.FeatureStruct.PriorityUnion(rhsConstraint.FeatureStruct);
                    targetConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean);
                    Pattern.Children.Add(new Group <Word, ShapeNode>("target" + i)
                    {
                        Children = { targetConstraint }
                    });

                    FeatureStruct fs = rhsConstraint.FeatureStruct.AntiFeatureStruct();
                    fs.Subtract(lhsConstraint.FeatureStruct.AntiFeatureStruct());
                    fs.AddValue(HCFeatureSystem.Type, HCFeatureSystem.Segment);
                    _analysisRhs.Children.Add(new Constraint <Word, ShapeNode>(fs));

                    i++;
                }
            }
            Pattern.Freeze();

            SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(matcherSettings, subrule, Unapply));
        }
Esempio n. 4
0
        public NarrowAnalysisRewriteRuleSpec(SpanFactory <ShapeNode> spanFactory, MatcherSettings <ShapeNode> matcherSettings, Pattern <Word, ShapeNode> lhs, RewriteSubrule subrule)
            : base(subrule.Rhs.IsEmpty)
        {
            _analysisRhs = lhs;
            _targetCount = subrule.Rhs.Children.Count;

            if (subrule.Rhs.IsEmpty)
            {
                Pattern.Children.Add(new Constraint <Word, ShapeNode>(FeatureStruct.New().Symbol(HCFeatureSystem.Segment, HCFeatureSystem.Anchor).Value));
            }
            else
            {
                Pattern.Children.AddRange(subrule.Rhs.Children.DeepClone());
            }
            Pattern.Freeze();

            SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(spanFactory, matcherSettings, subrule, Unapply));
        }