Пример #1
0
        /// <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);
        }
Пример #2
0
        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));
        }
        public static IList <CoreLabel> ToCoreLabelList(IList <string> words)
        {
            IList <CoreLabel> tokens = new List <CoreLabel>(words.Count);

            foreach (string word in words)
            {
                CoreLabel cl = new CoreLabel();
                cl.SetWord(word);
                tokens.Add(cl);
            }
            return(tokens);
        }
        public static IList <CoreLabel> ToCoreLabelList(params string[] words)
        {
            IList <CoreLabel> tokens = new List <CoreLabel>(words.Length);

            foreach (string word in words)
            {
                CoreLabel cl = new CoreLabel();
                cl.SetWord(word);
                tokens.Add(cl);
            }
            return(tokens);
        }
Пример #5
0
        /// <summary>
        /// Create a sentence as a List of
        /// <c>CoreLabel</c>
        /// objects from
        /// an array (or varargs) of String objects.
        /// </summary>
        /// <param name="words">The words to make it from</param>
        /// <returns>The Sentence</returns>
        public static IList <CoreLabel> ToCoreLabelList(params string[] words)
        {
            IList <CoreLabel> sent = new List <CoreLabel>(words.Length);

            foreach (string word in words)
            {
                CoreLabel cl = new CoreLabel();
                cl.SetValue(word);
                cl.SetWord(word);
                sent.Add(cl);
            }
            return(sent);
        }
Пример #6
0
        public static IList <IHasWord> ToWordList(params string[] words)
        {
            IList <IHasWord> sent = new List <IHasWord>();

            foreach (string word in words)
            {
                CoreLabel cl = new CoreLabel();
                cl.SetValue(word);
                cl.SetWord(word);
                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);
        }
Пример #8
0
 /// <summary>
 /// Copy Constructor - relies on
 /// <see cref="CoreLabel"/>
 /// copy constructor
 /// It will set the value, and if the word is not set otherwise, set
 /// the word to the value.
 /// </summary>
 /// <param name="w">A Label to initialize this IndexedWord from</param>
 public IndexedWord(ILabel w)
 {
     if (w is CoreLabel)
     {
         this.label = (CoreLabel)w;
     }
     else
     {
         label = new CoreLabel(w);
         if (label.Word() == null)
         {
             label.SetWord(label.Value());
         }
     }
 }
        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);
     }
 }
Пример #11
0
 public virtual void SetWord(string word)
 {
     label.SetWord(word);
 }