コード例 #1
0
ファイル: LexEntryTests.cs プロジェクト: ermshiperete/machine
        public void AllomorphEnvironments()
        {
            var vowel = FeatureStruct.New(Language.PhonologicalFeatureSystem).Symbol("voc+").Value;

            LexEntry headEntry = Entries["32"];
            Pattern <Word, ShapeNode> envPattern = Pattern <Word, ShapeNode> .New().Annotation(vowel).Value;

            var env = new AllomorphEnvironment(ConstraintType.Require, null, envPattern);

            headEntry.PrimaryAllomorph.Environments.Add(env);

            var word = new Word(headEntry.PrimaryAllomorph, FeatureStruct.New().Value);

            ShapeNode node         = word.Shape.Last;
            LexEntry  nonHeadEntry = Entries["40"];

            word.Shape.AddRange(nonHeadEntry.PrimaryAllomorph.Segments.Shape.AsEnumerable().CloneItems());
            Annotation <ShapeNode> nonHeadMorph = word.MarkMorph(word.Shape.GetNodes(node.Next, word.Shape.Last),
                                                                 nonHeadEntry.PrimaryAllomorph);

            Assert.That(env.IsWordValid(word), Is.True);

            word.RemoveMorph(nonHeadMorph);

            nonHeadEntry = Entries["41"];
            word.Shape.AddRange(nonHeadEntry.PrimaryAllomorph.Segments.Shape.AsEnumerable().CloneItems());
            nonHeadMorph = word.MarkMorph(word.Shape.GetNodes(node.Next, word.Shape.Last),
                                          nonHeadEntry.PrimaryAllomorph);

            Assert.That(env.IsWordValid(word), Is.False);

            headEntry.PrimaryAllomorph.Environments.Clear();

            env = new AllomorphEnvironment(ConstraintType.Require, envPattern, null);
            headEntry.PrimaryAllomorph.Environments.Add(env);

            word.RemoveMorph(nonHeadMorph);

            node         = word.Shape.First;
            nonHeadEntry = Entries["40"];
            word.Shape.AddRangeAfter(word.Shape.Begin,
                                     nonHeadEntry.PrimaryAllomorph.Segments.Shape.AsEnumerable().CloneItems());
            nonHeadMorph = word.MarkMorph(word.Shape.GetNodes(word.Shape.First, node.Prev),
                                          nonHeadEntry.PrimaryAllomorph);

            Assert.That(env.IsWordValid(word), Is.True);

            word.RemoveMorph(nonHeadMorph);

            nonHeadEntry = Entries["41"];
            word.Shape.AddRangeAfter(word.Shape.Begin,
                                     nonHeadEntry.PrimaryAllomorph.Segments.Shape.AsEnumerable().CloneItems());
            word.MarkMorph(word.Shape.GetNodes(word.Shape.First, node.Prev), nonHeadEntry.PrimaryAllomorph);

            Assert.That(env.IsWordValid(word), Is.False);
        }
コード例 #2
0
ファイル: Allomorph.cs プロジェクト: ermshiperete/machine
        internal virtual bool IsWordValid(Morpher morpher, Word word)
        {
            AllomorphEnvironment env = Environments.FirstOrDefault(e => !e.IsWordValid(word));

            if (env != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.Failed(morpher.Language, word, FailureReason.Environments, this, env);
                }
                return(false);
            }

            AllomorphCoOccurrenceRule alloRule = AllomorphCoOccurrenceRules.FirstOrDefault(r => !r.IsWordValid(word));

            if (alloRule != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.Failed(morpher.Language, word, FailureReason.AllomorphCoOccurrenceRules, this, alloRule);
                }
                return(false);
            }

            MorphemeCoOccurrenceRule morphemeRule = Morpheme.MorphemeCoOccurrenceRules.FirstOrDefault(r => !r.IsWordValid(word));

            if (morphemeRule != null)
            {
                if (morpher.TraceManager.IsTracing)
                {
                    morpher.TraceManager.Failed(morpher.Language, word, FailureReason.MorphemeCoOccurrenceRules, this, morphemeRule);
                }
                return(false);
            }

            return(true);
        }