}//replaceSynonyms(string input, Dictionary<string, Synonym> synonymGroups)

        public static string ReplaceOutputSynonyms(string text, Dictionary <string, Synonym> synonyms)
        {
            int start = text.IndexOf("(");
            int end;

            while (start != -1)
            {
                if (!TextToolbox.IsEscaped(text, start))
                {
                    end = TextToolbox.FindNextMatchingChar(text, start);
                    if (end != -1)
                    {
                        string synonymName = text.Substring(start + 1, end - start - 1).Trim().ToLower();
                        if (synonyms.ContainsKey(synonymName) && !TextToolbox.IsInCommand(text, start, end - start))
                        {
                            Synonym syn = ((Synonym)synonyms[synonymName]);
                            if (syn.Phrases.Count > 0)
                            {
                                Random rand = new Random();
                                int    pick = rand.Next(syn.Phrases.Count);
                                if (end == text.Length - 1)                               //the end is the end
                                {
                                    text = text.Substring(0, start) + ((Phrase)syn.Phrases[pick]).Text;
                                }
                                else
                                {
                                    text = text.Substring(0, start) + ((Phrase)syn.Phrases[pick]).Text + text.Substring(end + 1);
                                }
                            }
                            else
                            {
                                text = text.Substring(0, start + 1) + synonymName + text.Substring(end);
                            }
                        }
                        start = text.IndexOf("(", start + 1);
                    }
                    else
                    {
                        //TODO: log an error somewhere?
                        return(text);
                    }
                }
                else                 //it's escaped \(..
                {
                    //remove the '\'
                    text = text.Remove(start - 1, 1);
                    //find the next start
                    if (start >= text.Length - 1)                   //the old start is now at the end
                    {
                        start = -1;
                    }
                    else
                    {
                        start = text.IndexOf("(", start);
                    }
                }
            }            //while
            return(text);
        }//replaceSynonyms(string input, Dictionary<string, Synonym> synonymGroups)
        /*
         * Modifier Methods
         */

        public string AddSynonym(string synonymName)
        {
            Synonym synonymNew = new Synonym();

            synonymNew.Id   = GetNewSynoymId();
            synonymNew.Name = synonymName;
            this.Synonyms.Add(synonymNew);
            return(synonymNew.Id);
        }
Esempio n. 3
0
 /*
  * Modifier Methods
  */
 public string AddSynonym(string synonymName)
 {
     Synonym synonymNew = new Synonym();
     synonymNew.Id = GetNewSynoymId();
     synonymNew.Name = synonymName;
     this.Synonyms.Add(synonymNew);
     return synonymNew.Id;
 }