Example #1
0
            public ILabel NewLabel(string labelStr)
            {
                CoreLabel coreLabel = new CoreLabel();

                coreLabel.SetValue(labelStr);
                return(new Edu.Stanford.Nlp.Ling.IndexedWord(coreLabel));
            }
Example #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));
        }
Example #3
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);
        }
            public virtual ILabel NewLabel(string labelStr)
            {
                CoreLabel label = new CoreLabel();

                label.SetValue(labelStr);
                return(label);
            }
Example #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);
        }
Example #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 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);
     }
 }
Example #8
0
 public virtual void SetValue(string value)
 {
     label.SetValue(value);
 }