Esempio n. 1
0
        public void ComplexRule()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var rule1 = new MetathesisRule
                            {
                                Name = "rule1",
                                Pattern = Pattern<Word, ShapeNode>.New()
                                    .Group("1", group => group.Annotation(Char(Table3, "i")))
                                    .Group("middle", group => group.Annotation(Char(Table3, "+")))
                                    .Group("2", group => group.Annotation(Char(Table3, "u")))
                                    .Group("rightEnv", group => group.Annotation(HCFeatureSystem.RightSideAnchor)).Value,
                                LeftSwitchName = "2",
                                RightSwitchName = "1"
                            };
            Morphophonemic.PhonologicalRules.Add(rule1);

            var uSuffix = new AffixProcessRule
                          	{
                                Name = "u_suffix",
                          		Gloss = "3SG"
                          	};
            Morphophonemic.MorphologicalRules.Add(uSuffix);
            uSuffix.Allomorphs.Add(new AffixProcessAllomorph
                                    {
                                        Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                                        Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+u")}
                                    });

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("mui"), "53 3SG");
        }
        public void CircumfixRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var circumfix = new AffixProcessRule
            {
                Name = "circumfix",
                Gloss = "OBJ"
            };
            circumfix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "ta"), new CopyFromInput("1"), new InsertSegments(Table3, "od")}
            });
            Morphophonemic.MorphologicalRules.Add(circumfix);

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "3SG"
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "s")}
            });
            Morphophonemic.MorphologicalRules.Add(sSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("tasagods"), "OBJ 32 3SG");
        }
Esempio n. 3
0
        public void SimpleRule()
        {
            var rule1 = new MetathesisRule
                            {
                                Name = "rule1",
                                Pattern = Pattern<Word, ShapeNode>.New()
                                    .Group("1", group => group.Annotation(Char(Table3, "i")))
                                    .Group("2", group => group.Annotation(Char(Table3, "u"))).Value,
                                LeftSwitchName = "2",
                                RightSwitchName = "1"
                            };
            Morphophonemic.PhonologicalRules.Add(rule1);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("mui"), "51");
        }
Esempio n. 4
0
        public SynthesisMetathesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, MetathesisRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            var ruleSpec = new SynthesisMetathesisRuleSpec(spanFactory, rule.Pattern, rule.LeftSwitchName, rule.RightSwitchName);

            var settings = new MatcherSettings <ShapeNode>
            {
                Direction   = rule.Direction,
                Filter      = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Boundary, HCFeatureSystem.Anchor) && !ann.IsDeleted(),
                UseDefaults = true
            };

            _patternRule = new IterativePhonologicalPatternRule(spanFactory, ruleSpec, settings);
        }
Esempio n. 5
0
        public void AffixTemplateAppliedAfterMorphologicalRule()
        {
            var any         = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var nominalizer = new AffixProcessRule
            {
                Name  = "nominalizer",
                Gloss = "NOM",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct      = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };

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

            var sSuffix = new AffixProcessRule
            {
                Name  = "s_suffix",
                Gloss = "PL",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };

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

            var nounTemplate = new AffixTemplate {
                Name = "noun", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };

            nounTemplate.Slots.Add(new AffixTemplateSlot(sSuffix)
            {
                Optional = true
            });
            Morphophonemic.AffixTemplates.Add(nounTemplate);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);

            AssertMorphsEqual(morpher.ParseWord("sagv"), "32 NOM");
            AssertMorphsEqual(morpher.ParseWord("sagvs"), "32 NOM PL");
        }
 public SynthesisAffixProcessRule(SpanFactory <ShapeNode> spanFactory, 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>(spanFactory, ruleSpec,
                                                      new MatcherSettings <ShapeNode>
         {
             Filter          = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Boundary) && !ann.IsDeleted(),
             AnchoredToStart = true,
             AnchoredToEnd   = true
         }));
     }
 }
Esempio n. 7
0
        public static TResult Morph <TResult, TArgument>(
            ref int target,
            TArgument argument,
            Morpher <TResult, TArgument> morpher)
        {
            TResult morphResult;
            int     currentVal = target, startVal, desiredVal;

            do
            {
                startVal   = currentVal;
                desiredVal = morpher(startVal, argument, out morphResult);
                currentVal =
                    Interlocked.CompareExchange(ref target, desiredVal, startVal);                     // Generic overload! Can be generalized!!!
            } while (startVal != currentVal);

            return(morphResult);
        }
Esempio n. 8
0
        internal override bool IsWordValid(Morpher morpher, Word word)
        {
            if (!base.IsWordValid(morpher, word))
            {
                return(false);
            }

            if (!RequiredSyntacticFeatureStruct.IsUnifiable(word.SyntacticFeatureStruct))
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.RequiredSyntacticFeatureStruct, this, RequiredSyntacticFeatureStruct);
                }
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary> Tells the story in the chosen language. </summary>
        static IEnumerable<string> TellStory (Dictionary <string, string> dict, Morpher.IDynamicDeclension grammar)
        {
            // THE PLOT. See if you can read the story from it!
            var story = new [] 
            {
                new {Verb = "title",     Actors = ""},
                new {Verb = "likes2",    Actors = "bob,alice,photo"},
                new {Verb = "commented", Actors = "bob,alice,photo"},
                new {Verb = "emailed",   Actors = "bob,alice"},
                new {Verb = "likes",     Actors = "bob,alice"},
                new {Verb = "likes",     Actors = "alice,celebrity"},
            };

            return story.Select (sentence => Regex.Replace (
                string.Format (dict [sentence.Verb], sentence.Actors.Split (',')), 
                @"<(?<id>\w*)(:(?<format>\w*))?>",
                match => GetDeclension (dict [match.Groups ["id"].Value], match.Groups ["format"].Value, grammar)));
        }
Esempio n. 10
0
        public void SimpleRule()
        {
            var rule1 = new MetathesisRule
            {
                Name    = "rule1",
                Pattern = Pattern <Word, ShapeNode> .New()
                          .Group("1", group => group.Annotation(Char(Table3, "i")))
                          .Group("2", group => group.Annotation(Char(Table3, "u"))).Value,
                LeftSwitchName  = "2",
                RightSwitchName = "1"
            };

            Morphophonemic.PhonologicalRules.Add(rule1);

            var morpher = new Morpher(TraceManager, Language);

            AssertMorphsEqual(morpher.ParseWord("mui"), "51");
        }
Esempio n. 11
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(SpanFactory, 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);

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

            morpher = new Morpher(SpanFactory, 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(SpanFactory, TraceManager, Language);
            output  = morpher.ParseWord("ssagabba").ToList();
            AssertMorphsEqual(output, "Perc0 39", "Perc0 40", "Perc3 39", "Perc3 40");
            AssertRootAllomorphsEquals(output, "Perc0", "Perc3");
        }
