Exemple #1
0
        /// <summary>
        /// Returns the next object. Calling this method repeatedly until it returns,
        /// null will return each object from the underlying source exactly once.
        /// </summary>
        /// <returns>
        /// The next object or null to signal that the stream is exhausted.
        /// </returns>
        public Sequence Read()
        {
            var sample = psi.Read();

            if (sample != null)
            {
                var events = new Event[sample.Sentence.Length];

                for (int i = 0; i < sample.Sentence.Length; i++)
                {
                    // it is safe to pass the tags as previous tags because
                    // the context generator does not look for non predicted tags
                    var tags = seqCodec.Encode(sample.Names, sample.Sentence.Length);


                    var context = pcg.GetContext(
                        i,
                        sample.Sentence,
                        useOutcomes ? tags : null,
                        null);

                    events[i] = new Event(tags[i], context);
                }

                return(new Sequence(events, sample));
            }
            return(null);
        }
        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);
        }
        /// <summary>
        /// Adds name events for the specified sentence.
        /// </summary>
        /// <param name="sentence">
        /// The sentence for which name events should be added.
        /// </param>
        private void AddEvents(string sentence)
        {
            string[]      parts        = sentence.Split(' ');
            string        outcome      = MaximumEntropyNameFinder.Other;
            List <string> tokens       = new List <string>();
            List <string> outcomesList = new List <string>();

            for (int currentPart = 0, partCount = parts.Length; currentPart < partCount; currentPart++)
            {
                if (parts[currentPart] == "<START>")
                {
                    outcome = MaximumEntropyNameFinder.Start;
                }
                else if (parts[currentPart] == "<END>")
                {
                    outcome = MaximumEntropyNameFinder.Other;
                }
                else
                {
                    //regular token
                    tokens.Add(parts[currentPart]);
                    outcomesList.Add(outcome);
                    if (outcome == MaximumEntropyNameFinder.Start)
                    {
                        outcome = MaximumEntropyNameFinder.Continue;
                    }
                }
            }
            mEvents = new SharpEntropy.TrainingEvent[tokens.Count];
            for (int currentToken = 0, tokenCount = tokens.Count; currentToken < tokenCount; currentToken++)
            {
                mEvents[currentToken] = new SharpEntropy.TrainingEvent(outcomesList[currentToken], mContextGenerator.GetContext(currentToken, tokens, outcomesList, mPreviousTags));
            }
            for (int currentToken = 0, tokenCount = tokens.Count; currentToken < tokenCount; currentToken++)
            {
                mPreviousTags[tokens[currentToken]] = outcomesList[currentToken];
            }
        }