public SentenceDetection(PhraseNode silence, long threshold, double gap, double leadingSilence, Settings settings) : this() { if (silence != null) { double thresholdVal = Audio.PhraseDetection.GetSilenceAmplitude(silence.Audio); if (thresholdVal > Convert.ToDouble(mThresholdNumericBox.Maximum)) { thresholdVal = Convert.ToDouble(mThresholdNumericBox.Maximum); } mThresholdNumericBox.Value = Convert.ToDecimal(thresholdVal); } else { MessageBox.Show(Localizer.Message("no_preceding_silence_phrase"), Localizer.Message("no_preceding_silence_phrase_caption"), MessageBoxButtons.OK, MessageBoxIcon.Information); mThresholdNumericBox.Value = Convert.ToDecimal(threshold); } mGapNumericBox.Value = Convert.ToDecimal(gap); mLeadingNumericBox.Value = Convert.ToDecimal(leadingSilence); //mGapNumericBox.Value = Convert.ToDecimal(Audio.PhraseDetection.DEFAULT_GAP); //mLeadingNumericBox.Value = Convert.ToDecimal(Audio.PhraseDetection.DEFAULT_LEADING_SILENCE); if (settings.ObiFont != this.Font.Name) { this.Font = new System.Drawing.Font(settings.ObiFont, this.Font.Size, System.Drawing.FontStyle.Regular);//@fontconfig } }
public Copy(ProjectView.ProjectView view, PhraseNode node, AudioRange range) : base(view) { mOldClipboard = view.Clipboard; mNewClipboard = new AudioClipboard(node, range); SetDescriptions(Localizer.Message("copy_audio")); }
// Create a split command preserving used/TODO status, and optionally transferring the role to the next node public static SplitAudio AppendSplitCommandWithProperties(ProjectView.ProjectView view, CompositeCommand command, PhraseNode phrase, double time, bool transferRole) { SplitAudio split = new SplitAudio(view, phrase, time); if (split.Node.TODO) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.ToggleNodeTODO(view, split.NodeAfter)); } if (!split.Node.Used) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.ToggleNodeUsed(view, split.NodeAfter)); } if (split.Node.Role_ == EmptyNode.Role.Silence || phrase.Role_ == EmptyNode.Role.Custom) { Commands.Node.AssignRole copyRoleCmd = new Commands.Node.AssignRole(view, split.NodeAfter, phrase.Role_, phrase.CustomRole); copyRoleCmd.UpdateSelection = false; command.ChildCommands.Insert(command.ChildCommands.Count, copyRoleCmd); } command.ChildCommands.Insert(command.ChildCommands.Count, split); if (transferRole && phrase.Role_ != EmptyNode.Role.Plain) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AssignRole(view, phrase, EmptyNode.Role.Plain)); if (phrase.Role_ == EmptyNode.Role.Page) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.SetPageNumber(view, split.NodeAfter, phrase.PageNumber.Clone())); } else { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AssignRole(view, split.NodeAfter, phrase.Role_, phrase.CustomRole)); } } return(split); }
public void TestConstructor_EnumerableStringsNull() { var pn = new PhraseNode(null); Assert.AreEqual(0, pn.Size()); Assert.AreEqual(Location.None, pn.Location); }
/// <summary> /// Determines whether the given PhraseNode overlaps with the given word. /// The two overlap if the last word of the phrase is the same as the given word, /// or if the second-to-last word of the phrase is the same as the given word and the last word of the phrase is ignorable. /// </summary> /// <param name="name">The phrase to check for overlap.</param> /// <param name="word">The word to check for overlap with.</param> /// <returns>True if the phrase and word overlap, False otherwise.</returns> private bool HasOverlap(PhraseNode name, string word) { if (name == null || name.Size() == 0 || string.IsNullOrEmpty(word)) { return(false); } bool hasOverlap = false; if (string.Equals(name.LastWord().Text, word, StringComparison.InvariantCultureIgnoreCase)) { //last word of name is same as given word hasOverlap = true; } else if (name.Size() > 1) { if (string.Equals(name[name.Size() - 2].Text, word, StringComparison.InvariantCultureIgnoreCase) && PosData.IsIgnorableHeadWord(name.LastWord().Text)) { //second-to-last word of name is same as given word, and the last word of name is ignorable hasOverlap = true; } } return(hasOverlap); }
public void ImportAudio(string path, SectionNode sectionNode) { List <string> tempAudioFilePaths = new List <string>(); string[] tempAudioFilePathsArray = new string[1]; if (path != string.Empty && System.IO.File.Exists(path) && (System.IO.Path.GetExtension(path).ToLower() == ".wav" || System.IO.Path.GetExtension(path).ToLower() == ".mp3" || System.IO.Path.GetExtension(path).ToLower() == ".mp4" || System.IO.Path.GetExtension(path).ToLower() == ".m4a")) { tempAudioFilePathsArray[0] = path; tempAudioFilePathsArray = Audio.AudioFormatConverter.ConvertFiles(tempAudioFilePathsArray, m_Presentation); } else { tempAudioFilePathsArray[0] = string.Empty; if (path != string.Empty) { m_audioFilesNotImported += ", " + Path.GetFileName(path); } } if (tempAudioFilePathsArray.Length != 0) { path = tempAudioFilePathsArray[0]; } if (m_ProjectView.ObiForm.Settings.Project_CSVImportPhraseDetection && !m_IsPhraseDetectionSettingsShown) { m_Threshold = (long)m_ProjectView.ObiForm.Settings.Audio_DefaultThreshold; m_Gap = (double)m_ProjectView.ObiForm.Settings.Audio_DefaultGap; m_LeadingSilence = (double)m_ProjectView.ObiForm.Settings.Audio_DefaultLeadingSilence; Dialogs.SentenceDetection sentenceDetection = new Obi.Dialogs.SentenceDetection(m_Threshold, m_Gap, m_LeadingSilence, m_ProjectView.ObiForm.Settings); //@fontconfig m_IsPhraseDetectionSettingsShown = true; if (sentenceDetection.ShowDialog() == DialogResult.OK) { m_Threshold = sentenceDetection.Threshold; m_Gap = sentenceDetection.Gap; m_LeadingSilence = sentenceDetection.LeadingSilence; } } try { if (path != string.Empty) { PhraseNode phraseNode = m_Presentation.CreatePhraseNode(path); if (phraseNode != null) { m_Presentation.Do(this.GetCommandForImportAudioFileInEachSection(phraseNode, sectionNode)); } if (m_ProjectView.ObiForm.Settings.Project_CSVImportPhraseDetection) { ApplyPhraseDetectionOnPhrase(phraseNode, m_Threshold, m_Gap, m_LeadingSilence); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(path + ": " + e.Message, Localizer.Message("Caption_Error")); } }
public PhraseDetectionEventArgs(object origin, PhraseNode node, long threshold, double gap, double leading) : base(origin, node) { mThreshold = threshold; mGap = gap; mLeadingSilence = leading; }
/// <summary> /// Creates a tree from the given query /// </summary> /// <param name="query">Query to parse into a tree</param> /// <returns>The tree representation of the query</returns> public static Node CreateTree(string query) { var queryIdentifiers = new[] { "\"", "\\sand\\s", "\\sor\\s", "\\snot\\s", "\\sselect\\s", "\\swhere\\s", }; Node tree; if (string.IsNullOrEmpty(query)) { tree = new ScanNode(); } else if (!queryIdentifiers.Any(i => Regex.IsMatch(query, i)) && !query.TrimStart().StartsWith("*")) { tree = new PhraseNode(query, false, null, null); } else { lock (_fieldTypes) { tree = QueryParser.Parse(query); } } return(tree); }
public Paste(ProjectView.ProjectView view, double pasteTime) : base(view) { mNode = view.SelectedNodeAs <PhraseNode>(); //AudioSelection selection = (AudioSelection)view.Selection; mMediaBefore = mNode.Audio.Copy(); mMediaAfter = mMediaBefore.Copy(); urakawa.media.data.audio.ManagedAudioMedia copy; if (view.Clipboard is AudioClipboard) { AudioClipboard clipboard = (AudioClipboard)view.Clipboard; copy = view.Presentation.MediaFactory.CreateManagedAudioMedia(); WavAudioMediaData mediaData = ((WavAudioMediaData)((PhraseNode)clipboard.Node).Audio.AudioMediaData).Copy( new Time((long)(clipboard.AudioRange.SelectionBeginTime * Time.TIME_UNIT)), new Time((long)(clipboard.AudioRange.SelectionEndTime * Time.TIME_UNIT)) ); copy.AudioMediaData = mediaData; } else { copy = ((PhraseNode)view.Clipboard.Node).Audio.Copy(); } urakawa.media.data.audio.ManagedAudioMedia after; after = mMediaAfter.Split(new Time((long)(pasteTime * Time.TIME_UNIT))); double begin = mMediaAfter.Duration.AsMilliseconds; mSelectionAfter = new AudioSelection(mNode, view.Selection.Control, new AudioRange(begin, begin + copy.Duration.AsMilliseconds)); mMediaAfter.AudioMediaData.MergeWith(copy.AudioMediaData); mMediaAfter.AudioMediaData.MergeWith(after.AudioMediaData); SetDescriptions(Localizer.Message("paste_audio")); }
private Time mSplitTime; // split point (begin/cursor) // Create a split command to split the selected node at the given position. // Use only through GetSplitCommand. private SplitAudio(ProjectView.ProjectView view, PhraseNode node, double time) : base(view) { mNode = node; mNodeAfter = view.Presentation.CreatePhraseNode(); mSplitTime = new Time((long)(time * Time.TIME_UNIT)); SetDescriptions(Localizer.Message("split_phrase")); }
public static CompositeCommand GetSplitCommand(ProjectView.ProjectView view, PhraseNode phrase, double time) { CompositeCommand command = view.Presentation.CreateCompositeCommand(Localizer.Message("split_phrase")); AppendSplitCommandWithProperties(view, command, phrase, time, false); return(command); }
//public SetMediaEventArgs(object origin, PhraseNode node, string channel, IMedia media): public SetMediaEventArgs(object origin, PhraseNode node, string channel, urakawa.media.Media media)//sdk2 : base(origin, node) { mChannel = channel; mMedia = media; mCancel = false; }
private CompositeCommand GetCommandForImportAudioFileInEachSection(PhraseNode phraseNode, SectionNode section) { CompositeCommand command = m_Presentation.CreateCompositeCommand(Localizer.Message("import_phrases")); Commands.Node.AddNode addCmd = new Commands.Node.AddNode(m_ProjectView, phraseNode, section, section.PhraseChildCount, false); command.ChildCommands.Insert(command.ChildCommands.Count, addCmd); return(command); }
private PhraseNode CreatePhraseNodeFromAudioElement(SectionNode section, XmlNode audioNode) { PhraseNode phrase = m_Presentation.CreatePhraseNode(); section.AppendChild(phrase); addAudio(phrase, audioNode, true); return(phrase); }
/// <summary> /// Add an existing node to a parent node at the given index. /// </summary> public UpdateAudioMedia(ProjectView.ProjectView view, PhraseNode node, ManagedAudioMedia media, bool updateSelection) : base(view, "") { m_Node = node; m_OriginalManagedAudioMedia = node.Audio; m_ManagedAudioMedia = media; UpdateSelection = updateSelection; mSelection = view.Selection != null && view.Selection.Control is ProjectView.ContentView ? new NodeSelection(m_Node, view.Selection.Control) : view.Selection; }
public void TestConstructor_EnumerableStrings() { var words = new string[] {"Eat", "More", "chicken"}; var pn = new PhraseNode(words); Assert.AreEqual(3, pn.Size()); for(int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i].Text); } Assert.AreEqual(Location.None, pn.Location); }
public void TestRoundTrip() { var wn1 = new WordNode("Get", PartOfSpeechTag.Verb); var wn2 = new WordNode("Fixed", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Hydro", PartOfSpeechTag.NounModifier); var wn4 = new WordNode("Schedule", PartOfSpeechTag.Noun); var pn = new PhraseNode(new[] { wn1, wn2, wn3, wn4 }, Location.Name, false); Assert.IsTrue(PhraseNodesAreEqual(pn, PhraseNode.Parse(pn.ToString()))); }
public void TestConstructor_EnumerableWordNodesEmpty() { var words = new WordNode[] {}; PhraseNode pn = new PhraseNode(words, Location.Name, true); Assert.AreEqual(words.Length, pn.Size()); for(int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i]); } Assert.AreEqual(Location.Name, pn.Location); }
public void TestConstructor_EnumerableStringsEmpty() { var words = new string[] {}; var pn = new PhraseNode(words); Assert.AreEqual(words.Length, pn.Size()); for(int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i].Text); } Assert.AreEqual(Location.None, pn.Location); }
public void TestCreateThemeFromPhrases_SecondNull() { MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod"); PhraseNode pn2 = new PhraseNode(new string[] { "cowboy", "watermelon" }); mdn.CreateThemeFromPhrases(null, pn2); Assert.AreSame(pn2, mdn.Theme); Assert.AreEqual(2, pn2.Size()); Assert.AreEqual("cowboy", pn2[0].Text); Assert.AreEqual("watermelon", pn2[1].Text); }
public void TestCreateThemeFromPhrases_FirstNull() { MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod"); PhraseNode pn1 = new PhraseNode(new string[] { "hello", "World" }); mdn.CreateThemeFromPhrases(pn1, null); Assert.AreSame(pn1, mdn.Theme); Assert.AreEqual(2, pn1.Size()); Assert.AreEqual("hello", pn1[0].Text); Assert.AreEqual("World", pn1[1].Text); }
/// <summary> /// Finds the index of the first preposition within the given PhraseNode, starting from the word indicated by startIndex. /// </summary> /// <param name="parsedName">The PhraseNode to search.</param> /// <param name="startIndex">The index of the word to start searching for prepositions from.</param> /// <returns>The index of the first preposition in the PhraseNode after startIndex, inclusively.</returns> private int FindFirstPreposition(PhraseNode parsedName, int startIndex) { for (int i = startIndex; i < parsedName.Size(); i++) { if (parsedName[i].Tag == PartOfSpeechTag.Preposition) { return(i); } } return(-1); }
public MergeAudio(ProjectView.ProjectView view, PhraseNode node, PhraseNode next) : base(view) { mNode = node; mNextNode = next; // allow setting split time while executing command if the current node does not have audio yet. it is useful for composite commands mSplitTime = mNode.Audio != null? mNode.Audio.Duration : null; // new Time instance (no shared) m_IsNextNodeRooted = mNextNode.IsRooted; }
private bool IsPrepositionalPhrase(PhraseNode parsedName) { foreach (WordNode word in parsedName.GetPhrase()) { if (word.Tag == PartOfSpeechTag.Preposition) { return(true); } } return(false); }
public void TestParse() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] { wn1, wn2, wn3 }; var expected = new PhraseNode(words, Location.Name, false); var actual = PhraseNode.Parse("Eat(Verb) More(NounModifier) Chicken(Noun)"); Assert.IsTrue(PhraseNodesAreEqual(actual, expected)); }
public void TestGetParse() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] { wn1, wn2, wn3 }; PhraseNode pn = new PhraseNode(words, Location.Name, true); var parse = pn.GetParse(); Assert.AreEqual(pn, parse); }
public void TestConstructor_EnumerableStringsEmpty() { var words = new string[] {}; var pn = new PhraseNode(words); Assert.AreEqual(words.Length, pn.Size()); for (int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i].Text); } Assert.AreEqual(Location.None, pn.Location); }
public void TestToString() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] { wn1, wn2, wn3 }; PhraseNode pn = new PhraseNode(words, Location.Name, true); string expected = string.Format("{0} {1} {2}", wn1, wn2, wn3); Assert.AreEqual(expected, pn.ToString()); }
public void TestConstructor_EnumerableWordNodesEmpty() { var words = new WordNode[] {}; PhraseNode pn = new PhraseNode(words, Location.Name, true); Assert.AreEqual(words.Length, pn.Size()); for (int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i]); } Assert.AreEqual(Location.Name, pn.Location); }
public void TestConstructor_EnumerableStrings() { var words = new string[] { "Eat", "More", "chicken" }; var pn = new PhraseNode(words); Assert.AreEqual(3, pn.Size()); for (int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i].Text); } Assert.AreEqual(Location.None, pn.Location); }
public void Visit(PhraseNode node) { EstimatedCount = _log.Estimate(node.Tokens); Mode = node.Exact ? Query.EvaluationMode.Evaluate : Query.EvaluationMode.Index; if (EstimatedCount >= _log.Count) { Index = _log.Search(); } else { Index = _log.Search(node.Tokens); } }
/// <summary> /// Determines whether the given phrase indicates an event handler method. /// </summary> /// <param name="parsedName">The PhraseNode to test.</param> /// <returns>True if the phrase indicates an event handler method, False otherwise.</returns> protected bool IsEventHandler(PhraseNode parsedName) { if (parsedName == null || parsedName.Size() == 0) { return(false); } else { return(IsNonBaseVerb(parsedName.LastWord().Text) && parsedName[0].Text.ToLower() != "get" && parsedName[0].Text.ToLower() != "set"); } }
/// <summary> /// Determines whether the specified word in the given phrase is an ignorable verb. If so, it tags it appropriately. /// </summary> /// <param name="parsedName">The PhraseNode containing the word to check.</param> /// <param name="wordIndex">The index of the desired word within the PhraseNode.</param> /// <returns>wordIndex+1 if the word was an ignorable verb; wordIndex if it was not.</returns> private int CheckForIgnorableVerb(PhraseNode parsedName, int wordIndex) { if (wordIndex < parsedName.Size() - 1 && //make sure last word in name is verb (PosData.IsIgnorableVerb(parsedName[wordIndex].Text) && (PositionalFrequencies.GetVerbProbability(parsedName[wordIndex + 1].Text) > PositionalFrequencies.GetNounProbability(parsedName[wordIndex + 1].Text)) || PosData.IsModalVerb(parsedName[wordIndex].Text)) ) { parsedName[wordIndex].Tag = PartOfSpeechTag.VerbIgnorable; wordIndex++; } return(wordIndex); }
public void TestConstructor_EnumerableWordNodes() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] {wn1, wn2, wn3}; PhraseNode pn = new PhraseNode(words, Location.Name, true); Assert.AreEqual(words.Length, pn.Size()); for(int i = 0; i < pn.Size(); i++) { Assert.AreEqual(words[i], pn[i]); } Assert.AreEqual(Location.Name, pn.Location); }
public void TestConstructor_EnumerableStringsNull() { var pn = new PhraseNode(null); Assert.AreEqual(0, pn.Size()); Assert.AreEqual(Location.None, pn.Location); }
public void TestCreateThemeFromPhrases_FirstNull() { MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod"); PhraseNode pn1 = new PhraseNode(new string[] { "hello", "World" }); mdn.CreateThemeFromPhrases(pn1, null); Assert.AreSame(pn1, mdn.Theme); Assert.AreEqual(2, pn1.Size()); Assert.AreEqual("hello", pn1[0].Text); Assert.AreEqual("World", pn1[1].Text); }
public void TestCreateThemeFromPhrases() { MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod"); PhraseNode pn1 = new PhraseNode(new string[] { "hello", "World" }); PhraseNode pn2 = new PhraseNode(new string[] { "cowboy", "watermelon" }); mdn.CreateThemeFromPhrases(pn1, pn2); Assert.AreSame(pn1, mdn.Theme); Assert.AreEqual(4, pn1.Size()); Assert.AreEqual("hello", pn1[0].Text); Assert.AreEqual("World", pn1[1].Text); Assert.AreEqual("cowboy", pn1[2].Text); Assert.AreEqual("watermelon", pn1[3].Text); }
public void TestCreateEquivalenceFromUnknownArguments() { var arg1 = new VariableDeclarationNode("arg1"); var arg2 = new VariableDeclarationNode("arg2"); var arg3 = new VariableDeclarationNode("arg3"); var arg4 = new VariableDeclarationNode("arg4"); var mdn = new MethodDeclarationNode("MyMethod"); mdn.AddUnknownArguments(new VariableDeclarationNode[] { arg1, arg2, arg3, arg4 }); Assert.AreEqual(4, mdn.UnknownArguments.Count); var themeNode = new PhraseNode(new string[] { "Relevent", "Args" }); EquivalenceNode equiv = mdn.CreateEquivalenceFromUnknownArguments(themeNode, new bool[] { true, false, true, false }); Assert.AreEqual(3, equiv.EquivalentNodes.Count); Assert.IsTrue(equiv.EquivalentNodes.Contains(themeNode)); Assert.IsTrue(equiv.EquivalentNodes.Contains(arg1)); Assert.IsTrue(equiv.EquivalentNodes.Contains(arg3)); Assert.AreEqual(2, mdn.UnknownArguments.Count); Assert.IsTrue(mdn.UnknownArguments.Contains(arg2)); Assert.IsTrue(mdn.UnknownArguments.Contains(arg4)); }
public void TestCreateThemeFromPhrases_SecondNull() { MethodDeclarationNode mdn = new MethodDeclarationNode("MyMethod"); PhraseNode pn2 = new PhraseNode(new string[] { "cowboy", "watermelon" }); mdn.CreateThemeFromPhrases(null, pn2); Assert.AreSame(pn2, mdn.Theme); Assert.AreEqual(2, pn2.Size()); Assert.AreEqual("cowboy", pn2[0].Text); Assert.AreEqual("watermelon", pn2[1].Text); }
public void TestToString_EmptyPhrase() { var pn = new PhraseNode(); Assert.AreEqual(string.Empty, pn.ToString()); }
public void TestToString() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] {wn1, wn2, wn3}; PhraseNode pn = new PhraseNode(words, Location.Name, true); string expected = string.Format("{0} {1} {2}", wn1, wn2, wn3); Assert.AreEqual(expected, pn.ToString()); }
public void TestGetPhrase() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] {wn1, wn2, wn3}; PhraseNode pn = new PhraseNode(words, Location.Name, true); var phrase = pn.GetPhrase(); Assert.AreEqual(words.Length, phrase.Count); for(int i = 0; i < phrase.Count; i++) { Assert.AreEqual(pn[i], words[i]); } }
public static bool PhraseNodesAreEqual(PhraseNode pn1, PhraseNode pn2) { if(pn1.Size() != pn2.Size()) { return false; } for(int i = 0; i < pn1.Size(); i++) { if(!WordNodeTests.WordNodesAreEqual(pn1[i], pn2[i])) { return false; } } return true; }
public void TestGetParse() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] {wn1, wn2, wn3}; PhraseNode pn = new PhraseNode(words, Location.Name, true); var parse = pn.GetParse(); Assert.AreEqual(pn, parse); }
public void TestRoundTrip() { var wn1 = new WordNode("Get", PartOfSpeechTag.Verb); var wn2 = new WordNode("Fixed", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Hydro", PartOfSpeechTag.NounModifier); var wn4 = new WordNode("Schedule", PartOfSpeechTag.Noun); var pn = new PhraseNode(new[] { wn1, wn2, wn3, wn4 }, Location.Name, false); Assert.IsTrue(PhraseNodesAreEqual(pn, PhraseNode.Parse(pn.ToString()))); }
public void TestParse() { var wn1 = new WordNode("Eat", PartOfSpeechTag.Verb); var wn2 = new WordNode("More", PartOfSpeechTag.NounModifier); var wn3 = new WordNode("Chicken", PartOfSpeechTag.Noun); var words = new WordNode[] { wn1, wn2, wn3 }; var expected = new PhraseNode(words, Location.Name, false); var actual = PhraseNode.Parse("Eat(Verb) More(NounModifier) Chicken(Noun)"); Assert.IsTrue(PhraseNodesAreEqual(actual, expected)); }