Esempio n. 12
0
        private void LexKag(string input, string title = "input")
        {
            ClearLog();
            DateTime opStart = DateTime.Now;

            Token token;
            var   reader  = new StringSourceReader(title, input);
            var   lexer   = new Lexer(reader);
            var   morpher = new Morpher(lexer);
            var   sb      = new StringBuilder();

            do
            {
                try
                {
                    token = morpher.ReadToken();
                }
                catch (ParseException ex)
                {
                    sb.AppendLine(Environment.NewLine +
                                  ex.Position + Environment.NewLine +
                                  ex.GetType() + Environment.NewLine +
                                  ex.Message + Environment.NewLine);
                    break;
                }
                catch (Exception ex)
                {
                    sb.AppendLine(Environment.NewLine +
                                  ex.GetType() + Environment.NewLine +
                                  ex.Message + Environment.NewLine);
                    break;
                }
                if (DisplayOutput(title))
                {
                    sb.AppendLine(token.ToString());
                }
            } while (token.Type != TokenType.Eof);

            DateTime opEnd    = DateTime.Now;
            TimeSpan duration = opEnd - opStart;

            sb.AppendLine($"Done in {duration.TotalMilliseconds}ms." + Environment.NewLine);
            Log(sb.ToString());
        }
Esempio n. 13
0
        public AnalysisMetathesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, MetathesisRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            var ruleSpec = new AnalysisMetathesisRuleSpec(rule.Pattern, rule.LeftSwitchName, rule.RightSwitchName);

            var settings = new MatcherSettings <ShapeNode>
            {
                Direction      = rule.Direction == Direction.LeftToRight ? Direction.RightToLeft : Direction.LeftToRight,
                Filter         = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Anchor),
                MatchingMethod = MatchingMethod.Unification,
                UseDefaults    = true,
                // during analysis shape nodes can have features that are underspecified, so this must be non-deterministic
                Nondeterministic = true
            };

            _patternRule = new IterativePhonologicalPatternRule(spanFactory, ruleSpec, settings);
        }
        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
                }));
            }
        }
Esempio n. 15
0
        public AnalysisCompoundingRule(SpanFactory <ShapeNode> spanFactory, 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>(spanFactory, new AnalysisCompoundingSubruleRuleSpec(sr),
                                                                     new MatcherSettings <ShapeNode>
                {
                    Filter          = ann => ann.Type() == HCFeatureSystem.Segment,
                    MatchingMethod  = MatchingMethod.Unification,
                    AnchoredToStart = true,
                    AnchoredToEnd   = true,
                    AllSubmatches   = true
                }));
            }
        }
Esempio n. 16
0
        public override string GetPossessiveName(GDMIndividualRecord iRec)
        {
            var nameParts = GKUtils.GetNameParts(iRec);
            var gender    = DeclGenders[(int)iRec.Sex];

            string result  = "";
            string surname = nameParts.Surname.Trim();

            int p = surname.IndexOf('(');

            if (p >= 0)
            {
                string part = surname.Substring(0, p).Trim();
                if (part != "")
                {
                    result  = Morpher.GetDeclension(part, DeclensionCase.Genitive, gender, "1", 1);
                    result += " ";
                }
                part = surname.Substring(p).Trim();
                part = part.Substring(1, part.Length - 2);

                result += "(";
                string[] parts = part.Split(',');
                for (int i = 0; i < parts.Length; i++)
                {
                    if (i > 0)
                    {
                        result += "(";
                    }
                    part    = Morpher.GetDeclension(parts[i], DeclensionCase.Genitive, gender, "1", 1);
                    result += part;
                }
                result += ")";
            }
            else
            {
                result = Morpher.GetDeclension(surname, DeclensionCase.Genitive, gender, "1", 1);
            }

            result += " " + Morpher.GetDeclension(nameParts.Name + " " + nameParts.Patronymic, DeclensionCase.Genitive, gender, "23", 2);
            return(result);
        }
        public ITranslationEngine Create(Engine engine)
        {
            string         hcSrcConfigFileName = Path.Combine(engine.ConfigDirectory, "src-hc.xml");
            string         hcTrgConfigFileName = Path.Combine(engine.ConfigDirectory, "trg-hc.xml");
            TransferEngine transferEngine      = null;

            if (File.Exists(hcSrcConfigFileName) && File.Exists(hcTrgConfigFileName))
            {
                var spanFactory    = new ShapeSpanFactory();
                var hcTraceManager = new TraceManager();

                Language srcLang    = XmlLanguageLoader.Load(hcSrcConfigFileName);
                var      srcMorpher = new Morpher(spanFactory, hcTraceManager, srcLang);

                Language trgLang    = XmlLanguageLoader.Load(hcTrgConfigFileName);
                var      trgMorpher = new Morpher(spanFactory, hcTraceManager, trgLang);

                transferEngine = new TransferEngine(srcMorpher, new SimpleTransferer(new GlossMorphemeMapper(trgMorpher)), trgMorpher);
            }
            return(transferEngine);
        }
Esempio n. 18
0
        public ITranslationEngine Create(string engineId)
        {
            string         engineDir           = Path.Combine(_engineOptions.Value.EnginesDir, engineId);
            string         hcSrcConfigFileName = Path.Combine(engineDir, "src-hc.xml");
            string         hcTrgConfigFileName = Path.Combine(engineDir, "trg-hc.xml");
            TransferEngine transferEngine      = null;

            if (File.Exists(hcSrcConfigFileName) && File.Exists(hcTrgConfigFileName))
            {
                var hcTraceManager = new TraceManager();

                Language srcLang    = XmlLanguageLoader.Load(hcSrcConfigFileName);
                var      srcMorpher = new Morpher(hcTraceManager, srcLang);

                Language trgLang    = XmlLanguageLoader.Load(hcTrgConfigFileName);
                var      trgMorpher = new Morpher(hcTraceManager, trgLang);

                transferEngine = new TransferEngine(srcMorpher, new SimpleTransferer(new GlossMorphemeMapper(trgMorpher)), trgMorpher);
            }
            return(transferEngine);
        }
Esempio n. 19
0
        public void BoundRootAllomorph()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value
            };
            Morphophonemic.MorphologicalRules.Add(edSuffix);
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+ɯd")}
            });

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            Assert.That(morpher.ParseWord("dag"), Is.Empty);
            AssertMorphsEqual(morpher.ParseWord("dagɯd"), "bound PAST");
        }
Esempio n. 20
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(SpanFactory, 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);

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

            morpher = new Morpher(SpanFactory, 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(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagabba").ToList();
            AssertMorphsEqual(output, "Perc0 39", "Perc0 40", "Perc3 39", "Perc3 40");
            AssertRootAllomorphsEquals(output, "Perc0", "Perc3");
        }
Esempio n. 21
0
        public void AffixTemplateAppliedAfterMorphologicalRule()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var nominalizer = new AffixProcessRule
            {
                Name = "nominalizer",
                Gloss = "NOM",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };

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

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "PL",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };

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

            var nounTemplate = new AffixTemplate {Name = "noun", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value};
            nounTemplate.Slots.Add(new AffixTemplateSlot(sSuffix) {Optional = true});
            Morphophonemic.AffixTemplates.Add(nounTemplate);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagv"), "32 NOM");
            AssertMorphsEqual(morpher.ParseWord("sagvs"), "32 NOM PL");
        }
