/// <summary> /// Ergänzt die Wissensbasis anhand einer Datenbank. /// </summary> /// <param name="strFile">Die Datei, welche die Datenbank enthält.</param> public static void LoadKnowledgeBaseFromFile(string strFile) { try { XmlDocument doc = new XmlDocument(); doc.Load(strFile); XmlNode root = doc.DocumentElement; if (root?.Name != "knowledgebase") { return; } XmlNode xmlRules = root.SelectSingleNode("nodes"); if (xmlRules == null || !xmlRules.HasChildNodes || !(xmlRules.SelectNodes("node") is XmlNodeList listTokens)) { return; } foreach (XmlNode node in listTokens) { XmlNode xmlType = node.SelectSingleNode("type"); XmlNode xmlValue = node.SelectSingleNode("value"); XmlNode xmlIsDynamicValue = node.SelectSingleNode("dynamicvalue"); XmlNode xmlChildren = node.SelectSingleNode("children"); XmlNode xmlChildrenCount = xmlChildren?.SelectSingleNode("count"); if (xmlType != null && xmlValue != null && xmlIsDynamicValue != null && xmlChildrenCount != null && Enum.TryParse(typeof(TokenType), xmlType.InnerText, out object tt) && bool.TryParse(xmlIsDynamicValue.InnerText, out bool bDnamic) && int.TryParse(xmlChildrenCount.InnerText, out int iChildrenCount)) { NodeFactory.AddTemplate(new NodeTemplate((TokenType)tt, xmlValue.InnerText, bDnamic, iChildrenCount)); } else { Console.WriteLine($"Invalid knowledge base entry: {node.InnerXml}"); } } } catch (Exception e) { Console.WriteLine(e); } }