public override void Setup()
        {
            _ignoredMappings.SelectedMapping = null;
            _ignoredMappings.Mappings.Clear();

            ICognateIdentifier cognateIdentifier = _projectService.Project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier];
            var blair = cognateIdentifier as BlairCognateIdentifier;

            if (blair == null)
            {
                Set(() => IgnoreRegularInsertionDeletion, ref _ignoreRegularInsertionDeletion, false);
                Set(() => RegularConsonantsEqual, ref _regularConsEqual, false);
                Set(() => AutomaticRegularCorrespondenceThreshold, ref _automaticRegularCorrespondenceThreshold, false);
                Set(() => DefaultRegularCorrepondenceThreshold, ref _defaultRegularCorrepondenceThreshold, 3);
                _similarVowels.SegmentMappings     = null;
                _similarConsonants.SegmentMappings = null;
            }
            else
            {
                Set(() => IgnoreRegularInsertionDeletion, ref _ignoreRegularInsertionDeletion, blair.IgnoreRegularInsertionDeletion);
                Set(() => RegularConsonantsEqual, ref _regularConsEqual, blair.RegularConsonantEqual);
                Set(() => AutomaticRegularCorrespondenceThreshold, ref _automaticRegularCorrespondenceThreshold, blair.AutomaticRegularCorrespondenceThreshold);
                Set(() => DefaultRegularCorrepondenceThreshold, ref _defaultRegularCorrepondenceThreshold, blair.DefaultRegularCorrespondenceThreshold);
                var ignoredMappings = (ListSegmentMappings)blair.IgnoredMappings;
                foreach (UnorderedTuple <string, string> mapping in ignoredMappings.Mappings)
                {
                    _ignoredMappings.Mappings.Add(_mappingFactory(mapping.Item1, mapping.Item2));
                }
                var segmentMappings = (TypeSegmentMappings)blair.SimilarSegments;
                _similarVowels.SegmentMappings     = (UnionSegmentMappings)segmentMappings.VowelMappings;
                _similarConsonants.SegmentMappings = (UnionSegmentMappings)segmentMappings.ConsonantMappings;
            }
            _similarVowels.Setup();
            _similarConsonants.Setup();
        }
示例#2
0
        public override void Setup()
        {
            ICognateIdentifier cognateIdentifier = _projectService.Project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier];
            int index = -1;

            if (cognateIdentifier is BlairCognateIdentifier)
            {
                index = 0;
            }
            else if (cognateIdentifier is ThresholdCognateIdentifier)
            {
                index = 1;
            }
            else if (cognateIdentifier is DolgopolskyCognateIdentifier)
            {
                index = 2;
            }
            SelectedOption = Options[index];

            var wordPairGenerator = (CognicityWordPairGenerator)_projectService.Project.VarietyPairProcessors[ComponentIdentifiers.WordPairGenerator];

            Set(() => InitialAlignmentThreshold, ref _initialAlignmentThreshold, wordPairGenerator.InitialAlignmentThreshold);

            base.Setup();
        }
        public override void Setup()
        {
            _ignoredMappings.SelectedMapping = null;
            _ignoredMappings.Mappings.Clear();

            ICognateIdentifier cognateIdentifier = _projectService.Project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier];
            var blair = cognateIdentifier as BlairCognateIdentifier;

            if (blair == null)
            {
                Set(() => IgnoreRegularInsertionDeletion, ref _ignoreRegularInsertionDeletion, false);
                Set(() => RegularConsonantsEqual, ref _regularConsEqual, false);
                _similarVowels.SegmentMappings     = null;
                _similarConsonants.SegmentMappings = null;
            }
            else
            {
                Set(() => IgnoreRegularInsertionDeletion, ref _ignoreRegularInsertionDeletion, blair.IgnoreRegularInsertionDeletion);
                Set(() => RegularConsonantsEqual, ref _regularConsEqual, blair.RegularConsonantEqual);
                var ignoredMappings = (ListSegmentMappings)blair.IgnoredMappings;
                foreach (Tuple <string, string> mapping in ignoredMappings.Mappings)
                {
                    _ignoredMappings.Mappings.Add(new SegmentMappingViewModel(_projectService.Project.Segmenter, mapping.Item1, mapping.Item2));
                }
                var segmentMappings = (TypeSegmentMappings)blair.SimilarSegments;
                _similarVowels.SegmentMappings     = (UnionSegmentMappings)segmentMappings.VowelMappings;
                _similarConsonants.SegmentMappings = (UnionSegmentMappings)segmentMappings.ConsonantMappings;
            }
            _similarVowels.Setup();
            _similarConsonants.Setup();
        }
        public override void Setup()
        {
            ICognateIdentifier cognateIdentifier = _projectService.Project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier];
            var threshold = cognateIdentifier as ThresholdCognateIdentifier;

            Set(() => Threshold, ref _threshold, threshold == null ? 0.75 : threshold.Threshold);
        }