Esempio n. 22
0
        public void FreeFluctuation()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var d   = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                      .Symbol(HCFeatureSystem.Segment)
                      .Symbol("cons+")
                      .Symbol("strident-")
                      .Symbol("del_rel-")
                      .Symbol("alveolar")
                      .Symbol("nasal-")
                      .Symbol("vd+").Value;

            var edSuffix = new AffixProcessRule
            {
                Name  = "ed_suffix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value
            };

            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = { Pattern <Word, ShapeNode> .New("1").Annotation(any).OneOrMore.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, "+"), new InsertSimpleContext(d) }
            });
            Morphophonemic.MorphologicalRules.Add(edSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);

            AssertMorphsEqual(morpher.ParseWord("tazd"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tast"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tazt"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tasd"), "free PAST");
        }
Esempio n. 23
0
        private void LoadParser()
        {
            m_morpher = null;

            int    delReapps      = 0;
            string loadErrorsFile = Path.Combine(m_outputDirectory, m_cache.ProjectId.Name + "HCLoadErrors.xml");

            using (XmlWriter writer = XmlWriter.Create(loadErrorsFile))
                using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance <IWorkerThreadReadHandler>()))
                {
                    m_language = HCLoader.Load(m_spanFactory, m_cache, writer);
                    XElement parserParamsElem = XElement.Parse(m_cache.LanguageProject.MorphologicalDataOA.ParserParameters);
                    XElement delReappsElem    = parserParamsElem.Elements("ParserParameters").Elements("HC").Elements("DelReapps").FirstOrDefault();
                    if (delReappsElem != null)
                    {
                        delReapps = (int)delReappsElem;
                    }
                }
            m_morpher = new Morpher(m_spanFactory, m_traceManager, m_language)
            {
                DeletionReapplications = delReapps
            };
        }
Esempio n. 24
0
        public void BoundRootAllomorph()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var edSuffix = new AffixProcessRule
            {
                Name  = "ed_suffix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value
            };

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

            var morpher = new Morpher(SpanFactory, TraceManager, Language);

            Assert.That(morpher.ParseWord("dag"), Is.Empty);
            AssertMorphsEqual(morpher.ParseWord("dagɯd"), "bound PAST");
        }
Esempio n. 25
0
    public override void ShootTheBitch(int x, int y)
    {
        Jobster jb  = GameObject.Find("jobster").GetComponent <Jobster>();
        Morpher mph = GameObject.Find("Morpher").GetComponent <Morpher>();

        if (!jb.startedGame.AI.currentField.cells[x, y].IsShot)
        {
            jb.startedGame.AI.currentField.cells[x, y].IsShot = true;
            if (jb.startedGame.AI.currentField.cells[x, y].HasShip)
            {
                jb.startedGame.WhosTurn = 1;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < jb.startedGame.AI.ships[i].Size; j++)
                    {
                        Cell c = jb.startedGame.AI.ships[i].GetCell(j);
                        if (x == c.X && y == c.Y)
                        {
                            jb.startedGame.AI.ships[i].ShotIncrease();
                            mph.InstShotCell(x, y, 2, 's');
                            jb.PlayExplosion();
                        }
                    }
                }
            }
            else
            {
                jb.startedGame.WhosTurn = 2;
                mph.InstShotCell(x, y, 2, 'm');
                jb.PlayMiss();
            }
        }
        else
        {
            jb.startedGame.WhosTurn = 1;
        }
    }
Esempio n. 26
0
    public GridCell(int _x, int _y, bool _hasBrick, char brickTypeChar = '\0')
    {
        this.cellCoords.x = _x;
        this.cellCoords.y = _y;
        this.hasBrick     = _hasBrick;

        Morpher morph = GameObject.Find("Morpher").GetComponent <Morpher>();

        try
        {
            if (this.hasBrick)
            {
                this.realObjRef = morph.MorphBrick(this.cellCoords.x, this.cellCoords.y, brickTypeChar);
            }
        }
        catch (UnityException e)
        {
            this.cellCoords.x = -1;
            this.cellCoords.y = -1;

#if UNITY_EDITOR
            Debug.LogError("Can't instantiate Brick in Cell");
            Debug.LogError(e.Message);
            return;
#else
            //do later: handle exceptions to the main menu with a popup informing of the exception
            Application.Quit();
#endif
        }
        finally
        {
            if (this.realObjRef != null)
            {
                this.realObjRef.GetComponent <BrickObjectHandler>().SetCoordinates(this.cellCoords);
            }
        }
    }
Esempio n. 27
0
        public void ComplexRule()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var rule1 = new MetathesisRule
            {
                Name    = "rule1",
                Pattern = Pattern <Word, ShapeNode> .New()
                          .Group("1", group => group.Annotation(Char(Table3, "i")))
                          .Group("middle", group => group.Annotation(Char(Table3, "+")))
                          .Group("2", group => group.Annotation(Char(Table3, "u")))
                          .Group("rightEnv", group => group.Annotation(HCFeatureSystem.RightSideAnchor)).Value,
                LeftSwitchName  = "2",
                RightSwitchName = "1"
            };

            Morphophonemic.PhonologicalRules.Add(rule1);

            var uSuffix = new AffixProcessRule
            {
                Name  = "u_suffix",
                Gloss = "3SG"
            };

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

            var morpher = new Morpher(TraceManager, Language);

            AssertMorphsEqual(morpher.ParseWord("mui"), "53 3SG");
        }
Esempio n. 28
0
        public void BoundaryRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var cons = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+").Value;
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons-").Value;

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "3SG",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")).Value
            };
            Morphophonemic.MorphologicalRules.Add(sSuffix);
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2")
                        .Annotation(FeatureStruct.New().Symbol(HCFeatureSystem.Boundary).Feature(HCFeatureSystem.StrRep).EqualTo("+").Value)
                        .Annotation(cons)
                        .Annotation(vowel).Value
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new InsertSegments(Table3, "s")}
            });

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("abbas"), "39 3SG");
        }
Esempio n. 29
0
        public void NonFinalTemplate()
        {
            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 edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                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 verbTemplate = new AffixTemplate {Name = "verb", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value};
            verbTemplate.Slots.Add(new AffixTemplateSlot(edSuffix));
            Morphophonemic.AffixTemplates.Add(verbTemplate);

            var nominalizer = new AffixProcessRule
            {
                Name = "nominalizer",
                Gloss = "NOM",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };
            nominalizer.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "v")}
            });
            Morphophonemic.MorphologicalRules.Add(nominalizer);

            var crule = new CompoundingRule
            {
                Name = "rule1",
                HeadRequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                NonHeadRequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };
            crule.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")}
            });
            Morphophonemic.MorphologicalRules.Add(crule);

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "PL",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "s")}
            });

            var nounTemplate = new AffixTemplate {Name = "noun", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value};
            nounTemplate.Slots.Add(new AffixTemplateSlot(sSuffix) {Optional = true});
            Morphophonemic.AffixTemplates.Add(nounTemplate);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagd"), "32 PAST");
            AssertMorphsEqual(morpher.ParseWord("sagdv"));
            AssertMorphsEqual(morpher.ParseWord("sagdvs"));
            AssertMorphsEqual(morpher.ParseWord("sagdmi"));
            AssertMorphsEqual(morpher.ParseWord("sagdmis"));

            verbTemplate.IsFinal = false;
            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagd"));
            AssertMorphsEqual(morpher.ParseWord("sagdv"), "32 PAST NOM");
            AssertMorphsEqual(morpher.ParseWord("sagdvs"), "32 PAST NOM PL");
            AssertMorphsEqual(morpher.ParseWord("sagdmi"), "32 PAST 53");
            AssertMorphsEqual(morpher.ParseWord("sagdmis"), "32 PAST 53 PL");
        }
