예제 #1
0
        private void AddTagEvents(List <Event> tagEvents, Parse[] chunks)
        {
            var toks  = new List <string>();
            var preds = new List <string>();

            for (int ci = 0, cl = chunks.Length; ci < cl; ci++)
            {
                var c = chunks[ci];
                if (c.IsPosTag)
                {
                    toks.Add(c.CoveredText);
                    preds.Add(c.Type);
                }
                else
                {
                    var kids = c.Children;
                    for (int ti = 0, tl = kids.Length; ti < tl; ti++)
                    {
                        var tok = kids[ti];
                        toks.Add(tok.CoveredText);
                        preds.Add(tok.Type);
                    }
                }
            }
            for (int ti = 0, tl = toks.Count; ti < tl; ti++)
            {
                tagEvents.Add(
                    new Event(
                        preds[ti],
                        posContextGenerator.GetContext(ti, toks.ToArray(), preds.ToArray(), null)));
            }
        }
예제 #2
0
        internal static List <Event> GenerateEvents(string[] sentence, string[] tags, object[] additionalContext,
                                                    IPOSContextGenerator cg)
        {
            var events = new List <Event>();

            for (var i = 0; i < 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 context = cg.GetContext(i, sentence, tags, additionalContext);

                events.Add(new Event(tags[i], context));
            }
            return(events);
        }
예제 #3
0
        /// <summary>
        /// Returns the next <see cref="Sequence"/>. Calling this method repeatedly until it returns,
        /// null will return each object from the underlying source exactly once.
        /// </summary>
        /// <returns>
        /// The next <see cref="Sequence"/> or null to signal that the stream is exhausted.
        /// </returns>
        public Sequence Read()
        {
            var sample = objectStream.Read();

            if (sample != null)
            {
                var events = new Event[sample.Sentence.Length];
                for (var i = 0; i < events.Length; i++)
                {
                    events[i] = new Event(sample.Tags[i],
                                          contextGenerator.GetContext(i, sample.Sentence, sample.Tags, null));
                }
                return(new Sequence(events, sample));
            }

            return(null);
        }