예제 #1
0
        public override bool CheckEntityMatch(Document document, CorefCluster mentionCluster, CorefCluster potentialAntecedent, Dictionaries dict, ICollection <Mention> roleSet)
        {
            bool    matched     = false;
            Mention mainMention = mentionCluster.GetRepresentativeMention();
            Mention antMention  = potentialAntecedent.GetRepresentativeMention();

            // Check if the representative mentions are compatible
            if (IsNamedMention(mainMention, dict, roleSet) && IsNamedMention(antMention, dict, roleSet))
            {
                if (mainMention.originalSpan.Count > minTokens || antMention.originalSpan.Count > minTokens)
                {
                    if (CorefRules.EntityAttributesAgree(mentionCluster, potentialAntecedent, ignoreGender))
                    {
                        if (supportedNerTypes.Contains(mainMention.nerString) || supportedNerTypes.Contains(antMention.nerString))
                        {
                            matched = mentionMatcher.IsCompatible(mainMention, antMention);
                            if (matched != null)
                            {
                                //Redwood.log("Match '" + mainMention + "' with '" + antMention + "' => " + matched);
                                if (!matched)
                                {
                                    document.AddIncompatible(mainMention, antMention);
                                }
                            }
                            else
                            {
                                matched = false;
                            }
                        }
                    }
                }
            }
            return(matched);
        }
        public static IList <int> PairwiseFeatures(Document document, Mention m1, Mention m2, Dictionaries dictionaries, bool isConll)
        {
            string      speaker1 = m1.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
            string      speaker2 = m2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
            IList <int> features = new List <int>();

            features.Add(isConll ? (speaker1.Equals(speaker2) ? 1 : 0) : 0);
            features.Add(isConll ? (CorefRules.AntecedentIsMentionSpeaker(document, m2, m1, dictionaries) ? 1 : 0) : 0);
            features.Add(isConll ? (CorefRules.AntecedentIsMentionSpeaker(document, m1, m2, dictionaries) ? 1 : 0) : 0);
            features.Add(m1.HeadsAgree(m2) ? 1 : 0);
            features.Add(m1.ToString().Trim().ToLower().Equals(m2.ToString().Trim().ToLower()) ? 1 : 0);
            features.Add(FeatureExtractor.RelaxedStringMatch(m1, m2) ? 1 : 0);
            return(features);
        }