Esempio n. 30
0
 public override IRule<Word, ShapeNode> CompileAnalysisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher)
 {
     return new AnalysisAffixProcessRule(spanFactory, morpher, this);
 }
Esempio n. 31
0
    public override void Bind()
    {
        this.CheckBindSpace();
        Morpher mph     = GameObject.Find("Morpher").GetComponent <Morpher>();
        Jobster jb      = GameObject.Find("jobster").GetComponent <Jobster>();
        int     i       = 0;
        int     barrier = this.size;

        if (this.Orientation > 0)
        {
            if (this.X > 0)
            {
                i = -1;
            }
            else
            {
                i = 0;
            }

            if (this.X + this.size < 10)
            {
                barrier += 1;
            }
        }
        else
        {
            if (this.Y > 0)
            {
                i = -1;
            }
            else
            {
                i = 0;
            }

            if (this.Y + this.size < 10)
            {
                barrier += 1;
            }
        }

        for (; i < barrier; i++)
        {
            if (this.Orientation > 0)
            {
                jb.startedGame.Human.currentField.cells[this.X + i, this.Y].IsOccupied = true;
                if (i > -1 && i < size + 1)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y].HasShip = true;
                }

                if (this.Y > 0)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y - 1].IsOccupied = true;
                }
                if (this.Y < 9)
                {
                    jb.startedGame.Human.currentField.cells[this.X + i, this.Y + 1].IsOccupied = true;
                }
            }
            else
            {
                jb.startedGame.Human.currentField.cells[this.X, this.Y + i].IsOccupied = true;
                if (i > -1 && i < size + 1)
                {
                    jb.startedGame.Human.currentField.cells[this.X, this.Y + i].HasShip = true;
                }

                if (this.X > 0)
                {
                    jb.startedGame.Human.currentField.cells[this.X - 1, this.Y + i].IsOccupied = true;
                }
                if (this.X < 9)
                {
                    jb.startedGame.Human.currentField.cells[this.X + 1, this.Y + i].IsOccupied = true;
                }
            }
        }

        for (int k = 0; k < this.size; k++)
        {
            if (this.Orientation > 0)
            {
                this.cells[k] = jb.startedGame.Human.currentField.cells[this.X + k, this.Y];
            }
            else
            {
                this.cells[k] = jb.startedGame.Human.currentField.cells[this.X, this.Y + k];
            }
        }

        mph.InstAShip(this.Orientation);
        EventManager.OnBindShip -= this.Bind;
    }
Esempio n. 32
0
        public static TResult Morph <TResult, TArgument>(ref Int32 target, TArgument argument, Morpher <TResult, TArgument> morpher)
        {
            TResult morphResult;
            Int32   currentVal = target, startVal, desiredVal;

            do
            {
                startVal   = currentVal;
                desiredVal = morpher(startVal, argument, out morphResult);
                currentVal = Interlocked.CompareExchange(ref target, desiredVal, startVal);
            } while (startVal != currentVal);
            return(morphResult);
        }
Esempio n. 33
0
 public override IRule <Word, ShapeNode> CompileAnalysisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new AnalysisAffixProcessRule(spanFactory, morpher, this));
 }
Esempio n. 34
0
        public void StemNames()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "1",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("1")).Value
            };
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+ɯd")}
            });
            Morphophonemic.MorphologicalRules.Add(edSuffix);

            var tSuffix = new AffixProcessRule
            {
                Name = "t_suffix",
                Gloss = "2",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("2")).Value
            };
            tSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+t")}
            });
            Morphophonemic.MorphologicalRules.Add(tSuffix);

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "3",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")).Value
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+s")}
            });
            Morphophonemic.MorphologicalRules.Add(sSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);

            AssertMorphsEqual(morpher.ParseWord("sanɯd"));
            AssertMorphsEqual(morpher.ParseWord("sant"));
            AssertMorphsEqual(morpher.ParseWord("sans"));
            AssertMorphsEqual(morpher.ParseWord("san"), "stemname");

            AssertMorphsEqual(morpher.ParseWord("sadɯd"), "stemname 1");
            AssertMorphsEqual(morpher.ParseWord("sadt"), "stemname 2");
            AssertMorphsEqual(morpher.ParseWord("sads"));
            AssertMorphsEqual(morpher.ParseWord("sad"));

            AssertMorphsEqual(morpher.ParseWord("sapɯd"), "stemname 1");
            AssertMorphsEqual(morpher.ParseWord("sapt"));
            AssertMorphsEqual(morpher.ParseWord("saps"), "stemname 3");
            AssertMorphsEqual(morpher.ParseWord("sap"));
        }
Esempio n. 35
0
 private static string GetDeclension (string s, string format, Morpher.IDynamicDeclension morpher)
 {
     return Bold (string.IsNullOrEmpty (format) ? s : morpher.GetCase (s, format));
 }
Esempio n. 36
0
        public void PartialRule()
        {
            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 edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "TEMP_VERB",
            };

            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 verbTemplate = new AffixTemplate {Name = "verb", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value};
            verbTemplate.Slots.Add(new AffixTemplateSlot(edSuffix) {Optional = true});
            Morphophonemic.AffixTemplates.Add(verbTemplate);

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "PART_VERB",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                IsPartial = true
            };

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

            var nominalizer = new AffixProcessRule
            {
                Name = "nominalizer",
                Gloss = "DERIV",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };

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

            var uSuffix = new AffixProcessRule
            {
                Name = "u_suffix",
                Gloss = "PART_NOUN",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
                IsPartial = true
            };
            uSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "u")}
            });
            Morphophonemic.MorphologicalRules.Add(uSuffix);

            var pSuffix = new AffixProcessRule
            {
                Name = "p_suffix",
                Gloss = "TEMP_NOUN",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };
            pSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "p")}
            });

            var nounTemplate = new AffixTemplate {Name = "noun", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value};
            nounTemplate.Slots.Add(new AffixTemplateSlot(pSuffix) {Optional = true});
            Morphophonemic.AffixTemplates.Add(nounTemplate);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagd"), "32 TEMP_VERB");
            AssertMorphsEqual(morpher.ParseWord("sagds"), "32 TEMP_VERB PART_VERB");
            AssertMorphsEqual(morpher.ParseWord("sagst"), "32 PART_VERB TEMP_VERB");
            AssertMorphsEqual(morpher.ParseWord("sags"), "32 PART_VERB");
            AssertMorphsEqual(morpher.ParseWord("sagsv"), "32 PART_VERB DERIV");
            AssertMorphsEqual(morpher.ParseWord("sagstv"), "32 PART_VERB TEMP_VERB DERIV");
            AssertMorphsEqual(morpher.ParseWord("sagdst"));

            AssertMorphsEqual(morpher.ParseWord("sagvu"), "32 DERIV PART_NOUN");
            AssertMorphsEqual(morpher.ParseWord("sagvup"), "32 DERIV PART_NOUN TEMP_NOUN");

            verbTemplate.IsFinal = false;
            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagds"));
        }
