Пример #1
0
 public SynthesisAffixProcessRule(Morpher morpher, AffixProcessRule rule)
 {
     _morpher = morpher;
     _rule    = rule;
     _rules   = new List <PatternRule <Word, ShapeNode> >();
     foreach (AffixProcessAllomorph allo in rule.Allomorphs)
     {
         var ruleSpec = new SynthesisAffixProcessAllomorphRuleSpec(allo);
         _rules.Add(new PatternRule <Word, ShapeNode>(ruleSpec,
                                                      new MatcherSettings <ShapeNode>
         {
             Filter = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Boundary) &&
                      !ann.IsDeleted(),
             AnchoredToStart = true,
             AnchoredToEnd   = true
         }));
     }
 }
        public AnalysisAffixProcessRule(Morpher morpher, AffixProcessRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            _rules = new List <PatternRule <Word, ShapeNode> >();
            foreach (AffixProcessAllomorph allo in rule.Allomorphs)
            {
                _rules.Add(new MultiplePatternRule <Word, ShapeNode>(new AnalysisAffixProcessAllomorphRuleSpec(allo),
                                                                     new MatcherSettings <ShapeNode>
                {
                    Filter          = ann => ann.Type() == HCFeatureSystem.Segment,
                    MatchingMethod  = MatchingMethod.Unification,
                    AnchoredToStart = true,
                    AnchoredToEnd   = true,
                    AllSubmatches   = true
                }));
            }
        }
Пример #3
0
        public void SimpleRules()
        {
            var any   = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var rule1 = new CompoundingRule {
                Name = "rule1"
            };

            Allophonic.MorphologicalRules.Add(rule1);
            rule1.Subrules.Add(new CompoundingSubrule
            {
                HeadLhs    = { Pattern <Word, ShapeNode> .New("head").Annotation(any).OneOrMore.Value },
                NonHeadLhs = { Pattern <Word, ShapeNode> .New("nonHead").Annotation(any).OneOrMore.Value },
                Rhs        = { new CopyFromInput("head"), new InsertSegments(Table3, "+"), new CopyFromInput("nonHead") }
            });

            var         morpher = new Morpher(TraceManager, Language);
            List <Word> output  = morpher.ParseWord("pʰutdat").ToList();

            AssertMorphsEqual(output, "5 8", "5 9");
            AssertRootAllomorphsEquals(output, "5");
            Assert.That(morpher.ParseWord("pʰutdas"), Is.Empty);
            Assert.That(morpher.ParseWord("pʰusdat"), Is.Empty);

            rule1.Subrules.Clear();
            rule1.Subrules.Add(new CompoundingSubrule
            {
                HeadLhs    = { Pattern <Word, ShapeNode> .New("head").Annotation(any).OneOrMore.Value },
                NonHeadLhs = { Pattern <Word, ShapeNode> .New("nonHead").Annotation(any).OneOrMore.Value },
                Rhs        = { new CopyFromInput("nonHead"), new InsertSegments(Table3, "+"), new CopyFromInput("head") }
            });

            morpher = new Morpher(TraceManager, Language);
            output  = morpher.ParseWord("pʰutdat").ToList();
            AssertMorphsEqual(output, "5 8", "5 9");
            AssertRootAllomorphsEquals(output, "8", "9");
            Assert.That(morpher.ParseWord("pʰutdas"), Is.Empty);
            Assert.That(morpher.ParseWord("pʰusdat"), Is.Empty);

            var prefix = new AffixProcessRule
            {
                Name  = "prefix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct      = FeatureStruct.New(Language.SyntacticFeatureSystem)
                                                 .Feature(Head).EqualTo(head => head
                                                                        .Feature("tense").EqualTo("past")).Value
            };

            Allophonic.MorphologicalRules.Insert(0, prefix);
            prefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = { Pattern <Word, ShapeNode> .New("1").Annotation(any).OneOrMore.Value },
                Rhs = { new InsertSegments(Table3, "di+"), new CopyFromInput("1") }
            });

            morpher = new Morpher(TraceManager, Language);
            output  = morpher.ParseWord("pʰutdidat").ToList();
            AssertMorphsEqual(output, "5 PAST 9");
            AssertRootAllomorphsEquals(output, "9");

            Allophonic.MorphologicalRules.RemoveAt(0);

            rule1.MaxApplicationCount = 2;
            rule1.Subrules.Clear();
            rule1.Subrules.Add(new CompoundingSubrule
            {
                HeadLhs    = { Pattern <Word, ShapeNode> .New("head").Annotation(any).OneOrMore.Value },
                NonHeadLhs = { Pattern <Word, ShapeNode> .New("nonHead").Annotation(any).OneOrMore.Value },
                Rhs        = { new CopyFromInput("head"), new InsertSegments(Table3, "+"), new CopyFromInput("nonHead") }
            });

            morpher = new Morpher(TraceManager, Language)
            {
                MaxStemCount = 3
            };
            output = morpher.ParseWord("pʰutdatpip").ToList();
            AssertMorphsEqual(output, "5 8 41", "5 9 41");
            AssertRootAllomorphsEquals(output, "5");

            rule1.MaxApplicationCount = 1;

            var rule2 = new CompoundingRule {
                Name = "rule2"
            };

            Allophonic.MorphologicalRules.Add(rule2);
            rule2.Subrules.Add(new CompoundingSubrule
            {
                HeadLhs    = { Pattern <Word, ShapeNode> .New("head").Annotation(any).OneOrMore.Value },
                NonHeadLhs = { Pattern <Word, ShapeNode> .New("nonHead").Annotation(any).OneOrMore.Value },
                Rhs        = { new CopyFromInput("nonHead"), new InsertSegments(Table3, "+"), new CopyFromInput("head") }
            });

            morpher = new Morpher(TraceManager, Language)
            {
                MaxStemCount = 3
            };
            output = morpher.ParseWord("pʰutdatpip").ToList();
            AssertMorphsEqual(output, "5 8 41", "5 9 41");
            AssertRootAllomorphsEquals(output, "8", "9");
        }