예제 #3
0
        private ICounter <string> GetFeatures(Document doc, Mention m1, Mention m2)
        {
            System.Diagnostics.Debug.Assert((m1.AppearEarlierThan(m2)));
            ICounter <string> features = new ClassicCounter <string>();

            // global features
            features.IncrementCount("bias");
            if (useDocSource)
            {
                features.IncrementCount("doc-type=" + doc.docType);
                if (doc.docInfo != null && doc.docInfo.Contains("DOC_ID"))
                {
                    features.IncrementCount("doc-source=" + doc.docInfo["DOC_ID"].Split("/")[1]);
                }
            }
            // singleton feature conjunctions
            IList <string> singletonFeatures1 = m1.GetSingletonFeatures(dictionaries);
            IList <string> singletonFeatures2 = m2.GetSingletonFeatures(dictionaries);

            foreach (KeyValuePair <int, string> e in SingletonFeatures)
            {
                if (e.Key < singletonFeatures1.Count && e.Key < singletonFeatures2.Count)
                {
                    features.IncrementCount(e.Value + "=" + singletonFeatures1[e.Key] + "_" + singletonFeatures2[e.Key]);
                }
            }
            SemanticGraphEdge p1 = GetDependencyParent(m1);
            SemanticGraphEdge p2 = GetDependencyParent(m2);

            features.IncrementCount("dep-relations=" + (p1 == null ? "null" : p1.GetRelation()) + "_" + (p2 == null ? "null" : p2.GetRelation()));
            features.IncrementCount("roles=" + GetRole(m1) + "_" + GetRole(m2));
            CoreLabel headCL1  = HeadWord(m1);
            CoreLabel headCL2  = HeadWord(m2);
            string    headPOS1 = GetPOS(headCL1);
            string    headPOS2 = GetPOS(headCL2);

            features.IncrementCount("head-pos-s=" + headPOS1 + "_" + headPOS2);
            features.IncrementCount("head-words=" + WordIndicator("h_" + headCL1.Word().ToLower() + "_" + headCL2.Word().ToLower(), headPOS1 + "_" + headPOS2));
            // agreement features
            AddFeature(features, "animacies-agree", m2.AnimaciesAgree(m1));
            AddFeature(features, "attributes-agree", m2.AttributesAgree(m1, dictionaries));
            AddFeature(features, "entity-types-agree", m2.EntityTypesAgree(m1, dictionaries));
            AddFeature(features, "numbers-agree", m2.NumbersAgree(m1));
            AddFeature(features, "genders-agree", m2.GendersAgree(m1));
            AddFeature(features, "ner-strings-equal", m1.nerString.Equals(m2.nerString));
            // string matching features
            AddFeature(features, "antecedent-head-in-anaphor", HeadContainedIn(m1, m2));
            AddFeature(features, "anaphor-head-in-antecedent", HeadContainedIn(m2, m1));
            if (m1.mentionType != Dictionaries.MentionType.Pronominal && m2.mentionType != Dictionaries.MentionType.Pronominal)
            {
                AddFeature(features, "antecedent-in-anaphor", m2.SpanToString().ToLower().Contains(m1.SpanToString().ToLower()));
                AddFeature(features, "anaphor-in-antecedent", m1.SpanToString().ToLower().Contains(m2.SpanToString().ToLower()));
                AddFeature(features, "heads-equal", Sharpen.Runtime.EqualsIgnoreCase(m1.headString, m2.headString));
                AddFeature(features, "heads-agree", m2.HeadsAgree(m1));
                AddFeature(features, "exact-match", m1.ToString().Trim().ToLower().Equals(m2.ToString().Trim().ToLower()));
                AddFeature(features, "partial-match", RelaxedStringMatch(m1, m2));
                double editDistance = StringUtils.EditDistance(m1.SpanToString(), m2.SpanToString()) / (double)(m1.SpanToString().Length + m2.SpanToString().Length);
                features.IncrementCount("edit-distance", editDistance);
                features.IncrementCount("edit-distance=" + ((int)(editDistance * 10) / 10.0));
                double headEditDistance = StringUtils.EditDistance(m1.headString, m2.headString) / (double)(m1.headString.Length + m2.headString.Length);
                features.IncrementCount("head-edit-distance", headEditDistance);
                features.IncrementCount("head-edit-distance=" + ((int)(headEditDistance * 10) / 10.0));
            }
            // distance features
            AddNumeric(features, "mention-distance", m2.mentionNum - m1.mentionNum);
            AddNumeric(features, "sentence-distance", m2.sentNum - m1.sentNum);
            if (m2.sentNum == m1.sentNum)
            {
                AddNumeric(features, "word-distance", m2.startIndex - m1.endIndex);
                if (m1.endIndex > m2.startIndex)
                {
                    features.IncrementCount("spans-intersect");
                }
            }
            // setup for dcoref features
            ICollection <Mention> ms1 = new HashSet <Mention>();

            ms1.Add(m1);
            ICollection <Mention> ms2 = new HashSet <Mention>();

            ms2.Add(m2);
            Random       r  = new Random();
            CorefCluster c1 = new CorefCluster(20000 + r.NextInt(10000), ms1);
            CorefCluster c2 = new CorefCluster(10000 + r.NextInt(10000), ms2);
            string       s2 = m2.LowercaseNormalizedSpanString();
            string       s1 = m1.LowercaseNormalizedSpanString();

            // discourse dcoref features
            AddFeature(features, "mention-speaker-PER0", Sharpen.Runtime.EqualsIgnoreCase(m2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation)), "PER0"));
            AddFeature(features, "antecedent-is-anaphor-speaker", CorefRules.AntecedentIsMentionSpeaker(doc, m2, m1, dictionaries));
            AddFeature(features, "same-speaker", CorefRules.EntitySameSpeaker(doc, m2, m1));
            AddFeature(features, "person-disagree-same-speaker", CorefRules.EntityPersonDisagree(doc, m2, m1, dictionaries) && CorefRules.EntitySameSpeaker(doc, m2, m1));
            AddFeature(features, "antecedent-matches-anaphor-speaker", CorefRules.AntecedentMatchesMentionSpeakerAnnotation(m2, m1, doc));
            AddFeature(features, "discourse-you-PER0", m2.person == Dictionaries.Person.You && doc.docType == Document.DocType.Article && m2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation)).Equals("PER0"));
            AddFeature(features, "speaker-match-i-i", m2.number == Dictionaries.Number.Singular && dictionaries.firstPersonPronouns.Contains(s1) && m1.number == Dictionaries.Number.Singular && dictionaries.firstPersonPronouns.Contains(s2) && CorefRules.
                       EntitySameSpeaker(doc, m2, m1));
            AddFeature(features, "speaker-match-speaker-i", m2.number == Dictionaries.Number.Singular && dictionaries.firstPersonPronouns.Contains(s2) && CorefRules.AntecedentIsMentionSpeaker(doc, m2, m1, dictionaries));
            AddFeature(features, "speaker-match-i-speaker", m1.number == Dictionaries.Number.Singular && dictionaries.firstPersonPronouns.Contains(s1) && CorefRules.AntecedentIsMentionSpeaker(doc, m1, m2, dictionaries));
            AddFeature(features, "speaker-match-you-you", dictionaries.secondPersonPronouns.Contains(s1) && dictionaries.secondPersonPronouns.Contains(s2) && CorefRules.EntitySameSpeaker(doc, m2, m1));
            AddFeature(features, "discourse-between-two-person", ((m2.person == Dictionaries.Person.I && m1.person == Dictionaries.Person.You || (m2.person == Dictionaries.Person.You && m1.person == Dictionaries.Person.I)) && (m2.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation
                                                                                                                                                                                                                                                          )) - m1.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)) == 1) && doc.docType == Document.DocType.Conversation));
            AddFeature(features, "incompatible-not-match", m1.person != Dictionaries.Person.I && m2.person != Dictionaries.Person.I && (CorefRules.AntecedentIsMentionSpeaker(doc, m1, m2, dictionaries) || CorefRules.AntecedentIsMentionSpeaker(doc, m2, m1
                                                                                                                                                                                                                                                  , dictionaries)));
            int utteranceDist = Math.Abs(m1.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)) - m2.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)));

            if (doc.docType != Document.DocType.Article && utteranceDist == 1 && !CorefRules.EntitySameSpeaker(doc, m2, m1))
            {
                AddFeature(features, "speaker-mismatch-i-i", m1.person == Dictionaries.Person.I && m2.person == Dictionaries.Person.I);
                AddFeature(features, "speaker-mismatch-you-you", m1.person == Dictionaries.Person.You && m2.person == Dictionaries.Person.You);
                AddFeature(features, "speaker-mismatch-we-we", m1.person == Dictionaries.Person.We && m2.person == Dictionaries.Person.We);
            }
            // other dcoref features
            string firstWord1 = FirstWord(m1).Word().ToLower();

            AddFeature(features, "indefinite-article-np", (m1.appositions == null && m1.predicateNominatives == null && (firstWord1.Equals("a") || firstWord1.Equals("an"))));
            AddFeature(features, "far-this", m2.LowercaseNormalizedSpanString().Equals("this") && Math.Abs(m2.sentNum - m1.sentNum) > 3);
            AddFeature(features, "per0-you-in-article", m2.person == Dictionaries.Person.You && doc.docType == Document.DocType.Article && m2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation)).Equals("PER0"));
            AddFeature(features, "inside-in", m2.InsideIn(m1) || m1.InsideIn(m2));
            AddFeature(features, "indefinite-determiners", dictionaries.indefinitePronouns.Contains(m1.originalSpan[0].Lemma()) || dictionaries.indefinitePronouns.Contains(m2.originalSpan[0].Lemma()));
            AddFeature(features, "entity-attributes-agree", CorefRules.EntityAttributesAgree(c2, c1));
            AddFeature(features, "entity-token-distance", CorefRules.EntityTokenDistance(m2, m1));
            AddFeature(features, "i-within-i", CorefRules.EntityIWithinI(m2, m1, dictionaries));
            AddFeature(features, "exact-string-match", CorefRules.EntityExactStringMatch(c2, c1, dictionaries, doc.roleSet));
            AddFeature(features, "entity-relaxed-heads-agree", CorefRules.EntityRelaxedHeadsAgreeBetweenMentions(c2, c1, m2, m1));
            AddFeature(features, "is-acronym", CorefRules.EntityIsAcronym(doc, c2, c1));
            AddFeature(features, "demonym", m2.IsDemonym(m1, dictionaries));
            AddFeature(features, "incompatible-modifier", CorefRules.EntityHaveIncompatibleModifier(m2, m1));
            AddFeature(features, "head-lemma-match", m1.headWord.Lemma().Equals(m2.headWord.Lemma()));
            AddFeature(features, "words-included", CorefRules.EntityWordsIncluded(c2, c1, m2, m1));
            AddFeature(features, "extra-proper-noun", CorefRules.EntityHaveExtraProperNoun(m2, m1, new HashSet <string>()));
            AddFeature(features, "number-in-later-mentions", CorefRules.EntityNumberInLaterMention(m2, m1));
            AddFeature(features, "sentence-context-incompatible", CorefRules.SentenceContextIncompatible(m2, m1, dictionaries));
            // syntax features
            if (useConstituencyParse)
            {
                if (m1.sentNum == m2.sentNum)
                {
                    int  clauseCount = 0;
                    Tree tree        = m2.contextParseTree;
                    Tree current     = m2.mentionSubTree;
                    while (true)
                    {
                        current = current.Ancestor(1, tree);
                        if (current.Label().Value().StartsWith("S"))
                        {
                            clauseCount++;
                        }
                        if (current.Dominates(m1.mentionSubTree))
                        {
                            break;
                        }
                        if (current.Label().Value().Equals("ROOT") || current.Ancestor(1, tree) == null)
                        {
                            break;
                        }
                    }
                    features.IncrementCount("clause-count", clauseCount);
                    features.IncrementCount("clause-count=" + Bin(clauseCount));
                }
                if (RuleBasedCorefMentionFinder.IsPleonastic(m2, m2.contextParseTree) || RuleBasedCorefMentionFinder.IsPleonastic(m1, m1.contextParseTree))
                {
                    features.IncrementCount("pleonastic-it");
                }
                if (MaximalNp(m1.mentionSubTree) == MaximalNp(m2.mentionSubTree))
                {
                    features.IncrementCount("same-maximal-np");
                }
                bool m1Embedded = HeadEmbeddingLevel(m1.mentionSubTree, m1.headIndex - m1.startIndex) > 1;
                bool m2Embedded = HeadEmbeddingLevel(m2.mentionSubTree, m2.headIndex - m2.startIndex) > 1;
                features.IncrementCount("embedding=" + m1Embedded + "_" + m2Embedded);
            }
            return(features);
        }