Esempio n. 37
0
        public void FreeFluctuation()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var d = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("strident-")
                .Symbol("del_rel-")
                .Symbol("alveolar")
                .Symbol("nasal-")
                .Symbol("vd+").Value;

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value
            };
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.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, "+"), new InsertSimpleContext(d)}
            });
            Morphophonemic.MorphologicalRules.Add(edSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("tazd"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tast"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tazt"), "free PAST");
            AssertMorphsEqual(morpher.ParseWord("tasd"), "free PAST");
        }
Esempio n. 38
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(SpanFactory, 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(SpanFactory, 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(SpanFactory, 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(SpanFactory, 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(SpanFactory, TraceManager, Language) {MaxStemCount = 3};
            output = morpher.ParseWord("pʰutdatpip").ToList();
            AssertMorphsEqual(output, "5 8 41", "5 9 41");
            AssertRootAllomorphsEquals(output, "8", "9");
        }
Esempio n. 39
0
        public void WordSynthesisWithBoundaryAtBeginning()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var cons = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+").Value;
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons-").Value;

            var htSuffix = new AffixProcessRule
            {
                Name = "ht_suffix",
                Gloss = "prefix",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value
            };
            Morphophonemic.MorphologicalRules.Add(htSuffix);
            htSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).ZeroOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(vowel).Value,
                    Pattern<Word, ShapeNode>.New("4").Annotation(cons).Value
                },
                Rhs =
                {
                    new CopyFromInput("1"),
                    new InsertSegments(Table3, "+pa"),
                    new CopyFromInput("2"),
                    new InsertSegments(Table3, "t"),
                    new CopyFromInput("3"),
                    new CopyFromInput("4")
                }
            });

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "PST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("tense").EqualTo("past")).Value
            };
            Morphophonemic.MorphologicalRules.Add(edSuffix);
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+ɯd")}
            });

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            Word[] results = morpher.ParseWord("pastagɯd").ToArray();
            AssertMorphsEqual(results, "prefix 32 PST");
            Assert.That(results[0].Shape.First.Type(), Is.EqualTo(HCFeatureSystem.Boundary));
        }
Esempio n. 40
0
        public void PercolationRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var rule1 = new AffixProcessRule
            {
                Name = "rule1",
                Gloss = "3SG",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("2")).Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("2")).Value
            };
            rule1.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "z")}
            });
            Morphophonemic.MorphologicalRules.Add(rule1);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            List<Word> output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc3 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("2")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("2", "3")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc2 3SG", "Perc3 3SG", "Perc4 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("2")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("2")).Value;
            rule1.OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("3")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc3 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("3")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("2", "3")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc2 3SG", "Perc3 3SG", "Perc4 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("3")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("4")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("3")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("2")).Value;
            rule1.OutSyntacticFeatureStruct = FeatureStruct.New().Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc3 3SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("2")).Value);

            rule1.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("pers").EqualTo("2", "3")).Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("ssagz").ToList();
            AssertMorphsEqual(output, "Perc0 3SG", "Perc2 3SG", "Perc3 3SG", "Perc4 3SG");
            AssertSyntacticFeatureStructsEqual(output.Where(w => w.RootAllomorph.Morpheme.ToString().IsOneOf("Perc0", "Perc3")), FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("2", "3")).Value);
            AssertSyntacticFeatureStructsEqual(output.Where(w => w.RootAllomorph.Morpheme.ToString().IsOneOf("Perc2", "Perc4")), FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("num").EqualTo("pl")
                    .Feature("pers").EqualTo("3")).Value);
        }
Esempio n. 41
0
        internal override bool IsWordValid(Morpher morpher, Word word)
        {
            if (!base.IsWordValid(morpher, word))
                return false;

            if (!RequiredSyntacticFeatureStruct.IsUnifiable(word.SyntacticFeatureStruct))
            {
                if (morpher.TraceManager.IsTracing)
                    morpher.TraceManager.ParseFailed(morpher.Language, word, FailureReason.RequiredSyntacticFeatureStruct, this, RequiredSyntacticFeatureStruct);
                return false;
            }

            return true;
        }
Esempio n. 42
0
 public override IRule<Word, ShapeNode> CompileSynthesisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher)
 {
     return new SynthesisMetathesisRule(spanFactory, morpher, this);
 }
Esempio n. 43
0
        public void MorphosyntacticRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "NMLZ",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "s")}
            });
            Morphophonemic.MorphologicalRules.Add(sSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            List<Word> output = morpher.ParseWord("sags").ToList();
            AssertMorphsEqual(output, "32 NMLZ");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value);

            sSuffix.Gloss = "3.SG";
            sSuffix.OutSyntacticFeatureStruct = FeatureStruct.New().Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("sags").ToList();
            AssertMorphsEqual(output, "32 3.SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value);

            sSuffix.Gloss = "NMLZ";
            sSuffix.RequiredSyntacticFeatureStruct = FeatureStruct.New().Value;
            sSuffix.OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("sags").ToList();
            AssertMorphsEqual(output, "32 NMLZ");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value);

            sSuffix.Gloss = "3.SG";
            sSuffix.RequiredSyntacticFeatureStruct = FeatureStruct.New().Value;
            sSuffix.OutSyntacticFeatureStruct = FeatureStruct.New().Value;

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            output = morpher.ParseWord("sags").ToList();
            AssertMorphsEqual(output, "32 3.SG");
            AssertSyntacticFeatureStructsEqual(output, FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value);

            sSuffix.Gloss = "NMLZ";
            sSuffix.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Symbol("V")
                .Feature(Head).EqualTo(head => head
                    .Feature("tense").EqualTo("pres")).Value;
            sSuffix.OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                .Feature(Head).EqualTo(head => head
                    .Feature("tense").EqualTo("past")).Value;
            sSuffix.Allomorphs.Clear();
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "d")}
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            Assert.That(morpher.ParseWord("sid"), Is.Empty);
        }
