/// <summary> /// Adds the given word to the end of the phrase. /// </summary> /// <param name="word">The word to add.</param> public void Add(WordNode word) { if (word != null) { Words.Add(word); } }
/// <summary> /// Creates a new ArgumentNode from the given parameters, and adds it to the SecondaryArguments list. /// </summary> /// <param name="argument">The node that is serving as the argument.</param> /// <param name="preposition">The preposition describing the argument's relation to the method.</param> public void AddSecondaryArgument(Node argument, WordNode preposition) { if (this.SecondaryArguments == null) { this.SecondaryArguments = new List <ArgumentNode>(); } ArgumentNode an = new ArgumentNode(argument, preposition); this.SecondaryArguments.Add(an); }
/// <summary> /// Creates a PhraseNode by parsing the given string representation. /// </summary> /// <param name="source">The string to parse the PhraseNode from.</param> /// <returns>A new PhraseNode.</returns> public static PhraseNode Parse(string source) { if (source == null) { throw new ArgumentNullException("source"); } var words = source.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var pn = new PhraseNode(); foreach (var word in words) { pn.Words.Add(WordNode.Parse(word)); } return(pn); }
public void TestRoundTrip() { var a1 = new WordNode("DB", PartOfSpeechTag.Preamble); var a2 = new WordNode("Get", PartOfSpeechTag.Verb); var t1 = new WordNode("Hydro", PartOfSpeechTag.NounModifier); var t2 = new WordNode("Fixed", PartOfSpeechTag.NounModifier); var t3 = new WordNode("Schedule", PartOfSpeechTag.Noun); var sdr = new SwumDataRecord(); sdr.ParsedAction = new PhraseNode(new[] {a1, a2}, Location.None, false); sdr.Action = sdr.ParsedAction.ToPlainString(); sdr.ParsedTheme = new PhraseNode(new[] {t1, t2, t3}, Location.None, false); sdr.Theme = sdr.ParsedTheme.ToPlainString(); var actual = SwumDataRecord.Parse(sdr.ToString()); Assert.IsTrue(SwumDataRecordsAreEqual(sdr, actual)); }
/// <summary> /// Creates a new ArgumentNode from the given parameters, and adds it to the SecondaryArguments list. /// </summary> /// <param name="argument">The node that is serving as the argument.</param> /// <param name="preposition">The preposition describing the argument's relation to the method.</param> public void AddSecondaryArgument(Node argument, WordNode preposition) { if(this.SecondaryArguments == null) { this.SecondaryArguments = new List<ArgumentNode>(); } ArgumentNode an = new ArgumentNode(argument, preposition); this.SecondaryArguments.Add(an); }
/// <summary> /// Creates a new ArgumentNode. /// </summary> /// <param name="argument">The node being passed as an argument.</param> /// <param name="preposition">A prepostion describing the argument's relationship to its method.</param> public ArgumentNode(Node argument, WordNode preposition) { this.Argument = argument; this.Preposition = preposition; }
/// <summary> /// Adds the given word to the end of the phrase. /// </summary> /// <param name="word">The word to add.</param> public void Add(WordNode word) { if(word != null) { Words.Add(word); } }
public void TestRoundTrip_FileNames() { var a1 = new WordNode("DB", PartOfSpeechTag.Preamble); var a2 = new WordNode("Get", PartOfSpeechTag.Verb); var t1 = new WordNode("Hydro", PartOfSpeechTag.NounModifier); var t2 = new WordNode("Fixed", PartOfSpeechTag.NounModifier); var t3 = new WordNode("Schedule", PartOfSpeechTag.Noun); var f1 = @"C:\foo\bar.cpp"; var f2 = @"C:\foo\baz\xyzzy.h"; var f3 = "test.cpp"; var sdr = new SwumDataRecord(); sdr.ParsedAction = new PhraseNode(new[] { a1, a2 }, Location.None, false); sdr.Action = sdr.ParsedAction.ToPlainString(); sdr.ParsedTheme = new PhraseNode(new[] { t1, t2, t3 }, Location.None, false); sdr.Theme = sdr.ParsedTheme.ToPlainString(); sdr.FileNameHashes.Add(f1.GetHashCode()); sdr.FileNameHashes.Add(f2.GetHashCode()); sdr.FileNameHashes.Add(f3.GetHashCode()); var actual = SwumDataRecord.Parse(sdr.ToString()); Assert.IsTrue(SwumDataRecordsAreEqual(sdr, actual)); }
public bool WordNodesAreEqual(WordNode wn1, WordNode wn2) { if(wn1 == wn2) { return true; } if(wn1 == null ^ wn2 == null) { return false; } return wn1.Text == wn2.Text && wn1.Tag == wn2.Tag && wn1.Location == wn2.Location && Math.Abs(wn1.Confidence - wn2.Confidence) < .00001; }