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); } }
/// <summary> /// Default constructor; uses /// <see cref="CoreLabel"/> /// default constructor /// </summary> public IndexedWord() { // = 0; label = new CoreLabel(); }
/// <summary>Construct an IndexedWord from a CoreLabel just as for a CoreMap.</summary> /// <remarks> /// Construct an IndexedWord from a CoreLabel just as for a CoreMap. /// <i>Implementation note:</i> this is a the same as the constructor /// that takes a CoreMap, but is needed to ensure unique most specific /// type inference for selecting a constructor at compile-time. /// </remarks> /// <param name="w">A Label to initialize this IndexedWord from</param> public IndexedWord(CoreLabel w) { label = w; }
public static string WordToString <T>(T o, bool justValue, string separator) { if (justValue && o is ILabel) { if (o is CoreLabel) { CoreLabel l = (CoreLabel)o; string w = l.Value(); if (w == null) { w = l.Word(); } return(w); } else { return(((ILabel)o).Value()); } } else { if (o is CoreLabel) { CoreLabel l = ((CoreLabel)o); string w = l.Value(); if (w == null) { w = l.Word(); } if (l.Tag() != null) { if (separator == null) { return(w + CoreLabel.TagSeparator + l.Tag()); } else { return(w + separator + l.Tag()); } } return(w); } else { // an interface that covered these next four cases would be // nice, but we're moving away from these data types anyway if (separator != null && o is TaggedWord) { return(((TaggedWord)o).ToString(separator)); } else { if (separator != null && o is LabeledWord) { return(((LabeledWord)o).ToString(separator)); } else { if (separator != null && o is WordLemmaTag) { return(((WordLemmaTag)o).ToString(separator)); } else { if (separator != null && o is WordTag) { return(((WordTag)o).ToString(separator)); } else { return(o.ToString()); } } } } } } }
/// <summary><inheritDoc/></summary> public virtual ILabelFactory LabelFactory() { return(CoreLabel.Factory()); }