Beispiel #1
0
 private static void LoadWord(AIMLData parent, List<string> pattern, string template)
 {
     var key = pattern[0].ToUpper().Trim();
     pattern.RemoveAt(0);
     if (!parent.Data.ContainsKey(key))
         parent.Data.Add(key, new AIMLData(parent, key));
     if (pattern.Count > 0)
         LoadWord(parent.Data[key], pattern, template);
     else
         parent.Data[key].Template = template;
 }
Beispiel #2
0
 public AIMLData(AIMLData parent, string key)
 {
     Parent = parent;
     Key = key;
     Data = new Dictionary<string, AIMLData>();
 }
Beispiel #3
0
 private static PatternData FindTemplateRecursive(AIMLData ai, List<string> text,
     PatternData data, int searchPos)
 {
     var key = text[searchPos];
     if (data.IsInWildcard && searchPos < text.Count - 1 && !ai.Data.ContainsKey("_") &&
         !ai.Data.ContainsKey(key.ToUpper()) && !ai.Data.ContainsKey("*"))
     {
         data.WildTexts[data.WildTexts.Count - 1].WildText += key + " ";
         return FindTemplateRecursive(ai, text, data, searchPos + 1);
     }
     if (ai.Data.ContainsKey("_"))
     {
         if (searchPos == text.Count - 1)
         {
             data.IsAnswer = true;
             data.Template = ai.Data["_"].Template;
             return data;
         }
         data.WildTexts.Add(new WildData { WildText = key + " ", WildType = data.WildType });
         data.IsInWildcard = true;
         data = FindTemplateRecursive(ai.Data["_"], text, data, searchPos + 1);
         if (data.IsAnswer)
             return data;
         data.WildTexts.RemoveAt(data.WildTexts.Count - 1);
         data.WildType = data.WildTexts.Count == 0 ? StarType.Pattern :
             data.WildTexts[data.WildTexts.Count - 1].WildType;
     }
     if (ai.Data.ContainsKey(key.ToUpper()))
     {
         if (searchPos == text.Count - 1)
         {
             data.IsAnswer = true;
             data.Template = ai.Data[key.ToUpper()].Template;
             return data;
         }
         if (key.ToUpper() == "<THAT>")
             data.WildType = StarType.That;
         if (key.ToUpper() == "<TOPIC>")
             data.WildType = StarType.Topic;
         data.IsInWildcard = false;
         data = FindTemplateRecursive(ai.Data[key.ToUpper()], text, data, searchPos + 1);
         if (data.IsAnswer)
             return data;
     }
     if (!data.IsAnswer && ai.Data.ContainsKey("*"))
     {
         if (searchPos == text.Count - 1)
         {
             data.IsAnswer = true;
             data.Template = ai.Data["*"].Template;
             return data;
         }
         data.WildTexts.Add(new WildData { WildText = key + " ", WildType = data.WildType });
         data.IsInWildcard = true;
         data = FindTemplateRecursive(ai.Data["*"], text, data, searchPos + 1);
         if (data.IsAnswer)
             return data;
         data.WildTexts.RemoveAt(data.WildTexts.Count - 1);
         data.WildType = data.WildTexts.Count == 0 ? StarType.Pattern :
             data.WildTexts[data.WildTexts.Count - 1].WildType;
     }
     return data;
 }