public virtual void TestCoreLabelListToString() { IList <CoreLabel> clWords = new List <CoreLabel>(); IList <CoreLabel> clValues = new List <CoreLabel>(); IList <CoreLabel> clWordTags = new List <CoreLabel>(); IList <CoreLabel> clValueTags = new List <CoreLabel>(); for (int i = 0; i < words.Length; ++i) { CoreLabel cl = new CoreLabel(); cl.SetWord(words[i]); clWords.Add(cl); cl = new CoreLabel(); cl.SetValue(words[i]); clValues.Add(cl); cl = new CoreLabel(); cl.SetWord(words[i]); cl.SetTag(tags[i]); clWordTags.Add(cl); cl = new CoreLabel(); cl.SetValue(words[i]); cl.SetTag(tags[i]); clValueTags.Add(cl); } NUnit.Framework.Assert.AreEqual(expectedValueOnly, SentenceUtils.ListToString(clWords, true)); NUnit.Framework.Assert.AreEqual(expectedValueOnly, SentenceUtils.ListToString(clValues, true)); NUnit.Framework.Assert.AreEqual(expectedTagged, SentenceUtils.ListToString(clWordTags, false, separator)); NUnit.Framework.Assert.AreEqual(expectedTagged, SentenceUtils.ListToString(clValueTags, false, separator)); }
/// <summary> /// Create a sentence as a List of /// <c>CoreLabel</c> /// objects from /// a List of other label objects. /// </summary> /// <param name="words">The words to make it from</param> /// <returns>The Sentence</returns> public static IList <CoreLabel> ToCoreLabelList <_T0>(IList <_T0> words) where _T0 : IHasWord { IList <CoreLabel> sent = new List <CoreLabel>(words.Count); foreach (IHasWord word in words) { CoreLabel cl = new CoreLabel(); if (word is ILabel) { cl.SetValue(((ILabel)word).Value()); } cl.SetWord(word.Word()); if (word is IHasTag) { cl.SetTag(((IHasTag)word).Tag()); } if (word is IHasLemma) { cl.SetLemma(((IHasLemma)word).Lemma()); } sent.Add(cl); } return(sent); }
public static IList <CoreLabel> ToCoreLabelList(string[] words, string[] tags) { System.Diagnostics.Debug.Assert(tags.Length == words.Length); IList <CoreLabel> tokens = new List <CoreLabel>(words.Length); for (int i = 0; i < sz; i++) { CoreLabel cl = new CoreLabel(); cl.SetWord(words[i]); cl.SetTag(tags[i]); tokens.Add(cl); } return(tokens); }
public static IList <CoreLabel> ToCoreLabelListWithCharacterOffsets(string[] words, string[] tags) { System.Diagnostics.Debug.Assert(tags.Length == words.Length); IList <CoreLabel> tokens = new List <CoreLabel>(words.Length); int offset = 0; for (int i = 0; i < sz; i++) { CoreLabel cl = new CoreLabel(); cl.SetWord(words[i]); cl.SetTag(tags[i]); cl.Set(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation), offset); offset += words[i].Length; cl.Set(typeof(CoreAnnotations.CharacterOffsetEndAnnotation), offset); offset++; // assume one space between words :-) tokens.Add(cl); } return(tokens); }
public virtual ILabel NewLabel(ILabel oldLabel) { if (oldLabel is CoreLabel) { return(new CoreLabel((CoreLabel)oldLabel)); } else { //Map the old interfaces to the correct key/value pairs //Don't need to worry about HasIndex, which doesn't appear in any legacy code CoreLabel label = new CoreLabel(); if (oldLabel is IHasWord) { label.SetWord(((IHasWord)oldLabel).Word()); } if (oldLabel is IHasTag) { label.SetTag(((IHasTag)oldLabel).Tag()); } if (oldLabel is IHasOffset) { label.SetBeginPosition(((IHasOffset)oldLabel).BeginPosition()); label.SetEndPosition(((IHasOffset)oldLabel).EndPosition()); } if (oldLabel is IHasCategory) { label.SetCategory(((IHasCategory)oldLabel).Category()); } if (oldLabel is IHasIndex) { label.SetIndex(((IHasIndex)oldLabel).Index()); } label.SetValue(oldLabel.Value()); return(label); } }
public virtual void SetTag(string tag) { label.SetTag(tag); }