internal static List <Event> GenerateEvents(String[] sentence, String[] outcomes, INameContextGenerator cg)
        {
            var events = new List <Event>(outcomes.Length);

            for (int i = 0; i < outcomes.Length; i++)
            {
                events.Add(new Event(outcomes[i], cg.GetContext(i, sentence, outcomes, null)));
            }
            cg.UpdateAdaptiveData(sentence, outcomes);
            return(events);
        }
Ejemplo n.º 2
0
        /// <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);
        }