示例#5
0
        private void E(VarietyPair pair)
        {
            ICognateIdentifier cognateIdentifier = _project.CognateIdentifiers[CognateIdentifierId];
            var          cognateCorrCounts       = new ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> >();
            IWordAligner aligner      = _project.WordAligners[AlignerId];
            int          cognateCount = 0;
            double       totalScore   = 0;

            foreach (WordPair wordPair in pair.WordPairs)
            {
                IWordAlignerResult alignerResult = aligner.Compute(wordPair);
                cognateIdentifier.UpdatePredictedCognacy(wordPair, alignerResult);
                Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
                if (wordPair.Cognacy)
                {
                    for (int column = 0; column < alignment.ColumnCount; column++)
                    {
                        SoundContext    lhs  = alignment.ToSoundContext(_segmentPool, 0, column, aligner.ContextualSoundClasses);
                        Ngram <Segment> corr = alignment[1, column].ToNgram(_segmentPool);
                        cognateCorrCounts[lhs].Increment(corr);
                    }
                    cognateCount++;
                }
                wordPair.PhoneticSimilarityScore = alignment.NormalizedScore;
                totalScore += wordPair.PhoneticSimilarityScore;
            }

            pair.CognateCount = cognateCount;
            pair.CognateSoundCorrespondenceFrequencyDistribution = cognateCorrCounts;
            if (pair.WordPairs.Count == 0)
            {
                pair.LexicalSimilarityScore  = 0;
                pair.PhoneticSimilarityScore = 0;
            }
            else
            {
                pair.LexicalSimilarityScore  = (double)cognateCount / pair.WordPairs.Count;
                pair.PhoneticSimilarityScore = totalScore / pair.WordPairs.Count;
            }
        }
示例#6
0
        public override void Setup()
        {
            CogProject         project           = _projectService.Project;
            ICognateIdentifier cognateIdentifier = project.CognateIdentifiers[ComponentIdentifiers.PrimaryCognateIdentifier];
            var dolgopolsky = cognateIdentifier as DolgopolskyCognateIdentifier;

            IEnumerable <SoundClass> soundClasses;

            if (dolgopolsky == null)
            {
                Set(() => InitialEquivalenceThreshold, ref _initialEquivalenceThreshold, 2);
                soundClasses = new SoundClass[]
                {
                    new UnnaturalClass("K", new[] { "t͡s", "d͡z", "t͡ɕ", "d͡ʑ", "t͡ʃ", "d͡ʒ", "c", "ɟ", "t͡θ", "t͡ʂ", "d͡ʐ", "k", "g", "q", "ɢ", "ɡ", "ɠ", "x", "ɣ", "χ" }, true, project.Segmenter),
                    new UnnaturalClass("P", new[] { "ɸ", "β", "f", "p͡f", "p", "b", "ɓ" }, true, project.Segmenter),
                    new UnnaturalClass("Ø", new[] { "ʔ", "ħ", "ʕ", "h", "ɦ", "-", "#ŋ" }, true, project.Segmenter),
                    new UnnaturalClass("J", new[] { "j", "ɥ", "ɰ" }, true, project.Segmenter),
                    new UnnaturalClass("M", new[] { "m", "ɱ", "ʍ" }, true, project.Segmenter),
                    new UnnaturalClass("N", new[] { "n", "ɳ", "ŋ", "ɴ", "ɲ" }, true, project.Segmenter),
                    new UnnaturalClass("S", new[] { "s", "z", "ʃ", "ʒ", "ʂ", "ʐ", "ç", "ʝ", "ɕ", "ʑ", "ɧ" }, true, project.Segmenter),
                    new UnnaturalClass("R", new[] { "ɹ", "ɻ", "ʀ", "ɾ", "r", "ʁ", "ɽ", "l", "ɭ", "ʎ", "ʟ", "ɬ", "ɮ", "ɫ", "ł" }, true, project.Segmenter),
                    new UnnaturalClass("T", new[] { "t", "d", "ɗ", "ʈ", "ɖ", "θ", "ð" }, true, project.Segmenter),
                    new UnnaturalClass("W", new[] { "w", "ʋ", "v", "ʙ" }, true, project.Segmenter)
                };
            }
            else
            {
                Set(() => InitialEquivalenceThreshold, ref _initialEquivalenceThreshold, dolgopolsky.InitialEquivalenceThreshold);
                soundClasses = dolgopolsky.SoundClasses;
            }

            _soundClasses.SelectedSoundClass = null;
            _soundClasses.SoundClasses.Clear();
            foreach (SoundClass soundClass in soundClasses)
            {
                _soundClasses.SoundClasses.Add(new SoundClassViewModel(soundClass));
            }
        }
