Exemple #1
0
        /// <summary>
        /// Generates chunk tags for the given sequence returning the result in an array.
        /// </summary>
        /// <param name="tokens">an array of the tokens or words of the sequence.</param>
        /// <param name="tags">an array of the pos tags of the sequence.</param>
        /// <returns>An array of chunk tags for each token in the sequence or a <c>null</c> value if none.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="tokens"/> is null.
        /// or
        /// The <paramref name="tags"/> is null.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">The token array is empty.</exception>
        public string[] Chunk(string[] tokens, string[] tags)
        {
            if (tokens == null)
            {
                throw new ArgumentNullException("tokens");
            }

            if (tokens.Length == 0)
            {
                throw new ArgumentOutOfRangeException("tokens", "The token array is empty.");
            }

            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }

            bestSequence = model.BestSequence(tokens, new object[] { tags }, contextGenerator, sequenceValidator);

            return(bestSequence == null ? null : bestSequence.Outcomes.ToArray());
        }
        /// <summary>
        /// Returns the lemma of the specified word with the specified part-of-speech.
        /// </summary>
        /// <param name="tokens">An array of the tokens.</param>
        /// <param name="tags">An array of the POS tags.</param>
        /// <returns>An array of lemma classes for each token in the sequence.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tokens" /> or <paramref name="tags" /></exception>
        /// <exception cref="ArgumentException">The arguments must have the same length.</exception>
        public string[] Lemmatize(string[] tokens, string[] tags)
        {
            if (tokens == null)
            {
                throw new ArgumentNullException(nameof(tokens));
            }

            if (tags == null)
            {
                throw new ArgumentNullException(nameof(tags));
            }

            if (tokens.Length != tags.Length)
            {
                throw new ArgumentException("The arguments must have the same length.");
            }

            bestSequence = model.BestSequence(tokens, new object[] { tags }, contextGenerator, sequenceValidator);

            return(bestSequence.Outcomes.ToArray());
        }
        /// <summary>
        /// Generates name tags for the given sequence, typically a sentence, returning token spans for any identified names.
        /// </summary>
        /// <param name="tokens">An array of the tokens or words of the sequence, typically a sentence.</param>
        /// <param name="additionalContext">Features which are based on context outside of the sentence but which should also be used.</param>
        /// <returns>An array of spans for each of the names identified.</returns>
        public Span[] Find(string[] tokens, string[][] additionalContext)
        {
            additionalContextFeatureGenerator.SetCurrentContext(additionalContext);

            bestSequence = model.BestSequence(tokens,
                                              Array.ConvertAll(additionalContext, input => (object)input),
                                              contextGenerator,
                                              sequenceValidator);

            var outcomes = bestSequence.Outcomes.ToArray();

            contextGenerator.UpdateAdaptiveData(tokens, outcomes);

            var spans = sequenceCodec.Decode(outcomes);

            var probs = Probs(spans);

            for (var i = 0; i < probs.Length; i++)
            {
                spans[i].Probability = probs[i];
            }

            return(spans);
        }
Exemple #4
0
        /// <summary>
        /// Generates chunk tags for the given sequence returning the result in an array.
        /// </summary>
        /// <param name="tokens">an array of the tokens or words of the sequence.</param>
        /// <param name="tags">an array of the pos tags of the sequence.</param>
        /// <returns>an array of chunk tags for each token in the sequence.</returns>
        public string[] Chunk(string[] tokens, string[] tags)
        {
            bestSequence = model.BestSequence(tokens, new object[] { tags }, contextGenerator, sequenceValidator);

            return(bestSequence.Outcomes.ToArray());
        }
Exemple #5
0
 /// <summary>
 /// Assigns the sentence of tokens pos tags.
 /// </summary>
 /// <param name="sentence">The sentence of tokens to be tagged.</param>
 /// <param name="additionalContext">Any addition context specific to a class implementing this interface.</param>
 /// <returns>an array of pos tags for each token provided in sentence.</returns>
 public string[] Tag(string[] sentence, object[] additionalContext)
 {
     bestSequence = model.BestSequence(sentence, additionalContext, ContextGenerator, SequenceValidator);
     return(bestSequence.Outcomes.ToArray());
 }