Esempio n. 44
0
        public void InfixRules()
        {
            var voicelessStop = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("vd-")
                .Symbol("cont-").Value;
            var cons = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+").Value;
            var unasp = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("asp-").Value;

            var perfAct = new AffixProcessRule
            {
                Name = "perf_act",
                Gloss = "PER.ACT",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Symbol("V")
                    .Feature(Head).EqualTo(head => head
                        .Feature("aspect").EqualTo("perf")
                        .Feature("mood").EqualTo("active")).Value
            };
            perfAct.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(cons).Value
                },
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "a"), new CopyFromInput("2"), new InsertSegments(Table3, "a"), new CopyFromInput("3")}
            });
            Morphophonemic.MorphologicalRules.Add(perfAct);

            var perfPass = new AffixProcessRule
            {
                Name = "pref_pass",
                Gloss = "PER.PSV",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Symbol("V")
                    .Feature(Head).EqualTo(head => head
                        .Feature("aspect").EqualTo("perf")
                        .Feature("mood").EqualTo("passive")).Value
            };
            perfPass.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(cons).Value
                },
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "u"), new CopyFromInput("2"), new InsertSegments(Table3, "i"), new CopyFromInput("3")}
            });
            Morphophonemic.MorphologicalRules.Add(perfPass);

            var imperfAct = new AffixProcessRule
            {
                Name = "imperf_act",
                Gloss = "IMPF.ACT",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Symbol("V")
                    .Feature(Head).EqualTo(head => head
                        .Feature("aspect").EqualTo("impf")
                        .Feature("mood").EqualTo("active")).Value
            };
            imperfAct.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Value
                },
                Rhs = {new InsertSegments(Table3, "a"), new CopyFromInput("1"), new InsertSegments(Table3, "u"), new CopyFromInput("2")}
            });
            Morphophonemic.MorphologicalRules.Add(imperfAct);

            var imperfPass = new AffixProcessRule
            {
                Name = "imperf_pass",
                Gloss = "IMPF.PSV",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Symbol("V")
                    .Feature(Head).EqualTo(head => head
                        .Feature("aspect").EqualTo("impf")
                        .Feature("mood").EqualTo("passive")).Value
            };
            imperfPass.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(cons).Value
                },
                Rhs = {new InsertSegments(Table3, "u"), new CopyFromInput("1"), new CopyFromInput("2"), new InsertSegments(Table3, "a"), new CopyFromInput("3")}
            });
            Morphophonemic.MorphologicalRules.Add(imperfPass);

            var aspiration = new RewriteRule {Name = "aspiration", Lhs = Pattern<Word, ShapeNode>.New().Annotation(voicelessStop).Value};
            aspiration.Subrules.Add(new RewriteSubrule
            {
                Rhs = Pattern<Word, ShapeNode>.New().Annotation(unasp).Value,
            });
            Allophonic.PhonologicalRules.Add(aspiration);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("katab"), "49 PER.ACT");
            AssertMorphsEqual(morpher.ParseWord("kutib"), "49 PER.PSV");
            AssertMorphsEqual(morpher.ParseWord("aktub"), "IMPF.ACT 49");
            AssertMorphsEqual(morpher.ParseWord("uktab"), "IMPF.PSV 49");
        }
Esempio n. 45
0
 public override IRule <Word, ShapeNode> CompileSynthesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new SynthesisRealizationalAffixProcessRule(spanFactory, morpher, this));
 }
Esempio n. 46
0
        public void ReduplicationRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var cons = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+").Value;
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("voc+").Value;
            var voiced = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("vd+").Value;
            var affricate = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("del_rel+")
                .Symbol("cont-").Value;

            var redup = new AffixProcessRule
            {
                Name = "redup",
                Gloss = "RED",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")).Value
            };
            redup.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Annotation(vowel).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(any).OneOrMore.Value
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("1"), new CopyFromInput("2")}
            });
            Morphophonemic.MorphologicalRules.Add(redup);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sasag"), "RED 32");

            var voicing = new RewriteRule {Name = "voicing", Lhs = Pattern<Word, ShapeNode>.New().Annotation(Char(Table1, "s")).Value};
            voicing.Subrules.Add(new RewriteSubrule
            {
                Rhs = Pattern<Word, ShapeNode>.New().Annotation(voiced).Value,
                LeftEnvironment = Pattern<Word, ShapeNode>.New().Annotation(vowel).Value,
                RightEnvironment = Pattern<Word, ShapeNode>.New().Annotation(vowel).Value
            });
            Allophonic.PhonologicalRules.Add(voicing);

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sazag"), "RED 32");

            var affrication = new RewriteRule {Name = "affrication", Lhs = Pattern<Word, ShapeNode>.New().Annotation(Char(Table1, "s")).Value};
            affrication.Subrules.Add(new RewriteSubrule
            {
                Rhs = Pattern<Word, ShapeNode>.New().Annotation(affricate).Value,
                LeftEnvironment = Pattern<Word, ShapeNode>.New().Annotation(HCFeatureSystem.LeftSideAnchor).Value
            });
            Allophonic.PhonologicalRules.Add(affrication);

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("tsazag"), "RED 32");

            redup.Allomorphs.Clear();
            redup.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(vowel).Annotation(cons).Value,
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new CopyFromInput("2")}
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("tsagag"), "32 RED");

            Allophonic.PhonologicalRules.Clear();

            redup.Allomorphs.Clear();
            redup.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).ZeroOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(cons).Annotation(vowel).Annotation(cons).Value,
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new CopyFromInput("2")}
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("sagsag"), "32 RED");
            AssertMorphsEqual(morpher.ParseWord("sasibudbud"), "38 RED");

            redup.Allomorphs.Clear();
            redup.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(vowel).Annotation(cons).Value,
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new CopyFromInput("2")}
            });

            var gDelete = new RewriteRule {Name = "g_delete", Lhs = Pattern<Word, ShapeNode>.New().Annotation(Char(Table1, "g")).Value};
            gDelete.Subrules.Add(new RewriteSubrule
            {
                LeftEnvironment = Pattern<Word, ShapeNode>.New().Annotation(vowel).Value,
                RightEnvironment = Pattern<Word, ShapeNode>.New().Annotation(vowel).Value
            });
            Allophonic.PhonologicalRules.Add(gDelete);

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("saag"), "32 RED");

            gDelete.Subrules.Clear();
            gDelete.Subrules.Add(new RewriteSubrule
            {
                RightEnvironment = Pattern<Word, ShapeNode>.New().Annotation(HCFeatureSystem.RightSideAnchor).Value
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("saga"), "32 RED");

            Allophonic.PhonologicalRules.Clear();
            redup.RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value;
            redup.OutSyntacticFeatureStruct = FeatureStruct.New().Value;
            redup.Allomorphs.Clear();
            redup.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(vowel).Annotation(vowel).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(cons).Value
                },
                Rhs = {new CopyFromInput("1"), new CopyFromInput("2"), new CopyFromInput("2"), new CopyFromInput("3")}
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("buiuib"), "30 RED", "31 RED");
        }
Esempio n. 47
0
        public void ModifyFromInputRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons-").Value;
            var lowRound = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("high-")
                .Symbol("round+").Value;

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "PL",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(vowel).Value
                },
                Rhs =
                {
                    new CopyFromInput("1"),
                    new CopyFromInput("2"),
                    new InsertSegments(Table3, "s"),
                    new ModifyFromInput("2", lowRound)
                }
            });
            Morphophonemic.MorphologicalRules.Add(sSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("puso"), "52 PL");
        }
Esempio n. 48
0
        public void DisjunctiveAllomorphs()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem)
                .Symbol(HCFeatureSystem.Segment)
                .Symbol("cons-").Value;

            var esSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "PL",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };
            esSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Annotation(vowel).Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "s")}
            });
            esSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "ɯs")}
            });
            Morphophonemic.MorphologicalRules.Add(esSuffix);

            var guSuffix = new AffixProcessRule
            {
                Name = "gu_suffix",
                Gloss = "3SG",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
            };
            guSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "gun")},
                Environments = {new AllomorphEnvironment(SpanFactory, ConstraintType.Require, null, Pattern<Word, ShapeNode>.New().Annotation(vowel).Value)}
            });
            guSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "gu")}
            });
            Morphophonemic.MorphologicalRules.Add(guSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("pugunɯs"), "52 3SG PL");
            AssertMorphsEqual(morpher.ParseWord("pugus"), "52 3SG PL");
            AssertMorphsEqual(morpher.ParseWord("puguɯs"));
            AssertMorphsEqual(morpher.ParseWord("pus"), "52 PL");
            AssertMorphsEqual(morpher.ParseWord("puɯs"));
        }