示例#7
0
        public void Process(VarietyPair varietyPair)
        {
            IWordAligner aligner           = _project.WordAligners[_alignerID];
            var          ambiguousMeanings = new List <Tuple <Meaning, IWordAlignerResult, IWordAlignerResult[]> >();

            varietyPair.WordPairs.Clear();
            var cognateCorrCounts = new ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> >();
            int cognateCount      = 0;

            foreach (Meaning meaning in varietyPair.Variety1.Words.Meanings)
            {
                Word[] words1 = varietyPair.Variety1.Words[meaning].Where(w => w.Shape.Count > 0).ToArray();
                Word[] words2 = varietyPair.Variety2.Words[meaning].Where(w => w.Shape.Count > 0).ToArray();

                if (words1.Length == 1 && words2.Length == 1)
                {
                    Word     word1 = words1.Single();
                    Word     word2 = words2.Single();
                    WordPair wp    = varietyPair.WordPairs.Add(word1, word2);
                    _project.CognacyDecisions.UpdateActualCognacy(wp);
                    IWordAlignerResult alignerResult = aligner.Compute(wp);
                    _thresholdCognateIdentifier.UpdatePredictedCognacy(wp, alignerResult);
                    Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
                    if (wp.Cognacy)
                    {
                        UpdateCognateCorrespondenceCounts(aligner, cognateCorrCounts, alignment);
                        cognateCount++;
                    }
                    wp.PhoneticSimilarityScore = alignment.NormalizedScore;
                }
                else if (words1.Length > 0 && words2.Length > 0)
                {
                    IWordAlignerResult[] alignerResults   = words1.SelectMany(w1 => words2.Select(w2 => aligner.Compute(w1, w2))).ToArray();
                    IWordAlignerResult   maxAlignerResult = alignerResults.MaxBy(a => a.BestRawScore);
                    ambiguousMeanings.Add(Tuple.Create(meaning, maxAlignerResult, alignerResults));
                    WordPair wp = varietyPair.WordPairs.Add(maxAlignerResult.Words[0], maxAlignerResult.Words[1]);
                    _thresholdCognateIdentifier.UpdatePredictedCognacy(wp, maxAlignerResult);
                }
            }

            ICognateIdentifier cognateIdentifier = _project.CognateIdentifiers[_cognateIdentifierID];

            for (int i = 0; i < ambiguousMeanings.Count; i++)
            {
                ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> > newCognateCorrCounts = cognateCorrCounts.Clone();
                int newCognateCount = cognateCount;
                for (int j = i + 1; j < ambiguousMeanings.Count; j++)
                {
                    if (varietyPair.WordPairs[ambiguousMeanings[j].Item1].Cognacy)
                    {
                        UpdateCognateCorrespondenceCounts(aligner, newCognateCorrCounts, ambiguousMeanings[j].Item2.GetAlignments().First());
                        newCognateCount++;
                    }
                }

                IWordAlignerResult bestAlignerResult = null;
                WordPair           bestWordPair      = null;
                foreach (IWordAlignerResult alignerResult in ambiguousMeanings[i].Item3)
                {
                    ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> > alignmentCognateCorrCounts = newCognateCorrCounts.Clone();
                    int alignmentCognateCount             = newCognateCount;
                    Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
                    varietyPair.WordPairs.Remove(ambiguousMeanings[i].Item1);
                    WordPair wordPair = varietyPair.WordPairs.Add(alignerResult.Words[0], alignerResult.Words[1]);
                    _thresholdCognateIdentifier.UpdatePredictedCognacy(wordPair, alignerResult);
                    if (wordPair.Cognacy)
                    {
                        UpdateCognateCorrespondenceCounts(aligner, alignmentCognateCorrCounts, alignment);
                        alignmentCognateCount++;
                    }
                    varietyPair.CognateCount = alignmentCognateCount;
                    varietyPair.CognateSoundCorrespondenceFrequencyDistribution = alignmentCognateCorrCounts;
                    cognateIdentifier.UpdatePredictedCognacy(wordPair, alignerResult);
                    wordPair.PhoneticSimilarityScore = alignment.NormalizedScore;
                    if (bestWordPair == null || Compare(wordPair, bestWordPair) > 0)
                    {
                        bestWordPair      = wordPair;
                        bestAlignerResult = alignerResult;
                    }
                }

                Debug.Assert(bestWordPair != null);
                varietyPair.WordPairs.Remove(ambiguousMeanings[i].Item1);
                varietyPair.WordPairs.Add(bestWordPair);
                _project.CognacyDecisions.UpdateActualCognacy(bestWordPair);
                if (bestWordPair.Cognacy)
                {
                    UpdateCognateCorrespondenceCounts(aligner, cognateCorrCounts, bestAlignerResult.GetAlignments().First());
                    cognateCount++;
                }
            }

            varietyPair.CognateCount = cognateCount;
            varietyPair.CognateSoundCorrespondenceFrequencyDistribution = cognateCorrCounts;
        }