public override bool Transform(Sentence sentence) { KeyValuePair <string, string> nks = NeighborKinds(sentence); if (nks.Value == "ADVP") { sentence.MergeNext(this); return(true); } return(false); }
public override bool Transform(Sentence sentence) { if (!sentence.phrases.Contains(this)) { return(false); } bool success = false; bool lastFound = true; while (lastFound) { KeyValuePair <string, string> nks = NeighborKinds(sentence); if (nks.Value == "." && constituents[constituents.Count - 1].Text.Length == 1) { sentence.AbsorbNext(this); // eat the period } else if (nks.Key == "" && nks.Value == "NP") { sentence.MergeNext(this); } else if (nks.Key == "NP" && nks.Value == "NP") { sentence.MergeNext(this); } else if (nks.Key == "NP" && (nks.Value == "" || nks.Value == "." || nks.Value == "!")) { sentence.MergePrevious(this); } else { lastFound = false; } if (lastFound == true) { success = true; } } KeyValuePair <string, string> neighbors = NeighborKinds(sentence); if (neighbors.Key == "DT" || neighbors.Key == "PRP$") { sentence.AbsorbPrevious(this); neighbors = NeighborKinds(sentence); success = true; } if (neighbors.Key == "ADJP") { List <Phrase> phrases = new List <Phrase>(); phrases.Add(sentence.PhraseBefore(this)); phrases.Add(this); sentence.Combine(phrases, new NounPhrase()); neighbors = NeighborKinds(sentence); success = true; } if (neighbors.Value == "PP") { Phrase after = sentence.PhraseAfter(this); if (after.Constituents.Count > 1 && after.Constituents[0].Text.ToLower() == "of") { sentence.AbsorbNext(this); return(true); } } return(success); }