Esempio n. 49
0
 public override IRule <Word, ShapeNode> CompileSynthesisRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher)
 {
     return(new SynthesisRewriteRule(spanFactory, morpher, this));
 }
Esempio n. 50
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. 51
0
        public void RequiredSyntacticFeatureStruct()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var sSuffix = new AffixProcessRule
            {
                Name = "s_suffix",
                Gloss = "3SG",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")).Value
            };
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "s")},
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Feature(Head).EqualTo(head => head.Feature("tense").EqualTo("past")).Value
            });
            sSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "z")}
            });
            Morphophonemic.MorphologicalRules.Add(sSuffix);

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                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
            };
            edSuffix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "+ɯd")}
            });
            Morphophonemic.MorphologicalRules.Add(edSuffix);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("bagz"), "synfs 3SG");
            Assert.That(morpher.ParseWord("bags"), Is.Empty);
            AssertMorphsEqual(morpher.ParseWord("bagsɯd"), "synfs 3SG PAST");
            Assert.That(morpher.ParseWord("bagzɯd"), Is.Empty);
        }
Esempio n. 52
0
        public void SameRuleUsedInMultipleTemplates()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var edSuffix = new AffixProcessRule
            {
                Name = "ed_suffix",
                Gloss = "PAST",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V", "IV", "TV").Value,
            };

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

            var transitiveVerbTemplate = new AffixTemplate {Name = "Transitive Verb", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("TV").Value};
            transitiveVerbTemplate.Slots.Add(new AffixTemplateSlot(edSuffix));
            Morphophonemic.AffixTemplates.Add(transitiveVerbTemplate);

            var intransitiveVerbTemplate = new AffixTemplate {Name = "Intransitive Verb", RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("IV").Value};
            intransitiveVerbTemplate.Slots.Add(new AffixTemplateSlot(edSuffix));
            Morphophonemic.AffixTemplates.Add(intransitiveVerbTemplate);

            var nominalizer = new AffixProcessRule
            {
                Name = "intransitive verbalizer",
                Gloss = "IVERB",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("IV").Value
            };

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

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("mivd"), "53 IVERB PAST");
        }
Esempio n. 53
0
 public override void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs)
 {
     MorphAndLookupWord(morpher, word, prettyPrint, printTraceInputs, null);
 }
Esempio n. 54
0
        public void PrefixRules()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;
            var alvStop = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("strident-")
                .Symbol("cont-")
                .Symbol("del_rel-")
                .Symbol("alveolar")
                .Symbol("nasal-").Value;
            var voicelessCons = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("vd-").Value;
            var strident = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+")
                .Symbol("strident+").Value;
            var voicelessStop = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("vd-")
                .Symbol("cont-").Value;
            var cons = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons+").Value;
            var lowVowel = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("cons-")
                .Symbol("voc+")
                .Symbol("high-")
                .Symbol("low+")
                .Symbol("back+")
                .Symbol("round-")
                .Symbol("vd+")
                .Symbol("cont+").Value;
            var unasp = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment)
                .Symbol("asp-").Value;

            var sPrefix = new AffixProcessRule
            {
                Name = "s_prefix",
                Gloss = "3SG",
                RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
                OutSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem)
                    .Feature(Head).EqualTo(head => head
                        .Feature("pers").EqualTo("3")).Value
            };
            sPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(strident).Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "zi"), new CopyFromInput("1")}
            });
            sPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(voicelessCons).Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "s"), new CopyFromInput("1")}
            });
            sPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "z"), new CopyFromInput("1")}
            });
            Morphophonemic.MorphologicalRules.Add(sPrefix);

            var edPrefix = new AffixProcessRule
            {
                Name = "ed_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
            };
            edPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(alvStop).Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "di+"), new CopyFromInput("1")}
            });
            edPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(voicelessCons).Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "t+"), new CopyFromInput("1")}
            });
            edPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                Rhs = {new InsertSegments(Table3, "d+"), new CopyFromInput("1")}
            });
            Morphophonemic.MorphologicalRules.Add(edPrefix);

            var aspiration = new RewriteRule {Name = "aspiration", Lhs = Pattern<Word, ShapeNode>.New().Annotation(voicelessStop).Value};
            aspiration.Subrules.Add(new RewriteSubrule
            {
                Rhs = Pattern<Word, ShapeNode>.New().Annotation(unasp).Value,
            });
            Allophonic.PhonologicalRules.Add(aspiration);

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("zisag"), "3SG 32");
            AssertMorphsEqual(morpher.ParseWord("stag"), "3SG 47");
            AssertMorphsEqual(morpher.ParseWord("zabba"), "3SG 39", "3SG 40");
            AssertMorphsEqual(morpher.ParseWord("ditag"), "PAST 47");
            AssertMorphsEqual(morpher.ParseWord("tpag"), "PAST 48");
            AssertMorphsEqual(morpher.ParseWord("dabba"), "PAST 39", "PAST 40");
            Assert.That(morpher.ParseWord("zitag"), Is.Empty);
            Assert.That(morpher.ParseWord("sabba"), Is.Empty);
            Assert.That(morpher.ParseWord("ztag"), Is.Empty);
            Assert.That(morpher.ParseWord("disag"), Is.Empty);
            Assert.That(morpher.ParseWord("tabba"), Is.Empty);
            Assert.That(morpher.ParseWord("dtag"), Is.Empty);

            edPrefix.Allomorphs.RemoveAt(1);
            edPrefix.Allomorphs.RemoveAt(1);

            edPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1")
                        .Annotation(FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol(HCFeatureSystem.Segment).Feature("vd").EqualToVariable("a").Value)
                        .Annotation(any).OneOrMore.Value
                },
                Rhs = {new InsertSimpleContext(FeatureStruct.New(Language.PhonologicalFeatureSystem, alvStop).Feature("vd").EqualToVariable("a").Value), new CopyFromInput("1")}
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("ditag"), "PAST 47");
            AssertMorphsEqual(morpher.ParseWord("tpag"), "PAST 48");
            AssertMorphsEqual(morpher.ParseWord("dabba"), "PAST 39", "PAST 40");

            edPrefix.Allomorphs.Clear();

            edPrefix.Allomorphs.Add(new AffixProcessAllomorph
            {
                Lhs =
                {
                    Pattern<Word, ShapeNode>.New("1").Annotation(cons).Value,
                    Pattern<Word, ShapeNode>.New("2").Annotation(FeatureStruct.New(Language.PhonologicalFeatureSystem, lowVowel).Feature("ATR").EqualToVariable("a").Value).Value,
                    Pattern<Word, ShapeNode>.New("3").Annotation(any).OneOrMore.Value
                },
                Rhs =
                {
                    new InsertSegments(Table3, "m"),
                    new InsertSimpleContext(FeatureStruct.New(Language.PhonologicalFeatureSystem, lowVowel).Feature("ATR").EqualToVariable("a").Value),
                    new CopyFromInput("1"),
                    new CopyFromInput("3")
                }
            });

            morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("masg"), "PAST 32");
        }
Esempio n. 55
0
        public static TResult Morph <TResult, TArgument>(ref Int32 target, TArgument argument, Morpher <TResult, TArgument> morpher)
        {
            Contract.Requires(morpher != null);
            TResult morphResult;
            Int32   i, j = target;

            do
            {
                i = j;
                j = Interlocked.CompareExchange(ref target, morpher(i, argument, out morphResult), i);
            } while (i != j);
            return(morphResult);
        }
