public SynthesisRealizationalAffixProcessRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, RealizationalAffixProcessRule rule)
 {
     _morpher = morpher;
     _rule    = rule;
     _rules   = new List <PatternRule <Word, ShapeNode> >();
     foreach (AffixProcessAllomorph allo in rule.Allomorphs)
     {
         _rules.Add(new PatternRule <Word, ShapeNode>(spanFactory, new SynthesisAffixProcessAllomorphRuleSpec(allo),
                                                      new MatcherSettings <ShapeNode>
         {
             Filter          = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Boundary) && !ann.IsDeleted(),
             AnchoredToStart = true,
             AnchoredToEnd   = true
         }));
     }
 }
Esempio n. 2
0
        public AnalysisRealizationalAffixProcessRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, RealizationalAffixProcessRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            _rules = new List <PatternRule <Word, ShapeNode> >();
            foreach (AffixProcessAllomorph allo in rule.Allomorphs)
            {
                _rules.Add(new MultiplePatternRule <Word, ShapeNode>(spanFactory, new AnalysisAffixProcessAllomorphRuleSpec(allo),
                                                                     new MatcherSettings <ShapeNode>
                {
                    Filter          = ann => ann.Type() == HCFeatureSystem.Segment,
                    MatchingMethod  = MatchingMethod.Unification,
                    AnchoredToStart = true,
                    AnchoredToEnd   = true,
                    AllSubmatches   = true
                }));
            }
        }
Esempio n. 3
0
        public void RealizationalRule()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var alvStop = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("strident-")
                .Symbol("del_rel-")
                .Symbol("alveolar").Value;
            var voicelessCons = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("vd-").Value;
            var labiodental = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("labiodental").Value;
            var voiced = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("vd+").Value;
            var strident = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("strident+").Value;

            var edSuffix = new RealizationalAffixProcessRule
            {
                Name = "ed_suffix",
                RealizationalFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("tense").EqualTo("past")).Value,
                Gloss = "PAST"
            };

            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(alvStop).Value
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new InsertSegments(Table3, "ɯd")}
            });
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Annotation(voicelessCons).Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "t")}
            });
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "d")}
            });

            var sSuffix = new RealizationalAffixProcessRule
            {
                Name = "s_suffix",
                RealizationalFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")
                        .Feature("tense").EqualTo("pres")).Value,
                Gloss = "3SG"
            };

            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(labiodental).Value
                },
                Rhs = {new CopyFromInput("1"), new ModifyFromInput("2", voiced), new InsertSegments(Table3, "z")}
            });
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Annotation(strident).Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "ɯz")}
            });
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(voicelessCons).Value
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new InsertSegments(Table3, "s")}
            });
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "z")}
            });

            var evidential = new RealizationalAffixProcessRule
            {
                Name = "evidential",
                RealizationalFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("evidential").EqualTo("witnessed")).Value,
                Gloss = "WIT"
            };

            evidential.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "v")}
            });

            var verbTemplate = new AffixTemplate { Name = "verb", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value };
            verbTemplate.Slots.Add(new AffixTemplateSlot(sSuffix, edSuffix) {Optional = true});
            verbTemplate.Slots.Add(new AffixTemplateSlot(evidential) {Optional = true});
            Morphophonemic.AffixTemplates.Add(verbTemplate);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            Word[] output = morpher.ParseWord("sagd").ToArray();
            AssertMorphsEqual(output, "32 PAST");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("tense").EqualTo("past")).Value);
            output = morpher.ParseWord("sagdv").ToArray();
            AssertMorphsEqual(output, "32 PAST WIT");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("tense").EqualTo("past")
                    .Feature("evidential").EqualTo("witnessed")).Value);
            Assert.That(morpher.ParseWord("sid"), Is.Empty);
            output = morpher.ParseWord("sau").ToArray();
            AssertMorphsEqual(output, "bl2");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("tense").EqualTo("past")).Value);

            evidential.RealizationalFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("evidential").EqualTo("witnessed")
                    .Feature("tense").EqualTo("pres")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("sagzv").ToArray();
            AssertMorphsEqual(output, "32 3SG WIT");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("3")
                    .Feature("tense").EqualTo("pres")
                    .Feature("evidential").EqualTo("witnessed")).Value);
        }
Esempio n. 4
0
        private bool TryLoadRealizationalRule(XElement realRuleElem, CharacterDefinitionTable defaultTable, out IMorphologicalRule mrule)
        {
            var realRuleID = (string) realRuleElem.Attribute("id");
            var realRule = new RealizationalAffixProcessRule
            {
                Name = (string) realRuleElem.Element("Name"),
                Gloss = (string) realRuleElem.Element("Gloss"),
                Blockable = (bool?) realRuleElem.Attribute("blockable") ?? true
            };

            var fs = new FeatureStruct();
            XElement requiredHeadFeatElem = realRuleElem.Element("RequiredHeadFeatures");
            if (requiredHeadFeatElem != null)
                fs.AddValue(_headFeature, LoadFeatureStruct(requiredHeadFeatElem, _language.SyntacticFeatureSystem));
            XElement requiredFootFeatElem = realRuleElem.Element("RequiredFootFeatures");
            if (requiredFootFeatElem != null)
                fs.AddValue(_footFeature, LoadFeatureStruct(requiredFootFeatElem, _language.SyntacticFeatureSystem));
            fs.Freeze();
            realRule.RequiredSyntacticFeatureStruct = fs;

            XElement realFeatElem = realRuleElem.Element("RealizationalFeatures");
            if (realFeatElem != null)
                realRule.RealizationalFeatureStruct = FeatureStruct.New().Feature(_headFeature).EqualTo(LoadFeatureStruct(realFeatElem, _language.SyntacticFeatureSystem)).Value;
            LoadProperties(realRuleElem.Element("Properties"), realRule.Properties);

            foreach (XElement subruleElem in realRuleElem.Elements("MorphologicalSubrules").Elements("MorphologicalSubrule").Where(IsActive))
            {
                try
                {
                    AffixProcessAllomorph allomorph = LoadAffixProcessAllomorph(subruleElem, defaultTable);
                    realRule.Allomorphs.Add(allomorph);
                    _allomorphs[(string) subruleElem.Attribute("id")] = allomorph;
                }
                catch (Exception e)
                {
                    if (_errorHandler != null)
                        _errorHandler(e, (string) realRuleElem.Attribute("id"));
                    else
                        throw;
                }
            }

            if (realRule.Allomorphs.Count > 0)
            {
                _morphemes[realRuleID] = realRule;
                mrule = realRule;
                return true;
            }

            mrule = null;
            return false;
        }