/// <summary> /// Create a NameSample from scratch and validate it. /// </summary> /// <param name="useTypes">if set to <c>true</c> use nametypes.</param> /// <returns>NameSample.</returns> private static NameSample CreateSimpleNameSample(bool useTypes) { var sentence = new[] { "U", ".", "S", ".", "President", "Barack", "Obama", "is", "considering", "sending", "additional", "American", "forces", "to", "Afghanistan", "." }; Span[] names = { new Span(0, 4, "Location"), new Span(5, 7, "Person"), new Span(14, 15, "Location") }; NameSample nameSample; if (useTypes) { nameSample = new NameSample(sentence, names, false); } else { var namesWithoutType = new Span[names.Length]; for (var i = 0; i < names.Length; i++) { namesWithoutType[i] = new Span(names[i].Start, names[i].End); } nameSample = new NameSample(sentence, namesWithoutType, false); } return nameSample; }
public void TestOutcomesForSingleTypeSentence() { var sentence = new[] { "Elise", "Wendel", "appreciated", "the", "hint", "and", "enjoyed", "a", "delicious", "traditional", "meal", "." }; var nameSample = new NameSample(sentence, new[] {new Span(0, 2, "person")}, false); var eventStream = new NameFinderEventStream(new CollectionObjectStream<NameSample>(nameSample)); Assert.AreEqual("person-" + NameFinderME.START, eventStream.Read().Outcome); Assert.AreEqual("person-" + NameFinderME.Continue, eventStream.Read().Outcome); for (int i = 0; i < 10; i++) { Assert.AreEqual(NameFinderME.Other, eventStream.Read().Outcome); } Assert.Null(eventStream.Read()); }
/// <summary> /// Determines whether the specified <see cref="T:NameSample"/> is equal to the current <see cref="T:NameSample"/>. /// </summary> /// <returns> /// true if the specified object is equal to the current object; otherwise, false. /// </returns> /// <param name="other">The other <see cref="NameSample"/> to compare with the current object. </param> protected bool Equals(NameSample other) { if (other == null) { return(false); } return(Sentence.SequenceEqual(other.Sentence) && Names.SequenceEqual(other.Names) && AdditionalContext.SequenceEqual(other.AdditionalContext) && ClearAdaptiveData == other.ClearAdaptiveData); }
public void TestNameAtEnd() { var sentence = new[] { "My", "name", "is", "Anna" }; var sample = new NameSample(sentence, new[] {new Span(3, 4)}, false); Assert.AreEqual("My name is <START> Anna <END>", sample.ToString()); }
/// <summary> /// Determines whether the specified <see cref="T:NameSample"/> is equal to the current <see cref="T:NameSample"/>. /// </summary> /// <returns> /// true if the specified object is equal to the current object; otherwise, false. /// </returns> /// <param name="other">The other <see cref="NameSample"/> to compare with the current object. </param> protected bool Equals(NameSample other) { if (other == null) return false; return Sentence.SequenceEqual(other.Sentence) && Names.SequenceEqual(other.Names) && AdditionalContext.SequenceEqual(other.AdditionalContext) && ClearAdaptiveData == other.ClearAdaptiveData; }