Esempio n. 56
0
 public void MorphAndLookupWord(Morpher morpher, string word, bool prettyPrint, bool printTraceInputs, string[] selectTraceMorphs)
 {
     try
     {
         ICollection <WordGrammarTrace> wordGrammarTraces = null;
         if (m_fDotrace)
         {
             wordGrammarTraces = new HashSet <WordGrammarTrace>();
         }
         morpher.TraceAll = m_fDotrace;
         WordAnalysisTrace           trace;
         ICollection <WordSynthesis> synthesisRecs = morpher.MorphAndLookupWord(word, out trace, selectTraceMorphs);
         foreach (WordSynthesis ws in synthesisRecs)
         {
             WordGrammarTrace          wordGrammarTrace = null;
             IEnumerable <PcPatrMorph> morphs           = GetMorphs(ws);
             if (wordGrammarTraces != null)
             {
                 wordGrammarTrace = new WordGrammarTrace(((uint)ws.GetHashCode()).ToString(), morphs, m_cache);
                 wordGrammarTraces.Add(wordGrammarTrace);
             }
             if (morphs.Count() == 1)
             {
                 var morph     = morphs.First();
                 var formid    = morph.formId;
                 var forms     = m_cache.LanguageProject.LexDbOA.AllAllomorphs.Where(a => a.Hvo.ToString() == formid);
                 var form      = forms.First();
                 var morphtype = form.MorphTypeRA;
                 if (morphtype.IsBoundType)
                 {
                     if (wordGrammarTrace != null)
                     {
                         wordGrammarTrace.Success = false;                                     // this is not really true; what other options are there?
                     }
                     continue;
                 }
             }
             WritePcPatrLexiconFile(m_patrlexPath, morphs);
             m_patr.LoadLexiconFile(m_patrlexPath, 0);
             string sentence = BuildPcPatrInputSentence(morphs);
             try
             {
                 if (m_patr.ParseString(sentence) != null)
                 {
                     BuildXmlOutput(morphs);
                     if (wordGrammarTrace != null)
                     {
                         wordGrammarTrace.Success = true;
                     }
                 }
                 else if (wordGrammarTrace != null)
                 {
                     wordGrammarTrace.Success = false;
                 }
             }
             catch (Exception)
             {
             }
         }
         if (m_fDotrace)
         {
             Write(trace, prettyPrint, printTraceInputs);
             ConvertWordGrammarTraceToXml(wordGrammarTraces);
         }
     }
     catch (MorphException exc)
     {
         Write(exc);
     }
 }
Esempio n. 57
0
 public override string GetPossessiveName(string name)
 {
     // (genitive) "[the] sailor's / [of the] sailor"
     // (e.g. Сын моряка — художник – the sailor's son is an artist)
     return(Morpher.GetDeclension(name, DeclensionCase.Genitive));
 }
Esempio n. 58
0
        public void SimpleRuleNotUnapplied()
        {
            var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value;

            var prule = new MetathesisRule
                            {
                                Name = "rule1",
                                Pattern = Pattern<Word, ShapeNode>.New()
                                    .Group("1", group => group.Annotation(Char(Table3, "i")))
                                    .Group("2", group => group.Annotation(Char(Table3, "u"))).Value,
                                LeftSwitchName = "2",
                                RightSwitchName = "1"
                            };
            Morphophonemic.PhonologicalRules.Add(prule);

            var iSuffix = new AffixProcessRule
                          	{
                                Name = "i_suffix",
                          		Gloss = "3SG"
                          	};
            Morphophonemic.MorphologicalRules.Add(iSuffix);
            iSuffix.Allomorphs.Add(new AffixProcessAllomorph
                                    {
                                        Lhs = {Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value},
                                        Rhs = {new CopyFromInput("1"), new InsertSegments(Table3, "i")}
                                    });

            var morpher = new Morpher(SpanFactory, TraceManager, Language);
            AssertMorphsEqual(morpher.ParseWord("pui"), "52 3SG");
        }
Esempio n. 59
0
        public AnalysisRewriteRule(Morpher morpher, RewriteRule rule)
        {
            _morpher = morpher;
            _rule    = rule;

            var settings = new MatcherSettings <ShapeNode>
            {
                Direction      = rule.Direction == Direction.LeftToRight ? Direction.RightToLeft : Direction.LeftToRight,
                Filter         = ann => ann.Type().IsOneOf(HCFeatureSystem.Segment, HCFeatureSystem.Anchor),
                MatchingMethod = MatchingMethod.Unification,
                UseDefaults    = true,
                // during analysis shape nodes can have features that are underspecified, so this must be non-deterministic
                Nondeterministic = true
            };

            _rules = new List <Tuple <ReapplyType, PhonologicalPatternRule> >();
            foreach (RewriteSubrule sr in _rule.Subrules)
            {
                IPhonologicalPatternRuleSpec ruleSpec = null;
                var mode        = RewriteApplicationMode.Iterative;
                var reapplyType = ReapplyType.Normal;
                if (_rule.Lhs.Children.Count == sr.Rhs.Children.Count)
                {
                    ruleSpec = new FeatureAnalysisRewriteRuleSpec(settings, rule.Lhs, sr);
                    if (_rule.ApplicationMode == RewriteApplicationMode.Simultaneous)
                    {
                        foreach (Constraint <Word, ShapeNode> constraint in sr.Rhs.Children
                                 .Cast <Constraint <Word, ShapeNode> >())
                        {
                            if (constraint.Type() == HCFeatureSystem.Segment)
                            {
                                if (!IsUnifiable(constraint, sr.LeftEnvironment) ||
                                    !IsUnifiable(constraint, sr.RightEnvironment))
                                {
                                    reapplyType = ReapplyType.SelfOpaquing;
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (_rule.Lhs.Children.Count > sr.Rhs.Children.Count)
                {
                    ruleSpec    = new NarrowAnalysisRewriteRuleSpec(settings, _rule.Lhs, sr);
                    mode        = RewriteApplicationMode.Simultaneous;
                    reapplyType = ReapplyType.Deletion;
                }
                else if (_rule.Lhs.Children.Count == 0)
                {
                    ruleSpec = new EpenthesisAnalysisRewriteRuleSpec(settings, sr);
                    if (_rule.ApplicationMode == RewriteApplicationMode.Simultaneous)
                    {
                        reapplyType = ReapplyType.SelfOpaquing;
                    }
                }
                Debug.Assert(ruleSpec != null);

                PhonologicalPatternRule patternRule = null;
                switch (mode)
                {
                case RewriteApplicationMode.Iterative:
                    patternRule = new IterativePhonologicalPatternRule(ruleSpec, settings);
                    break;

                case RewriteApplicationMode.Simultaneous:
                    patternRule = new SimultaneousPhonologicalPatternRule(ruleSpec, settings);
                    break;
                }

                _rules.Add(Tuple.Create(reapplyType, patternRule));
            }
        }
 public override IRule<Word, ShapeNode> CompileSynthesisRule(SpanFactory<ShapeNode> spanFactory, Morpher morpher)
 {
     return new SynthesisRealizationalAffixProcessRule(spanFactory, morpher, this);
 }