/// <summary> /// defaukt ctor /// </summary> /// <param name="converter">Class that converst an xml document to a list of substitutions</param> /// <param name="fileController">File controller</param> /// <param name="substitutionMapper">Mappping class of substitutios</param> public SubstitutionController(ISubstitutionDocumentConverter converter, IXmlFileController fileController, ISubstitutionMapper substitutionMapper) { if (substitutionMapper == null) { throw new RnpcParameterException("A mapper is required for decision tree learning."); } if (fileController == null) { throw new RnpcParameterException("A file controller is required for decision tree learning."); } if (converter == null) { throw new RnpcParameterException("A converter is required for decision tree learning."); } if (string.IsNullOrWhiteSpace(ConfigurationDirectory.Instance.NodeSubstitutionsFile)) { throw new RnpcParameterException("A valid file path is required for decision tree learning."); } _converter = converter; _fileController = fileController; _substitionsFilePath = ConfigurationDirectory.Instance.NodeSubstitutionsFile; _substitutionMapper = substitutionMapper; if (!GetSubstitutionsList()) { throw new Exception("No substitutions have been loaded. Decision tree learning can not be done."); } }
public IDecisionNode BuildTreeFromDocument(IXmlFileController reader, Core.Action.Action action, string myName) { // ReSharper disable once JoinNullCheckWithUsage if (reader == null) { throw new RnpcParameterException("Objects FileController has not been properly initialized."); } _reader = reader; _characterName = myName; _currentAction = action; string treeName = $"{action.ActionType}-{action.Intent}-{action.EventName}"; var element = GetXmlElementForAction(treeName); var defaultreaction = string.Empty; if (element?.Attributes["defaultreaction"] != null) { defaultreaction = element.Attributes["defaultreaction"].Value; } var rootNode = InitializeNodeWithXmlElement(element?.FirstChild, null, defaultreaction); return(rootNode); }
/// <inheritdoc /> public void LearnFromMyExperiences(Character learningCharacter, IXmlFileController fileController, ITreeBuilder builder) { //TODO: Test for different psychological illnesses when it is implemented. MainLearningMethod learningMethod = new MainLearningMethod(fileController, builder); learningMethod.LearnFromMyExperiences(learningCharacter); }
/// <summary> /// Builds an XML document from a decision tree, starting with the root node. /// </summary> /// <param name="writer">file writer</param> /// <param name="rootNode">The root of the tree</param> /// <param name="decisionTreeName">The name of the decision tree</param> /// <param name="myName">Character name</param> /// <returns>An xmldocument with the complete decision tree</returns> public bool BuildAndSaveXmlDocumentFromTree(IXmlFileController writer, IDecisionNode rootNode, string decisionTreeName, string myName) { XmlDocument document = new XmlDocument(); var declaration = document.CreateXmlDeclaration("1.0", "UTF-8", null); document.InsertBefore(declaration, document.DocumentElement); XmlNode decisionTree = document.CreateElement(decisionTreeName); document.AppendChild(decisionTree); XmlNode root = document.CreateElement("Root"); var name = document.CreateAttribute("text"); name.Value = rootNode.ToString().Replace("RNPC.DecisionNodes.", "").Replace("RNPC.DecisionLeaves.", ""); root.Attributes?.Append(name); //If it's not a tree with only a leaf var branchNode = rootNode as AbstractDecisionNode; if (branchNode != null) { if (branchNode.ConfiguredPassFailValue != 0) { var testValue = document.CreateAttribute("test"); testValue.Value = branchNode.ConfiguredPassFailValue.ToString(); root.Attributes?.Append(testValue); } if (!string.IsNullOrEmpty(branchNode.DefaultTreeReaction)) { var defaultReaction = document.CreateAttribute("defaultreaction"); defaultReaction.Value = branchNode.DefaultTreeReaction; decisionTree.Attributes?.Append(defaultReaction); } if (branchNode.LeftNode != null) { root.AppendChild(CreateElementFromNode(branchNode.LeftNode, document, "left")); } if (branchNode.RightNode != null) { root.AppendChild(CreateElementFromNode(branchNode.RightNode, document, "right")); } } decisionTree.AppendChild(root); writer.WriteDecisionTreeToXmlFile(myName, document); return(true); }
/// <summary> /// Reads an xml file for a subtree and builds a decision node structure from it. /// </summary> /// <param name="reader"></param> /// <param name="subtreeName"></param> /// <param name="subtreeRepositoryPath"></param> /// <returns></returns> public IDecisionNode BuildSubTreeFromRepository(IXmlFileController reader, string subtreeName, string subtreeRepositoryPath) { // ReSharper disable once JoinNullCheckWithUsage if (reader == null) { throw new RnpcParameterException("Objects FileController has not been properly initialized."); } _reader = reader; var element = GetXmlElementForAction(subtreeName, subtreeRepositoryPath); var rootNode = InitializeNodeWithXmlElement(element.FirstChild, null, string.Empty); return(rootNode); }
internal MainLearningMethod(IXmlFileController fileController, ITreeBuilder builder) { ActionLearningStrategy = new MainActionLearningStrategy(); var controller = new SubstitutionController(new SubstitutionDocumentConverter(), fileController, new SubstitutionMapper()); DecisionTreeLearningStrategy = new MainDecisionTreeLearningStrategy(controller, builder); DesireLearningStrategy = new MainDesireLearningStrategy(); EmotionLearningStrategy = new MainEmotionLearningStrategy(); MemoryLearningStrategy = new MainMemoryLearningStrategy(); OpinionLearningStrategy = new MainOpinionLearningStrategy(); PersonalValueLearningStrategy = new MainPersonalValueLearningStrategy(new PersonalValueAssociations()); QualityLearningStrategy = new MainQualityLearningStrategy(); }
public IDecisionNode BuildTreeFromDocument(IXmlFileController reader, Action action, string myName) { return(null); }
public bool BuildAndSaveXmlDocumentFromTree(IXmlFileController controller, IDecisionNode firstNode, string treename, string myName) { throw new System.NotImplementedException(); }
public IDecisionNode BuildSubTreeFromRepository(IXmlFileController reader, string subtreeName, string subtreeRepositoryPath) { throw new System.NotImplementedException(); }