コード例 #1
0
 public bool IsMapped(ShapeNode leftNode1, Ngram <Segment> target1, ShapeNode rightNode1, ShapeNode leftNode2, Ngram <Segment> target2, ShapeNode rightNode2)
 {
     if ((target1.Length == 0 || target1.First.Type == CogFeatureSystem.VowelType) && (target2.Length == 0 || target2.First.Type == CogFeatureSystem.VowelType))
     {
         return(_vowelMappings.IsMapped(leftNode1, target1, rightNode1, leftNode2, target2, rightNode2));
     }
     if ((target1.Length == 0 || target1.First.Type == CogFeatureSystem.ConsonantType) && (target2.Length == 0 || target2.First.Type == CogFeatureSystem.ConsonantType))
     {
         return(_consMappings.IsMapped(leftNode1, target1, rightNode1, leftNode2, target2, rightNode2));
     }
     return(false);
 }
コード例 #2
0
ファイル: BlairCognateIdentifier.cs プロジェクト: FieldDB/cog
        public void UpdateCognicity(WordPair wordPair, IWordAlignerResult alignerResult)
        {
            wordPair.AlignmentNotes.Clear();
            int cat1Count     = 0;
            int cat1And2Count = 0;
            int totalCount    = 0;
            Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();

            for (int column = 0; column < alignment.ColumnCount; column++)
            {
                ShapeNode       uLeftNode  = alignment.GetLeftNode(0, column);
                Ngram <Segment> u          = alignment[0, column].ToNgram(_segmentPool);
                ShapeNode       uRightNode = alignment.GetRightNode(0, column);
                ShapeNode       vLeftNode  = alignment.GetLeftNode(1, column);
                Ngram <Segment> v          = alignment[1, column].ToNgram(_segmentPool);
                ShapeNode       vRightNode = alignment.GetRightNode(1, column);

                bool regular = wordPair.VarietyPair.SoundChangeFrequencyDistribution[alignment.ToSoundContext(_segmentPool, 0, column, alignerResult.WordAligner.ContextualSoundClasses)][v] >= 3;

                int cat = 3;
                if (u.Equals(v))
                {
                    cat = 1;
                }
                else if (_ignoredMappings.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                {
                    cat = 0;
                }
                else if (u.Length == 0 || v.Length == 0)
                {
                    if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode) || regular)
                    {
                        cat = _ignoreRegularInsertionDeletion ? 0 : 1;
                    }
                }
                else if (u[0].Type == CogFeatureSystem.VowelType && v[0].Type == CogFeatureSystem.VowelType)
                {
                    cat = _similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode) ? 1 : 2;
                }
                else if (u[0].Type == CogFeatureSystem.ConsonantType && v[0].Type == CogFeatureSystem.ConsonantType)
                {
                    if (_regularConsEqual)
                    {
                        if (regular)
                        {
                            cat = 1;
                        }
                        else if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                        {
                            cat = 2;
                        }
                    }
                    else
                    {
                        if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                        {
                            cat = regular ? 1 : 2;
                        }
                    }
                }

                if (cat > 0 && cat < 3)
                {
                    cat1And2Count++;
                    if (cat == 1)
                    {
                        cat1Count++;
                    }
                }
                wordPair.AlignmentNotes.Add(cat == 0 ? "-" : cat.ToString(CultureInfo.InvariantCulture));
                if (cat > 0)
                {
                    totalCount++;
                }
            }

            double type1Score     = (double)cat1Count / totalCount;
            double type1And2Score = (double)cat1And2Count / totalCount;

            wordPair.AreCognatePredicted = type1Score >= 0.5 && type1And2Score >= 0.75;
            wordPair.CognicityScore      = (type1Score * 0.75) + (type1And2Score * 0.25);
        }