Beispiel #1
0
        // ***
        // -------------------------------
        // Methods for building sentences.
        // -------------------------------
        // ***


        public IEnumerable <Sentence> BuildSentences(IEnumerable <string> seeds, string source)
        {
            if (seeds == null)
            {
                throw new ArgumentNullException(nameof(seeds));
            }

            using (var buildVectors = new BuilderVectors(conn, source))
            {
                foreach (string seed in seeds)
                {
                    if (string.IsNullOrEmpty(seed))
                    {
                        continue;
                    }

                    buildVectors.PrepareSeedSql(seed);

                    foreach (var sentence in Builder(buildVectors))
                    {
                        yield return(sentence);
                    }
                }
            }
        }
Beispiel #2
0
        public IEnumerable <Sentence> BuildRandomSentences(string source)
        {
            using (var buildVectors = new BuilderVectors(conn, source))
            {
                buildVectors.PrepareRandomSql();

                foreach (var sentence in Builder(buildVectors))
                {
                    yield return(sentence);
                }
            }
        }
Beispiel #3
0
        IEnumerable <Sentence> Builder(BuilderVectors v)
        {
            // Copies out the volatile field, so we have a consistent MaxWords while building.
            var words = new SentenceConstruct(Order, MaxWords);

            using (var reader = v.StartingChains.ExecuteReader())
            {
                while (reader.Read())
                {
                    string backward = reader.GetString(0);
                    string chain    = reader.GetString(1);
                    string forward  = reader.GetString(2);

                    words.Set(chain);

                    if (backward != string.Empty)
                    {
                        // Backward search.
                        words.PrependMode();
                        words.ModeAdd(backward);
                        CollectChains(words, v.BackwardSearch);
                    }

                    if (forward != string.Empty && words.Continue)
                    {
                        // Forward search.
                        words.AppendMode();
                        words.ModeAdd(forward);
                        CollectChains(words, v.ForwardSearch);
                    }

                    var    segment    = words.CurrentSegment();
                    long[] wordCounts = WordCount(segment, v.WordCount);

                    yield return(new Sentence(segment, wordCounts));
                }
            }
        }