예제 #4
0
        /// <summary>Checks if two clusters are coreferent according to our sieve pass constraints</summary>
        /// <param name="document"/>
        /// <exception cref="System.Exception"/>
        public virtual bool Coreferent(Document document, CorefCluster mentionCluster, CorefCluster potentialAntecedent, Mention mention2, Mention ant, Dictionaries dict, ICollection <Mention> roleSet)
        {
            bool    ret     = false;
            Mention mention = mentionCluster.GetRepresentativeMention();

            if (flags.UseIncompatibles)
            {
                // Check our list of incompatible mentions and don't cluster them together
                // Allows definite no's from previous sieves to propagate down
                if (document.IsIncompatible(mentionCluster, potentialAntecedent))
                {
                    return(false);
                }
            }
            if (flags.DoPronoun && Math.Abs(mention2.sentNum - ant.sentNum) > 3 && mention2.person != Dictionaries.Person.I && mention2.person != Dictionaries.Person.You)
            {
                return(false);
            }
            if (mention2.LowercaseNormalizedSpanString().Equals("this") && Math.Abs(mention2.sentNum - ant.sentNum) > 3)
            {
                return(false);
            }
            if (mention2.person == Dictionaries.Person.You && document.docType == Document.DocType.Article && mention2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation)).Equals("PER0"))
            {
                return(false);
            }
            if (document.conllDoc != null)
            {
                if (ant.generic && ant.person == Dictionaries.Person.You)
                {
                    return(false);
                }
                if (mention2.generic)
                {
                    return(false);
                }
            }
            // chinese newswire contains coref nested NPs with shared headword  Chen & Ng
            if (lang != Locale.Chinese || document.docInfo == null || !document.docInfo.GetOrDefault("DOC_ID", string.Empty).Contains("nw"))
            {
                if (mention2.InsideIn(ant) || ant.InsideIn(mention2))
                {
                    return(false);
                }
            }
            if (flags.UseSpeakermatch)
            {
                string mSpeaker = mention2.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
                string aSpeaker = ant.headWord.Get(typeof(CoreAnnotations.SpeakerAnnotation));
                // <I> from same speaker
                if (mention2.person == Dictionaries.Person.I && ant.person == Dictionaries.Person.I)
                {
                    return(mSpeaker.Equals(aSpeaker));
                }
                // <I> - speaker
                if ((mention2.person == Dictionaries.Person.I && mSpeaker.Equals(int.ToString(ant.mentionID))) || (ant.person == Dictionaries.Person.I && aSpeaker.Equals(int.ToString(mention2.mentionID))))
                {
                    return(true);
                }
            }
            if (flags.UseDiscoursematch)
            {
                string mString   = mention.LowercaseNormalizedSpanString();
                string antString = ant.LowercaseNormalizedSpanString();
                // mention and ant both belong to the same speaker cluster
                if (mention.speakerInfo != null && mention.speakerInfo == ant.speakerInfo)
                {
                    return(true);
                }
                // (I - I) in the same speaker's quotation.
                if (mention.number == Dictionaries.Number.Singular && dict.firstPersonPronouns.Contains(mString) && ant.number == Dictionaries.Number.Singular && dict.firstPersonPronouns.Contains(antString) && CorefRules.EntitySameSpeaker(document, mention,
                                                                                                                                                                                                                                               ant))
                {
                    return(true);
                }
                // (speaker - I)
                if ((mention.number == Dictionaries.Number.Singular && dict.firstPersonPronouns.Contains(mString)) && CorefRules.AntecedentIsMentionSpeaker(document, mention, ant, dict))
                {
                    if (mention.speakerInfo == null && ant.speakerInfo != null)
                    {
                        mention.speakerInfo = ant.speakerInfo;
                    }
                    return(true);
                }
                // (I - speaker)
                if ((ant.number == Dictionaries.Number.Singular && dict.firstPersonPronouns.Contains(antString)) && CorefRules.AntecedentIsMentionSpeaker(document, ant, mention, dict))
                {
                    if (ant.speakerInfo == null && mention.speakerInfo != null)
                    {
                        ant.speakerInfo = mention.speakerInfo;
                    }
                    return(true);
                }
                // Can be iffy if more than two speakers... but still should be okay most of the time
                if (dict.secondPersonPronouns.Contains(mString) && dict.secondPersonPronouns.Contains(antString) && CorefRules.EntitySameSpeaker(document, mention, ant))
                {
                    return(true);
                }
                // previous I - you or previous you - I in two person conversation
                if (((mention.person == Dictionaries.Person.I && ant.person == Dictionaries.Person.You || (mention.person == Dictionaries.Person.You && ant.person == Dictionaries.Person.I)) && (mention.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation
                                                                                                                                                                                                                              )) - ant.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)) == 1) && document.docType == Document.DocType.Conversation))
                {
                    return(true);
                }
                if (dict.reflexivePronouns.Contains(mention.headString) && CorefRules.EntitySubjectObject(mention, ant))
                {
                    return(true);
                }
            }
            if (!flags.UseExactstringmatch && !flags.UseRelaxedExactstringmatch && !flags.UseApposition && !flags.UseWordsInclusion)
            {
                foreach (Mention m in mentionCluster.GetCorefMentions())
                {
                    foreach (Mention a in potentialAntecedent.GetCorefMentions())
                    {
                        // angelx - not sure about the logic here, disable (code was also refactored from original)
                        // vv gabor - re-enabled code (seems to improve performance) vv
                        if (m.person != Dictionaries.Person.I && a.person != Dictionaries.Person.I && (CorefRules.AntecedentIsMentionSpeaker(document, m, a, dict) || CorefRules.AntecedentIsMentionSpeaker(document, a, m, dict)))
                        {
                            document.AddIncompatible(m, a);
                            return(false);
                        }
                        // ^^ end block of code in question ^^
                        int dist = Math.Abs(m.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)) - a.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)));
                        if (document.docType != Document.DocType.Article && dist == 1 && !CorefRules.EntitySameSpeaker(document, m, a))
                        {
                            string mSpeaker = document.speakers[m.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation))];
                            string aSpeaker = document.speakers[a.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation))];
                            if (m.person == Dictionaries.Person.I && a.person == Dictionaries.Person.I)
                            {
                                document.AddIncompatible(m, a);
                                return(false);
                            }
                            if (m.person == Dictionaries.Person.You && a.person == Dictionaries.Person.You)
                            {
                                document.AddIncompatible(m, a);
                                return(false);
                            }
                            // This is weak since we can refer to both speakers
                            if (m.person == Dictionaries.Person.We && a.person == Dictionaries.Person.We)
                            {
                                document.AddIncompatible(m, a);
                                return(false);
                            }
                        }
                    }
                }
                if (document.docType == Document.DocType.Article)
                {
                    foreach (Mention m_1 in mentionCluster.GetCorefMentions())
                    {
                        foreach (Mention a in potentialAntecedent.GetCorefMentions())
                        {
                            if (CorefRules.EntitySubjectObject(m_1, a))
                            {
                                document.AddIncompatible(m_1, a);
                                return(false);
                            }
                        }
                    }
                }
            }
            // Incompatibility constraints - do before match checks
            if (flags.USE_iwithini && CorefRules.EntityIWithinI(mention, ant, dict))
            {
                document.AddIncompatible(mention, ant);
                return(false);
            }
            // Match checks
            if (flags.UseExactstringmatch && CorefRules.EntityExactStringMatch(mention, ant, dict, roleSet))
            {
                return(true);
            }
            //    if(flags.USE_EXACTSTRINGMATCH && Rules.entityExactStringMatch(mentionCluster, potentialAntecedent, dict, roleSet)){
            //      return true;
            //    }
            if (flags.UseNameMatch && CheckEntityMatch(document, mentionCluster, potentialAntecedent, dict, roleSet))
            {
                ret = true;
            }
            if (flags.UseRelaxedExactstringmatch && CorefRules.EntityRelaxedExactStringMatch(mentionCluster, potentialAntecedent, mention, ant, dict, roleSet))
            {
                return(true);
            }
            if (flags.UseApposition && CorefRules.EntityIsApposition(mentionCluster, potentialAntecedent, mention, ant))
            {
                return(true);
            }
            if (flags.UsePredicatenominatives && CorefRules.EntityIsPredicateNominatives(mentionCluster, potentialAntecedent, mention, ant))
            {
                return(true);
            }
            if (flags.UseAcronym && CorefRules.EntityIsAcronym(document, mentionCluster, potentialAntecedent))
            {
                return(true);
            }
            if (flags.UseRelativepronoun && CorefRules.EntityIsRelativePronoun(mention, ant))
            {
                return(true);
            }
            if (flags.UseDemonym && mention.IsDemonym(ant, dict))
            {
                return(true);
            }
            if (flags.UseRoleapposition)
            {
                if (lang == Locale.Chinese)
                {
                    ret = false;
                }
                else
                {
                    if (CorefRules.EntityIsRoleAppositive(mentionCluster, potentialAntecedent, mention, ant, dict))
                    {
                        ret = true;
                    }
                }
            }
            if (flags.UseInclusionHeadmatch && CorefRules.EntityHeadsAgree(mentionCluster, potentialAntecedent, mention, ant, dict))
            {
                ret = true;
            }
            if (flags.UseRelaxedHeadmatch && CorefRules.EntityRelaxedHeadsAgreeBetweenMentions(mentionCluster, potentialAntecedent, mention, ant))
            {
                ret = true;
            }
            if (flags.UseWordsInclusion && ret && !CorefRules.EntityWordsIncluded(mentionCluster, potentialAntecedent, mention, ant))
            {
                return(false);
            }
            if (flags.UseIncompatibleModifier && ret && CorefRules.EntityHaveIncompatibleModifier(mentionCluster, potentialAntecedent))
            {
                return(false);
            }
            if (flags.UseProperheadAtLast && ret && !CorefRules.EntitySameProperHeadLastWord(mentionCluster, potentialAntecedent, mention, ant))
            {
                return(false);
            }
            if (flags.UseAttributesAgree && !CorefRules.EntityAttributesAgree(mentionCluster, potentialAntecedent))
            {
                return(false);
            }
            if (flags.UseDifferentLocation && CorefRules.EntityHaveDifferentLocation(mention, ant, dict))
            {
                if (flags.UseProperheadAtLast && ret && mention.goldCorefClusterID != ant.goldCorefClusterID)
                {
                }
                return(false);
            }
            if (flags.UseNumberInMention && CorefRules.EntityNumberInLaterMention(mention, ant))
            {
                if (flags.UseProperheadAtLast && ret && mention.goldCorefClusterID != ant.goldCorefClusterID)
                {
                }
                return(false);
            }
            if (flags.UseDistance && CorefRules.EntityTokenDistance(mention2, ant))
            {
                return(false);
            }
            if (flags.UseCorefDict)
            {
                // Head match
                if (ant.headWord.Lemma().Equals(mention2.headWord.Lemma()))
                {
                    return(false);
                }
                // Constraint: ignore pairs commonNoun - properNoun
                if (ant.mentionType != Dictionaries.MentionType.Proper && (mention2.headWord.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)).StartsWith("NNP") || !Sharpen.Runtime.Substring(mention2.headWord.Word(), 1).Equals(Sharpen.Runtime.Substring(mention2
                                                                                                                                                                                                                                                               .headWord.Word(), 1).ToLower())))
                {
                    return(false);
                }
                // Constraint: ignore plurals
                if (ant.headWord.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)).Equals("NNS") && mention2.headWord.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)).Equals("NNS"))
                {
                    return(false);
                }
                // Constraint: ignore mentions with indefinite determiners
                if (dict.indefinitePronouns.Contains(ant.originalSpan[0].Lemma()) || dict.indefinitePronouns.Contains(mention2.originalSpan[0].Lemma()))
                {
                    return(false);
                }
                // Constraint: ignore coordinated mentions
                if (ant.IsCoordinated() || mention2.IsCoordinated())
                {
                    return(false);
                }
                // Constraint: context incompatibility
                if (CorefRules.ContextIncompatible(mention2, ant, dict))
                {
                    return(false);
                }
                // Constraint: sentence context incompatibility when the mentions are common nouns
                if (CorefRules.SentenceContextIncompatible(mention2, ant, dict))
                {
                    return(false);
                }
                if (CorefRules.EntityClusterAllCorefDictionary(mentionCluster, potentialAntecedent, dict, 1, 8))
                {
                    return(true);
                }
                if (CorefRules.EntityCorefDictionary(mention, ant, dict, 2, 2))
                {
                    return(true);
                }
                if (CorefRules.EntityCorefDictionary(mention, ant, dict, 3, 2))
                {
                    return(true);
                }
                if (CorefRules.EntityCorefDictionary(mention, ant, dict, 4, 2))
                {
                    return(true);
                }
            }
            if (flags.DoPronoun)
            {
                Mention m;
                if (mention.predicateNominatives != null && mention.predicateNominatives.Contains(mention2))
                {
                    m = mention2;
                }
                else
                {
                    m = mention;
                }
                bool mIsPronoun = (m.IsPronominal() || dict.allPronouns.Contains(m.ToString()));
                bool attrAgree  = HybridCorefProperties.UseDefaultPronounAgreement(props) ? CorefRules.EntityAttributesAgree(mentionCluster, potentialAntecedent) : CorefRules.EntityAttributesAgree(mentionCluster, potentialAntecedent, lang);
                if (mIsPronoun && attrAgree)
                {
                    if (dict.demonymSet.Contains(ant.LowercaseNormalizedSpanString()) && dict.notOrganizationPRP.Contains(m.headString))
                    {
                        document.AddIncompatible(m, ant);
                        return(false);
                    }
                    if (CorefRules.EntityPersonDisagree(document, mentionCluster, potentialAntecedent, dict))
                    {
                        document.AddIncompatible(m, ant);
                        return(false);
                    }
                    return(true);
                }
            }
            if (flags.UseChineseHeadMatch)
            {
                if (mention2.headWord == ant.headWord && mention2.InsideIn(ant))
                {
                    if (!document.IsCoref(mention2, ant))
                    {
                    }
                    // TODO: exclude conjunction
                    // log.info("error in chinese head match: "+mention2.spanToString()+"\t"+ant.spanToString());
                    return(true);
                }
            }
            return(ret);
        }