Beispiel #1
0
 public SynthesisCompoundingRule(Morpher morpher, CompoundingRule rule)
 {
     _morpher         = morpher;
     _rule            = rule;
     _subruleMatchers = new List <Tuple <Matcher <Word, ShapeNode>, Matcher <Word, ShapeNode> > >();
     foreach (CompoundingSubrule sr in rule.Subrules)
     {
         _subruleMatchers.Add(Tuple.Create(BuildMatcher(sr.HeadLhs), BuildMatcher(sr.NonHeadLhs)));
     }
 }
Beispiel #2
0
        public void MorphosyntacticRules()
        {
            var any   = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var rule1 = new CompoundingRule
            {
                Name = "rule1",
                NonHeadRequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                                                        .Symbol("V").Value
            };

            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 9");
            AssertRootAllomorphsEquals(output, "5");
            AssertSyntacticFeatureStructsEqual(output,
                                               FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value);
            Assert.That(morpher.ParseWord("pʰutbupu"), Is.Empty);

            Assert.That(morpher.GenerateWords(Entries["5"], new Morpheme[] { Entries["9"] }, new FeatureStruct()),
                        Is.EquivalentTo(new[] { "pʰutdat" }));

            rule1.OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value;

            morpher = new Morpher(TraceManager, Language);
            output  = morpher.ParseWord("pʰutdat").ToList();
            AssertMorphsEqual(output, "5 9");
            AssertRootAllomorphsEquals(output, "5");
            AssertSyntacticFeatureStructsEqual(output,
                                               FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value);

            Allophonic.MorphologicalRules.Clear();
            Morphophonemic.MorphologicalRules.Add(rule1);
            rule1.HeadRequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                                                       .Symbol("V")
                                                       .Feature(Head).EqualTo(head => head
                                                                              .Feature("pers").EqualTo("2")).Value;
            rule1.NonHeadRequiredSyntacticFeatureStruct = FeatureStruct.New().Value;

            morpher = new Morpher(TraceManager, Language);
            output  = morpher.ParseWord("ssagabba").ToList();
            AssertMorphsEqual(output, "Perc0 39", "Perc0 40", "Perc3 39", "Perc3 40");
            AssertRootAllomorphsEquals(output, "Perc0", "Perc3");
        }
        public AnalysisCompoundingRule(Morpher morpher, CompoundingRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            _rules = new List <IRule <Word, ShapeNode> >();
            foreach (CompoundingSubrule sr in rule.Subrules)
            {
                _rules.Add(new MultiplePatternRule <Word, ShapeNode>(new AnalysisCompoundingSubruleRuleSpec(sr),
                                                                     new MatcherSettings <ShapeNode>
                {
                    Filter          = ann => ann.Type() == HCFeatureSystem.Segment,
                    MatchingMethod  = MatchingMethod.Unification,
                    AnchoredToStart = true,
                    AnchoredToEnd   = true,
                    AllSubmatches   = true
                }));
            }
        }
Beispiel #4
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");
        }