public void TestParameterValidation() { Assert.Throws <ArgumentException> (() => { var dummy = new ChunkSample(new[] { string.Empty }, new[] { string.Empty }, new[] { string.Empty, "Nop!" }); Assert.Null(dummy); }); }
public void testNicePrint() { var sample = new ChunkSample(createSentence(), createTags(), createChunks()); Assert.AreEqual(" [NP Forecasts_NNS ] [PP for_IN ] [NP the_DT trade_NN figures_NNS ] " + "[VP range_VBP ] [ADVP widely_RB ] ,_, [NP Forecasts_NNS ] [PP for_IN ] [NP the_DT trade_NN figures_NNS ] " + "[VP range_VBP ] [ADVP widely_RB ] ._.", sample.NicePrint); }
public void TestReadingEvents() { var sample = new StringBuilder(); // First sample sentence sample.Append("word11 tag11 pred11"); sample.Append('\n'); sample.Append("word12 tag12 pred12"); sample.Append('\n'); sample.Append("word13 tag13 pred13"); sample.Append('\n'); // Start next sample sentence sample.Append('\n'); // Second sample sentence sample.Append("word21 tag21 pred21"); sample.Append('\n'); sample.Append("word22 tag22 pred22"); sample.Append('\n'); sample.Append("word23 tag23 pred23"); sample.Append('\n'); var stringStream = new PlainTextByLineStream(new MemoryStream(Encoding.UTF8.GetBytes(sample.ToString()))); var chunkStream = new ChunkSampleStream(stringStream); // read first sample var firstSample = chunkStream.Read(); Assert.AreEqual("word11", firstSample.Sentence[0]); Assert.AreEqual("tag11", firstSample.Tags[0]); Assert.AreEqual("pred11", firstSample.Preds[0]); Assert.AreEqual("word12", firstSample.Sentence[1]); Assert.AreEqual("tag12", firstSample.Tags[1]); Assert.AreEqual("pred12", firstSample.Preds[1]); Assert.AreEqual("word13", firstSample.Sentence[2]); Assert.AreEqual("tag13", firstSample.Tags[2]); Assert.AreEqual("pred13", firstSample.Preds[2]); // read second sample ChunkSample secondSample = chunkStream.Read(); Assert.AreEqual("word21", secondSample.Sentence[0]); Assert.AreEqual("tag21", secondSample.Tags[0]); Assert.AreEqual("pred21", secondSample.Preds[0]); Assert.AreEqual("word22", secondSample.Sentence[1]); Assert.AreEqual("tag22", secondSample.Tags[1]); Assert.AreEqual("pred22", secondSample.Preds[1]); Assert.AreEqual("word23", secondSample.Sentence[2]); Assert.AreEqual("tag23", secondSample.Tags[2]); Assert.AreEqual("pred23", secondSample.Preds[2]); Assert.Null(chunkStream.Read()); }
public void testRetrievingContent() { var s = createSentence(); var t = createTags(); var c = createChunks(); var sample = new ChunkSample(s, t, c); Assert.True(s.SequenceEqual(sample.Sentence)); Assert.True(c.SequenceEqual(sample.Preds)); Assert.True(t.SequenceEqual(sample.Tags)); }
public void testPhraseAsSpan() { var spans = ChunkSample.PhrasesAsSpanList(createSentence(), createTags(), createChunks()); Assert.AreEqual(10, spans.Length); Assert.AreEqual(new Span(0, 1, "NP"), spans[0]); Assert.AreEqual(new Span(1, 2, "PP"), spans[1]); Assert.AreEqual(new Span(2, 5, "NP"), spans[2]); Assert.AreEqual(new Span(5, 6, "VP"), spans[3]); Assert.AreEqual(new Span(6, 7, "ADVP"), spans[4]); Assert.AreEqual(new Span(8, 9, "NP"), spans[5]); Assert.AreEqual(new Span(9, 10, "PP"), spans[6]); Assert.AreEqual(new Span(10, 13, "NP"), spans[7]); Assert.AreEqual(new Span(13, 14, "VP"), spans[8]); Assert.AreEqual(new Span(14, 15, "ADVP"), spans[9]); }
public void testToString() { var s = createSentence(); var t = createTags(); var c = createChunks(); var sample = new ChunkSample(s, t, c); var reader = new StringReader(sample.ToString()); for (var i = 0; i < s.Length; i++) { var line = reader.ReadLine(); var parts = line.Split(' '); Assert.AreEqual(3, parts.Length); Assert.AreEqual(s[i], parts[0]); Assert.AreEqual(t[i], parts[1]); Assert.AreEqual(c[i], parts[2]); } }
/// <summary> /// Generates chunk tags for the given sequence returning the result in an array. /// </summary> /// <param name="tokens">an array of the tokens or words of the sequence.</param> /// <param name="tags">an array of the pos tags of the sequence.</param> /// <returns>an array of chunk tags for each token in the sequence.</returns> public string[] Chunk(string[] tokens, string[] tags) { ChunkSample predsSample = mSampleStream.Read(); // checks if the streams are sync for (int i = 0; i < tokens.Length; i++) { if (!tokens[i].Equals(predsSample.Sentence[i]) || !tags[i].Equals(predsSample.Tags[i])) { throw new ApplicationException("The streams are not sync!" + "\n expected sentence: " + tokens.ToDisplay() + "\n expected tags: " + tags.ToDisplay() + "\n predicted sentence: " + predsSample.Sentence.ToArray().ToDisplay() + "\n predicted tags: " + predsSample.Tags.ToArray().ToDisplay()); } } return(predsSample.Preds.ToArray()); }
public void testParameterValidation() { var dummy = new ChunkSample(new[] { string.Empty }, new[] { string.Empty }, new[] { string.Empty, "Nop!" }); Assert.Null(dummy); }
public void testInvalidPhraseAsSpan3() { ChunkSample.PhrasesAsSpanList(new string[1], new string[1], new string[2]); }
public void testToString() { var s = createSentence(); var t = createTags(); var c = createChunks(); var sample = new ChunkSample(s, t, c); var reader = new StringReader(sample.ToString()); for (var i = 0; i < s.Length; i++) { var line = reader.ReadLine(); var parts = line.Split(' '); Assert.AreEqual(3, parts.Length); Assert.AreEqual(s[i], parts[0]); Assert.AreEqual(t[i], parts[1]); Assert.AreEqual(c[i], parts[2]); } }
public void testRetrievingContent() { var s = createSentence(); var t = createTags(); var c = createChunks(); var sample = new ChunkSample(s, t, c); Assert.True(s.SequenceEqual(sample.Sentence)); Assert.True(c.SequenceEqual(sample.Preds)); Assert.True(t.SequenceEqual(sample.Tags)); }
public void testParameterValidation() { var dummy = new ChunkSample(new[] {string.Empty}, new[] {string.Empty}, new[] {string.Empty, "Nop!"}); Assert.Null(dummy); }
public void testNicePrint() { var sample = new ChunkSample(createSentence(), createTags(), createChunks()); Assert.AreEqual(" [NP Forecasts_NNS ] [PP for_IN ] [NP the_DT trade_NN figures_NNS ] " + "[VP range_VBP ] [ADVP widely_RB ] ,_, [NP Forecasts_NNS ] [PP for_IN ] [NP the_DT trade_NN figures_NNS ] " + "[VP range_VBP ] [ADVP widely_RB ] ._.", sample.NicePrint); }
public void testAsSpan() { var sample = new ChunkSample(createSentence(), createTags(), createChunks()); var spans = sample.GetPhrasesAsSpanList(); Assert.AreEqual(10, spans.Length); Assert.AreEqual(new Span(0, 1, "NP"), spans[0]); Assert.AreEqual(new Span(1, 2, "PP"), spans[1]); Assert.AreEqual(new Span(2, 5, "NP"), spans[2]); Assert.AreEqual(new Span(5, 6, "VP"), spans[3]); Assert.AreEqual(new Span(6, 7, "ADVP"), spans[4]); Assert.AreEqual(new Span(8, 9, "NP"), spans[5]); Assert.AreEqual(new Span(9, 10, "PP"), spans[6]); Assert.AreEqual(new Span(10, 13, "NP"), spans[7]); Assert.AreEqual(new Span(13, 14, "VP"), spans[8]); Assert.AreEqual(new Span(14, 15, "ADVP"), spans[9]); }
public void TestInvalidPhraseAsSpan3() { Assert.Throws <ArgumentException> (() => { ChunkSample.PhrasesAsSpanList(new string[1], new string[1], new string[2]); }); }