示例#1
0
        bool TestOutput(List <string> sentence, MakeSentenceOptions options)
        {
            if (string.IsNullOrEmpty(SourceText))
            {
                return(true);
            }

            var overlapMax = Math.Min(
                options.MaxOverlapWords,
                (int)Math.Round(options.MaxOverlapRatio * sentence.Count));

            var sequenceCount  = Math.Max(sentence.Count - overlapMax, 1);
            var sequenceLength = Math.Min(sentence.Count, overlapMax);

            for (var i = 0; i < sequenceCount; i++)
            {
                var sequence = string.Join(" ", sentence.GetRange(i, sequenceLength));
                if (SourceText.IndexOf(sequence, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public string?MakeSentence(MakeSentenceOptions options)
        {
            for (var i = 0; i < options.Tries; i++)
            {
                List <string> sentence = Chain.GenerateSentence();
                if (options.MaxWords.HasValue && sentence.Count > options.MaxWords)
                {
                    continue;
                }

                if (!options.TestOutput || TestOutput(sentence, options))
                {
                    return(string.Join(" ", sentence));
                }
            }

            return(null);
        }