Example #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);
        }
        /// <summary>
        /// Creates events for the provided sample.
        /// </summary>
        /// <param name="sample">The sample the sample for which training <see cref="T:Event"/>s are be created.</param>
        /// <returns>The events enumerator.</returns>
        protected override IEnumerator <Event> CreateEvents(NameSample sample)
        {
            if (sample.ClearAdaptiveData)
            {
                contextGenerator.ClearAdaptiveData();
            }

            var tokens   = new string[sample.Sentence.Length];
            var outcomes = codec.Encode(sample.Names, tokens.Length);

            additionalContextFeatureGenerator.SetCurrentContext(sample.AdditionalContext);

            for (int i = 0; i < sample.Sentence.Length; i++)
            {
                tokens[i] = sample.Sentence[i];
            }

            return(GenerateEvents(tokens, outcomes, contextGenerator).GetEnumerator());
        }