UpdatePredictedCognacy() public method

public UpdatePredictedCognacy ( WordPair wordPair, IWordAlignerResult alignerResult ) : void
wordPair WordPair
alignerResult IWordAlignerResult
return void
コード例 #1
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;
        }
コード例 #2
0
        public void Process(VarietyPair varietyPair)
        {
            IWordAligner aligner = _project.WordAligners[_alignerID];

            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)
                {
                    WordPair           bestWordPair      = null;
                    IWordAlignerResult bestAlignerResult = null;
                    foreach (Word w1 in words1)
                    {
                        foreach (Word w2 in words2)
                        {
                            IWordAlignerResult alignerResult = aligner.Compute(w1, w2);
                            if (bestAlignerResult == null || alignerResult.BestRawScore > bestAlignerResult.BestRawScore)
                            {
                                bestWordPair      = new WordPair(w1, w2);
                                bestAlignerResult = alignerResult;
                            }
                        }
                    }

                    Debug.Assert(bestWordPair != null);
                    varietyPair.WordPairs.Add(bestWordPair);
                    _project.CognacyDecisions.UpdateActualCognacy(bestWordPair);
                    _thresholdCognateIdentifier.UpdatePredictedCognacy(bestWordPair, bestAlignerResult);
                    Alignment <Word, ShapeNode> alignment = bestAlignerResult.GetAlignments().First();
                    if (bestWordPair.Cognacy)
                    {
                        UpdateCognateCorrespondenceCounts(aligner, cognateCorrCounts, alignment);
                        cognateCount++;
                    }
                    bestWordPair.PhoneticSimilarityScore = alignment.NormalizedScore;
                }
            }

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