public NarrowSynthesisRewriteSubruleSpec(SpanFactory<ShapeNode> spanFactory, MatcherSettings<ShapeNode> matcherSettings, bool isIterative,
			int targetCount, RewriteSubrule subrule, int index)
            : base(spanFactory, matcherSettings, isIterative, subrule, index)
        {
            _rhs = subrule.Rhs;
            _targetCount = targetCount;
        }
 public NarrowSynthesisRewriteSubruleSpec(SpanFactory <ShapeNode> spanFactory, MatcherSettings <ShapeNode> matcherSettings, bool isIterative,
                                          int targetCount, RewriteSubrule subrule, int index)
     : base(spanFactory, matcherSettings, isIterative, subrule, index)
 {
     _rhs         = subrule.Rhs;
     _targetCount = targetCount;
 }
        public FeatureAnalysisRewriteRuleSpec(SpanFactory<ShapeNode> spanFactory, 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)
                {
                    var targetConstraint = lhsConstraint.DeepClone();
                    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(spanFactory, matcherSettings, subrule, Unapply));
        }
 protected SynthesisRewriteSubruleSpec(SpanFactory <ShapeNode> spanFactory, MatcherSettings <ShapeNode> matcherSettings, bool isIterative,
                                       RewriteSubrule subrule, int index)
     : base(spanFactory, matcherSettings, subrule.LeftEnvironment, subrule.RightEnvironment)
 {
     _isIterative = isIterative;
     _subrule     = subrule;
     _index       = index;
 }
        protected SynthesisRewriteSubruleSpec(SpanFactory<ShapeNode> spanFactory, MatcherSettings<ShapeNode> matcherSettings, bool isIterative,
			RewriteSubrule subrule, int index)
            : base(spanFactory, matcherSettings, subrule.LeftEnvironment, subrule.RightEnvironment)
        {
            _isIterative = isIterative;
            _subrule = subrule;
            _index = index;
        }
        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));
        }
        public EpenthesisAnalysisRewriteRuleSpec(SpanFactory<ShapeNode> spanFactory, 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>>())
            {
                var newConstraint = constraint.DeepClone();
                newConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean);
                Pattern.Children.Add(newConstraint);
            }
            Pattern.Freeze();

            SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(spanFactory, matcherSettings, subrule, Unapply));
        }
Esempio n. 8
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));
        }
Esempio n. 9
0
        public FeatureAnalysisRewriteRuleSpec(SpanFactory <ShapeNode> spanFactory, 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)
                {
                    var targetConstraint = lhsConstraint.DeepClone();
                    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(spanFactory, matcherSettings, subrule, Unapply));
        }
        public FeatureSynthesisRewriteSubruleSpec(SpanFactory<ShapeNode> spanFactory, MatcherSettings<ShapeNode> matcherSettings, bool isIterative,
			RewriteSubrule subrule, int index)
            : base(spanFactory, matcherSettings, isIterative, subrule, index)
        {
            _rhs = subrule.Rhs;
        }
Esempio n. 11
0
 public EpenthesisSynthesisRewriteSubruleSpec(SpanFactory <ShapeNode> spanFactory, MatcherSettings <ShapeNode> matcherSettings, bool isIterative,
                                              RewriteSubrule subrule, int index)
     : base(spanFactory, matcherSettings, isIterative, subrule, index)
 {
     _rhs = subrule.Rhs;
 }
Esempio n. 12
0
 public AnalysisRewriteSubruleSpec(SpanFactory <ShapeNode> spanFactory, MatcherSettings <ShapeNode> matcherSettings, RewriteSubrule subrule,
                                   Action <Match <Word, ShapeNode>, Span <ShapeNode>, VariableBindings> applyAction)
     : base(spanFactory, matcherSettings, CreateEnvironmentPattern(subrule.LeftEnvironment), CreateEnvironmentPattern(subrule.RightEnvironment))
 {
     _applyAction = applyAction;
 }
        public EpenthesisAnalysisRewriteRuleSpec(SpanFactory <ShapeNode> spanFactory, 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> >())
            {
                var newConstraint = constraint.DeepClone();
                newConstraint.FeatureStruct.AddValue(HCFeatureSystem.Modified, HCFeatureSystem.Clean);
                Pattern.Children.Add(newConstraint);
            }
            Pattern.Freeze();

            SubruleSpecs.Add(new AnalysisRewriteSubruleSpec(spanFactory, matcherSettings, subrule, Unapply));
        }
Esempio n. 14
0
        private RewriteSubrule LoadRewriteSubrule(XElement psubruleElem, Dictionary<string, Tuple<string, SymbolicFeature>> variables)
        {
            var subrule = new RewriteSubrule();

            var requiredPos = (string) psubruleElem.Attribute("requiredPartsOfSpeech");
            if (!string.IsNullOrEmpty(requiredPos))
                subrule.RequiredSyntacticFeatureStruct = FeatureStruct.New().Feature(_posFeature).EqualTo(ParsePartsOfSpeech(requiredPos)).Value;

            subrule.RequiredMprFeatures.UnionWith(LoadMprFeatures((string) psubruleElem.Attribute("requiredMPRFeatures")));
            subrule.ExcludedMprFeatures.UnionWith(LoadMprFeatures((string) psubruleElem.Attribute("excludedMPRFeatures")));

            subrule.Rhs = LoadPhoneticSequence(psubruleElem.Elements("PhoneticOutput").Elements("PhoneticSequence").SingleOrDefault(), variables);

            XElement envElem = psubruleElem.Element("Environment");
            if (envElem != null)
            {
                subrule.LeftEnvironment = LoadPhoneticTemplate(envElem.Elements("LeftEnvironment").Elements("PhoneticTemplate").SingleOrDefault(), variables);
                subrule.RightEnvironment = LoadPhoneticTemplate(envElem.Elements("RightEnvironment").Elements("PhoneticTemplate").SingleOrDefault(), variables);
            }

            return subrule;
        }
        public AnalysisRewriteSubruleSpec(SpanFactory<ShapeNode> spanFactory, MatcherSettings<ShapeNode> matcherSettings, RewriteSubrule subrule,
			Action<Match<Word, ShapeNode>, Span<ShapeNode>, VariableBindings> applyAction)
            : base(spanFactory, matcherSettings, CreateEnvironmentPattern(subrule.LeftEnvironment), CreateEnvironmentPattern(subrule.RightEnvironment))
        {
            _applyAction = applyAction;
        }