// Guess whether or not a phrase is plural public static ProbableStrength SeemsPlural(InformedPhrase phrase) { ProbableStrength result = new ProbableStrength(0, 0); double strengthFactor = result.ImproveStrengthStart(); // Noun count is well determined by ending in s ProbableStrength nounness = PartOSAttribute.SeemsA(phrase, SpeechPart.Noun); ProbableStrength nisplural; if (phrase.Name.ToLower().EndsWith("s")) nisplural = new ProbableStrength(1.0, 0.8); else nisplural = new ProbableStrength(0.0, 0.5); result.ImproveStrength(nounness.Relative(nisplural), ref strengthFactor); // Verbs that end in s are probably not plural ProbableStrength verbness = PartOSAttribute.SeemsA(phrase, SpeechPart.Verb); if (phrase.Name.ToLower().EndsWith("s")) { ProbableStrength visplural = new ProbableStrength(0.0, 0.8); result.ImproveStrength(verbness.Relative(visplural), ref strengthFactor); } result.ImproveStrengthFinish(strengthFactor); return result; }
public override ProbableStrength IsMatch(PhraseAttribute attribute) { if (attribute is PartOSAttribute) { PartOSAttribute partosAttribute = (PartOSAttribute)attribute; return(partosAttribute.part.SeemsA(part, false)); } return(ProbableStrength.None); }
// Look through phrases, finding all speech parts public List <KeyValuePair <SpeechPart, double> > SpeechParts() { List <KeyValuePair <SpeechPart, double> > kvparts = new List <KeyValuePair <SpeechPart, double> >(); foreach (KeyValuePair <PhraseSense, double> sense in senses) { PartOSAttribute partAttribute = (PartOSAttribute)sense.Key.FindAttribute(typeof(PartOSAttribute)); kvparts.Add(new KeyValuePair <SpeechPart, double>(partAttribute.Part, sense.Value)); } return(kvparts); }
// Find a sense of the given speech part public PhraseSense FindSense(SpeechPart part, bool allSubs) { foreach (KeyValuePair <PhraseSense, double> sense in senses) { PartOSAttribute partAttribute = (PartOSAttribute)sense.Key.FindAttribute(typeof(PartOSAttribute)); if (partAttribute.Part.SeemsA(part, allSubs).IsLikely(.5)) { return(sense.Key); } } return(null); // not found }
// Find all phrases with the given speech part // Phrases returned may overlap lots public List <InformedPhrase> FindPhrases(SpeechPart part, bool allSubs) { List <InformedPhrase> phrases = new List <InformedPhrase>(); // Look through each sense foreach (KeyValuePair <PhraseSense, double> sense in senses) { PartOSAttribute partAttribute = (PartOSAttribute)sense.Key.FindAttribute(typeof(PartOSAttribute)); if (partAttribute.Part.SeemsA(part, allSubs).IsLikely(.5)) { if (sense.Key.Phrases.Count == 1) { // just add the sub piece, if it matches too List <InformedPhrase> submatches = sense.Key.Phrases[0].FindPhrases(part, allSubs); if (submatches.Count > 0) { phrases.AddRange(submatches); } else if (!phrases.Contains(this)) { phrases.Add(this); } } else if (!phrases.Contains(this)) { phrases.Add(this); } } if (sense.Key.Phrases.Count > 1) { // Recurse on each phrase foreach (InformedPhrase subphrase in sense.Key.Phrases) { phrases.AddRange(subphrase.FindPhrases(part, allSubs)); } } } return(phrases); }