Inheritance: ICognateIdentifier
Esempio n. 1
0
        public void UpdateCognacy_NoSimilarSegments()
        {
            var segmentPool = new SegmentPool();

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæ", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛ.ɬa", project.Meanings[0]), new Word("gud", project.Meanings[1]), new Word("pæ", project.Meanings[2])});

            var varSegementer = new VarietySegmenter(project.Segmenter);
            foreach (Variety variety in project.Varieties)
                varSegementer.Process(variety);

            var vp = new VarietyPair(project.Varieties[0], project.Varieties[1]);
            project.VarietyPairs.Add(vp);

            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, "primary");
            wordPairGenerator.Process(vp);

            var aligner = new TestWordAligner(segmentPool);
            var ignoredMappings = Substitute.For<ISegmentMappings>();
            var similarSegmentsMappings = Substitute.For<ISegmentMappings>();
            var cognateIdentifier = new BlairCognateIdentifier(segmentPool, false, false, ignoredMappings, similarSegmentsMappings);
            var wp = vp.WordPairs[0];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.False);

            wp = vp.WordPairs[1];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.True);

            wp = vp.WordPairs[2];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.False);
        }
 public override object UpdateComponent()
 {
     _similarVowels.UpdateComponent();
     _similarConsonants.UpdateComponent();
     var cognateIdentifier = new BlairCognateIdentifier(_segmentPool, _ignoreRegularInsertionDeletion, _regularConsEqual,
         new ListSegmentMappings(_projectService.Project.Segmenter, _ignoredMappings.Mappings.Select(m => UnorderedTuple.Create(m.Segment1, m.Segment2)), false),
         new TypeSegmentMappings(_similarVowels.SegmentMappings, _similarConsonants.SegmentMappings));
     _projectService.Project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier] = cognateIdentifier;
     return cognateIdentifier;
 }
Esempio n. 3
0
        public void UpdateCognacy_RegularCorrespondences()
        {
            var segmentPool = new SegmentPool();

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.lo", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæ", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛ.ɬa", project.Meanings[0]), new Word("gud", project.Meanings[1]), new Word("pæ", project.Meanings[2])});

            var varSegementer = new VarietySegmenter(project.Segmenter);
            foreach (Variety variety in project.Varieties)
                varSegementer.Process(variety);

            var vp = new VarietyPair(project.Varieties[0], project.Varieties[1]);
            project.VarietyPairs.Add(vp);

            var wordPairGenerator = new SimpleWordPairGenerator(segmentPool, project, 0.3, "primary");
            wordPairGenerator.Process(vp);

            vp.SoundChangeFrequencyDistribution[new SoundContext(segmentPool.GetExisting("l"))].Increment(segmentPool.GetExisting("ɬ"), 3);
            vp.SoundChangeFrequencyDistribution[new SoundContext(segmentPool.GetExisting("b"))].Increment(segmentPool.GetExisting("p"), 3);

            var aligner = new TestWordAligner(segmentPool);
            var ignoredMappings = Substitute.For<ISegmentMappings>();
            ignoredMappings.IsMapped(Arg.Any<ShapeNode>(), Arg.Any<Ngram<Segment>>(), Arg.Any<ShapeNode>(), Arg.Any<ShapeNode>(), Arg.Any<Ngram<Segment>>(), Arg.Any<ShapeNode>()).Returns(false);
            var similarSegmentsMappings = Substitute.For<ISegmentMappings>();
            similarSegmentsMappings.IsMapped(Arg.Any<ShapeNode>(), segmentPool.GetExisting("b"), Arg.Any<ShapeNode>(), Arg.Any<ShapeNode>(), segmentPool.GetExisting("p"), Arg.Any<ShapeNode>()).Returns(true);
            var cognateIdentifier = new BlairCognateIdentifier(segmentPool, false, false, ignoredMappings, similarSegmentsMappings);
            var wp = vp.WordPairs[0];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.True);

            wp = vp.WordPairs[1];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.True);

            wp = vp.WordPairs[2];
            cognateIdentifier.UpdateCognacy(wp, aligner.Compute(wp));
            Assert.That(wp.AreCognatePredicted, Is.True);
        }
            public TestEnvironment(string word1, string word2, bool ignoreRegularInsertionDeletion = false, bool regularConsEqual = false, bool automaticRegularCorrThreshold = false)
            {
                _segmentPool = new SegmentPool();
                _project = TestHelpers.GetTestProject(_spanFactory, _segmentPool);
                _project.Meanings.Add(new Meaning("gloss1", "cat1"));
                _project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
                _project.Varieties[0].Words.Add(new Word(word1, _project.Meanings[0]));
                _project.Varieties[1].Words.Add(new Word(word2, _project.Meanings[0]));

                var varSegementer = new VarietySegmenter(_project.Segmenter);
                foreach (Variety variety in _project.Varieties)
                    varSegementer.Process(variety);

                var vp = new VarietyPair(_project.Varieties[0], _project.Varieties[1]);
                _project.VarietyPairs.Add(vp);

                var wordPairGenerator = new SimpleWordPairGenerator(_segmentPool, _project, 0.3, "primary");
                wordPairGenerator.Process(vp);
                vp.CognateSoundCorrespondenceFrequencyDistribution = new ConditionalFrequencyDistribution<SoundContext, Ngram<Segment>>();

                var ignoredMappings = Substitute.For<ISegmentMappings>();
                var similarSegmentsMappings = Substitute.For<ISegmentMappings>();
                _cognateIdentifier = new BlairCognateIdentifier(_segmentPool, ignoreRegularInsertionDeletion, regularConsEqual, automaticRegularCorrThreshold,
                    3, ignoredMappings, similarSegmentsMappings);

                _aligner = new TestWordAligner(_segmentPool);
            }