protected internal override List <string> GetFeatures(MentionContext mention, DiscourseEntity entity) { var features = base.GetFeatures(mention, entity); if (entity != null) { features.AddRange(GetPronounMatchFeatures(mention, entity)); var contexts = GetContextFeatures(mention); var cec = entity.LastExtent; if (PartsOfSpeech.IsPersOrPossPronoun(mention.HeadTokenTag) && PartsOfSpeech.IsPersOrPossPronoun(cec.HeadTokenTag)) { features.Add(mention.HeadTokenText + "," + cec.HeadTokenText); } else if (PartsOfSpeech.IsProperNoun(mention.HeadTokenText)) { for (int ci = 0, cl = contexts.Count; ci < cl; ci++) { features.Add(contexts[ci]); } features.Add(mention.NameType + "," + cec.HeadTokenText); } else { var ccontexts = GetContextFeatures(cec); for (int ci = 0, cl = ccontexts.Count; ci < cl; ci++) { features.Add(ccontexts[ci]); } features.Add(cec.NameType + "," + mention.HeadTokenText); } } return(features); }
protected internal override bool IsExcluded(MentionContext mention, DiscourseEntity entity) { if (base.IsExcluded(mention, entity)) { return(true); } string mentionGender = null; foreach (MentionContext entityMention in entity.Mentions) { string tag = entityMention.HeadTokenTag; if (tag != null && PartsOfSpeech.IsPersOrPossPronoun(tag) && Linker.SingularThirdPersonPronounPattern.IsMatch(mention.HeadTokenText)) { if (mentionGender == null) { //lazy initilization mentionGender = GetPronounGender(mention.HeadTokenText); } string entityGender = GetPronounGender(entityMention.HeadTokenText); if (!entityGender.Equals("u") && !mentionGender.Equals(entityGender)) { return(true); } } } return(false); }
private void CollectPossessivePronouns(IParse nounPhrase, List <Mention> entities) { //TODO: Look at how training is done and examine whether this is needed or can be accomidated in a different way. /* * List snps = np.getSubNounPhrases(); * if (snps.size() != 0) { * for (int si = 0, sl = snps.size(); si < sl; si++) { * Parse snp = (Parse) snps.get(si); * Extent ppExtent = new Extent(snp.getSpan(), snp.getSpan(), snp.getEntityId(), null,Linker.PRONOUN_MODIFIER); * entities.add(ppExtent); * } * } * else { */ List <IParse> nounPhraseTokens = nounPhrase.Tokens; IParse headToken = mHeadFinder.GetHeadToken(nounPhrase); for (int tokenIndex = nounPhraseTokens.Count - 2; tokenIndex >= 0; tokenIndex--) { IParse token = nounPhraseTokens[tokenIndex]; if (token == headToken) { continue; } if (PartsOfSpeech.IsPersOrPossPronoun(token.SyntacticType) && IsHandledPronoun(token.ToString())) { var possessivePronounExtent = new Mention(token.Span, token.Span, token.EntityId, null, Linker.PronounModifier); entities.Add(possessivePronounExtent); break; } } //} }
public override bool CanResolve(MentionContext mention) { var tag = mention.HeadTokenTag; var fpp = tag != null && PartsOfSpeech.IsPersOrPossPronoun(tag) && Linker.SpeechPronounPattern.IsMatch(mention.HeadTokenText); var pn = tag != null && PartsOfSpeech.IsProperNoun(tag); return(fpp || pn); }
/// <summary> /// Returns features indicating whether the specified mention is compatible with the pronouns /// of the specified entity. /// </summary> /// <param name="mention"> /// The mention. /// </param> /// <param name="entity"> /// The entity. /// </param> /// <returns> /// list of features indicating whether the specified mention is compatible with the pronouns /// of the specified entity. /// </returns> protected internal virtual List <string> GetPronounMatchFeatures(Mention.MentionContext mention, DiscourseEntity entity) { bool foundCompatiblePronoun = false; bool foundIncompatiblePronoun = false; if (PartsOfSpeech.IsPersOrPossPronoun(mention.HeadTokenTag)) { Dictionary <string, string> pronounMap = GetPronounFeatureMap(mention.HeadTokenText); foreach (Mention.MentionContext candidateMention in entity.Mentions) { if (PartsOfSpeech.IsPersOrPossPronoun(candidateMention.HeadTokenTag)) { if (mention.HeadTokenText.ToUpper() == candidateMention.HeadTokenText.ToUpper()) { foundCompatiblePronoun = true; break; } else { Dictionary <string, string> candidatePronounMap = GetPronounFeatureMap(candidateMention.HeadTokenText); bool allKeysMatch = true; foreach (string key in pronounMap.Keys) { if (candidatePronounMap.ContainsKey(key)) { if (pronounMap[key] != candidatePronounMap[key]) { foundIncompatiblePronoun = true; allKeysMatch = false; } } else { allKeysMatch = false; } } if (allKeysMatch) { foundCompatiblePronoun = true; } } } } } var pronounFeatures = new List <string>(); if (foundCompatiblePronoun) { pronounFeatures.Add("compatiblePronoun"); } if (foundIncompatiblePronoun) { pronounFeatures.Add("incompatiblePronoun"); } return(pronounFeatures); }
//UPGRADE_NOTE: Access modifiers of method 'excluded' were changed to 'public'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1204'" protected internal override bool IsExcluded(MentionContext mention, DiscourseEntity entity) { if (base.IsExcluded(mention, entity)) { return(true); } var cec = entity.LastExtent; if (!CanResolve(cec)) { return(true); } if (PartsOfSpeech.IsProperNoun(mention.HeadTokenTag)) { //mention is a propernoun if (PartsOfSpeech.IsProperNoun(cec.HeadTokenTag)) { return(true); // both NNP } else { if (entity.MentionCount > 1) { return(true); } return(!CanResolve(cec)); } } else if (PartsOfSpeech.IsPersOrPossPronoun(mention.HeadTokenTag)) { // mention is a speech pronoun // cec can be either a speech pronoun or a propernoun if (PartsOfSpeech.IsProperNoun(cec.HeadTokenTag)) { //exclude antecedents not in the same sentence when they are not pronoun return(mention.SentenceNumber - cec.SentenceNumber != 0); } else if (PartsOfSpeech.IsPersOrPossPronoun(cec.HeadTokenTag)) { return(false); } else { Console.Error.WriteLine("Unexpected candidate exluded: " + cec.ToText()); return(true); } } else { Console.Error.WriteLine("Unexpected mention exluded: " + mention.ToText()); return(true); } }
public override bool CanResolve(MentionContext mention) { string tag = mention.HeadTokenTag; return(tag != null && PartsOfSpeech.IsPersOrPossPronoun(tag) && Linker.SingularThirdPersonPronounPattern.IsMatch(mention.HeadTokenText)); }
private bool IsPronoun(Context nounPhrase) { return(PartsOfSpeech.IsPersOrPossPronoun(nounPhrase.HeadTokenTag)); }