Beispiel #1
0
        /// TODO this method doesn't need two for-loops
        /// <summary>
        /// This method is used by <c>TextChain</c>.
        /// Identical to the parameterless <c>NextOutput()</c> except it
        /// takes a Dictionary of TextEntities to supplement this template's
        /// TextEntities (generation pulls from both pools of entities). This is useful
        /// when "globally" defining TextEntities across multiple templates.
        /// This method also takes a Dictionary representing previously generated
        /// values. This is useful when the first output of a TextEntity must be
        /// used across multiple templates.
        /// </summary>
        ///

        public TextOutput NextOutput(Dictionary <string, ITextGenerator> supplementaryEntities, Dictionary <string, string> overrideValues)
        {
            var result = new StringBuilder(this.Template);
            var output = new TextOutput();

            foreach (var m in Regex.Matches(result.ToString(), @"({[^}]+})"))
            {
                var bracketedKey = m.ToString();
                var key          = bracketedKey.RemoveCurlyBrackets();

                if (overrideValues != null && overrideValues.ContainsKey(key))
                {
                    result.Replace("{" + key + "}", overrideValues[key]);
                    output.TextEntityOutput[key] = overrideValues[key];
                }
                else if (this.EntityDefinitions.ContainsKey(key))
                {
                    var e = this.EntityDefinitions[key].NextOutput();
                    result.Replace("{" + key + "}", e.Value);
                    output.Context.AddRange(e.Context);
                    output.TextEntityOutput[key] = e.Value;
                }
                else if (supplementaryEntities.ContainsKey(key))
                {
                    var s = supplementaryEntities[key].NextOutput();
                    result.Replace("{" + key + "}", s.Value);
                    output.Context.AddRange(s.Context);
                    output.TextEntityOutput[key] = s.Value;
                }
            }

            output.Value = result.ToString().Trim();

            // Are there are context clues in the template?
            if (output.Value.HasContextClues())
            {
                output.Context.AddRange(output.Value.GetContextClues());
                output.Value = output.Value.RemoveSquareBrackets();
            }

            if (this.EnableCapitalization)
            {
                output.Value = output.Value.Substring(0, 1).ToUpper() + output.Value.Substring(1);
            }

            return(output);
        }
Beispiel #2
0
        public TextOutput NextOutput()
        {
            var result  = new TextOutput();
            var builder = new StringBuilder();

            if (this.Determiners.Count > 0)
            {
                //builder.Append(this.Determiners[this.Random.Next(this.Determiners.Count)] + " ");
                builder.Append(this.Determiners.GetRandom <string>() + " ");
            }

            if (this.Adjectives.Count > 0)
            {
                //builder.Append(this.Adjectives[this.Random.Next(this.Adjectives.Count)] + " ");
                builder.Append(this.Adjectives.GetRandom <string>() + " ");
            }

            if (this.NameGenerator != null)
            {
                if (Chance.Roll(0.50))
                {
                    builder.Append(this.NameGenerator.Next() + " ");
                    builder.Append(this.Value);
                }
                else
                {
                    builder.Append(this.Value);
                    builder.Append(" of " + this.NameGenerator.Next());
                }
            }
            else
            {
                builder.Append(this.Value);
            }



            return(new TextOutput(builder.ToString().Trim()));
        }
Beispiel #3
0
        public TextOutput NextOutput()
        {
            var builder = new StringBuilder();
            var result  = new TextOutput();
            var context = new List <string>();


            if (this.Entities.Count > 0)
            {
                var o = this.Entities.GetRandom <TextEntity>().Next();

                if (o.HasContextClues())
                {
                    context.AddRange(o.GetContextClues());
                    o = o.RemoveSquareBrackets();
                }

                builder.Append(" ");
                builder.Append(o);
            }

            /*
             * if (this.Adjectives.Count > 0)
             * {
             *
             *  var adjective = this.Adjectives.GetRandom();
             *
             *  if (adjective.HasContextClues())
             *  {
             *      context.AddRange(adjective.GetContextClues());
             *      adjective = adjective.RemoveSquareBrackets();
             *  }
             *
             *  result.Insert(0, adjective);
             *  result.Insert(0, " ");
             * }
             *
             * if (this.Determiners.Count > 0)
             * {
             *
             *  var determiner = this.Determiners.GetRandom();
             *
             *  if (determiner.HasContextClues())
             *  {
             *      context.AddRange(determiner.GetContextClues());
             *      determiner = determiner.RemoveSquareBrackets();
             *  }
             *
             *  if (determiner == "a" && result.ToString().Trim().StartsWithVowel())
             *  {
             *      determiner = "an";
             *  }
             *  else if (determiner == "an" && !result.ToString().Trim().StartsWithVowel())
             *  {
             *      determiner = "a";
             *  }
             *
             *  result.Insert(0, determiner);
             *  result.Insert(0, " ");
             * }
             * /**/

            result.Value = builder.ToString().Trim();
            result.Context.AddRange(context);
            return(result);
        }