public bool Equals(SoundContext other) { if (other == null) { return(false); } return(_leftEnv == other._leftEnv && _target.Equals(other._target) && _rightEnv == other._rightEnv); }
public bool HaveSameStem(TSeq x, TSeq y, out double score) { var ngram1 = new Ngram <TItem>(SyllablesSelector(x).SelectMany(s => s)); var ngram2 = new Ngram <TItem>(SyllablesSelector(y).SelectMany(s => s)); if (ngram1.Equals(ngram2)) { score = NormalizeScores ? 1.0 : MaxZScore(_wordCount); return(true); } Tuple <AffixInfo, Ngram <TItem>, AffixInfo>[] analyses1 = GetAnalyses(ngram1).ToArray(); Tuple <AffixInfo, Ngram <TItem>, AffixInfo>[] analyses2 = GetAnalyses(ngram2).ToArray(); score = 0; foreach (Tuple <AffixInfo, Ngram <TItem>, AffixInfo> analysis1 in analyses1) { foreach (Tuple <AffixInfo, Ngram <TItem>, AffixInfo> analysis2 in analyses2) { if ((analysis1.Item1.Ngram.Length == 0 || analysis1.Item1 != analysis2.Item1) && analysis1.Item2.Equals(analysis2.Item2) && (analysis1.Item3.Ngram.Length == 0 || analysis1.Item3 != analysis2.Item3)) { double prefixScore = CalcAffixScore(analysis1.Item1, analysis2.Item1); double suffixScore = CalcAffixScore(analysis1.Item3, analysis2.Item3); double minScore = Math.Min(prefixScore, suffixScore); if (minScore >= Threshold && minScore > score) { score = minScore; } } } } return(score > 0); }
private void UpdateSelectedChangeWordPairs(WordPairsViewModel wordPairs) { IWordAligner aligner = _projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner]; wordPairs.SelectedCorrespondenceWordPairs.Clear(); foreach (WordPairViewModel wordPair in wordPairs.WordPairs) { bool selected = false; foreach (AlignedNodeViewModel node in wordPair.AlignedNodes) { if (_selectedSoundChange == null) { node.IsSelected = false; } else { SoundContext lhs = wordPair.DomainAlignment.ToSoundContext(_segmentPool, 0, node.Column, aligner.ContextualSoundClasses); Ngram <Segment> corr = wordPair.DomainAlignment[1, node.Column].ToNgram(_segmentPool); node.IsSelected = lhs.Equals(_selectedSoundChange.DomainSoundChangeLhs) && corr.Equals(_selectedSoundChange.DomainCorrespondence); if (node.IsSelected) { selected = true; } } } if (selected) { wordPairs.SelectedCorrespondenceWordPairs.Add(wordPair); } } }
public void UpdatePredictedCognacy(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); 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)) { cat = 1; } else if (IgnoreRegularInsertionDeletion && IsRegular(wordPair, alignerResult, alignment, column, v)) { cat = 0; } } 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 (RegularConsonantEqual) { if (IsRegular(wordPair, alignerResult, alignment, column, v)) { 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 = IsRegular(wordPair, alignerResult, alignment, column, v) ? 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.PredictedCognacy = type1Score >= 0.5 && type1And2Score >= 0.75; wordPair.PredictedCognacyScore = (type1Score * 0.75) + (type1And2Score * 0.25); }
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); }