예제 #1
0
        static void Main(string[] args)
        {
            // verbot variables
            Verbot5Engine     verbot = new Verbot5Engine();
            KnowledgeBase     kb     = new KnowledgeBase();
            KnowledgeBaseItem kbi    = new KnowledgeBaseItem();
            State             state  = new State();

            // build the knowledgebase
            Rule vRule = new Rule();

            vRule.Id = kb.GetNewRuleId();
            vRule.AddInput("Hello", "");
            vRule.AddInput("Hi", "");
            vRule.AddOutput("Hello, World", "", "");
            kb.Rules.Add(vRule);
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            // save the knowledgebase
            XMLToolbox xToolbox = new XMLToolbox(typeof(KnowledgeBase));

            xToolbox.SaveXML(kb, path + @"\kbi.vkb");

            // load the knowledgebase item
            kbi.Filename = "kbi.vkb";
            kbi.Fullpath = path + @"\";

            // set the knowledge base for verbot
            verbot.AddKnowledgeBase(kb, kbi);

            state.CurrentKBs.Add(path + @"\kbi.vkb");

            // get input
            Console.WriteLine("Please enter your message");

            while (true)
            {
                string msg = Console.ReadLine();

                // process the reply
                Reply reply = verbot.GetReply(msg, state);
                if (reply != null)
                {
                    Console.WriteLine(reply.AgentText);
                }
                else
                {
                    Console.WriteLine("No reply found.");
                }
            }
        }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        // build the knowledgebase
        Rule vRule = new Rule();

        vRule.Id = kb.GetNewRuleId();
        vRule.AddInput("Hello", "");
        vRule.AddInput("Hi", "");
        vRule.AddOutput("Hello, World", "", "");
        kb.Rules.Add(vRule);

        //Path to save the file
        string fileNameVKB = "kbi.vkb";
        string sPath       = System.IO.Path.Combine(Application.streamingAssetsPath, "Verbots");
        string fullPath    = System.IO.Path.Combine(sPath, fileNameVKB);

        try
        {
            // save the knowledgebase
            XMLToolbox xToolbox = new XMLToolbox(typeof(KnowledgeBase));
            xToolbox.SaveXML(kb, fullPath);
            Debug.Log(string.Format("{0} file saved in: {1}", fileNameVKB, fullPath));
        }
        catch (Exception e)
        {
            Debug.LogWarning(e.ToString());
        }

        // load the knowledgebase item
        kbi.Filename = fileNameVKB;
        kbi.Fullpath = sPath + @"\";

        // set the knowledge base for verbot
        verbot.AddKnowledgeBase(kb, kbi);

        state.CurrentKBs.Add(fullPath);

        //Console: bot Response
        Debug.Log("Verbot initialized");
        string userInput = "Hello";

        Debug.Log(string.Format("User: {0}", userInput));
        Debug.Log(string.Format("Bot: {0}", getReply(userInput)));
    }
예제 #3
0
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 1200, 500), EditorStyles.helpBox);
        _scrollPositionBottom = EditorGUILayout.BeginScrollView(_scrollPositionBottom, true, true);

        EditorGUILayout.LabelField("Rules:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField(" -S: second input item doesn't need to be selected. -I: main output goes straight to inventory. #Rules: " + RuleDatabase.GetNumOfAssets()); // +
        //"-A: rule is executed automatically. ");
        if (GUILayout.Button("Add New Rule", GUILayout.ExpandWidth(false)))
        {
            foldedOut.Add(false);
            RuleDatabase.CreateAsset();
        }



        for (int ruleIndx = 0; ruleIndx < RuleDatabase.GetNumOfAssets(); ruleIndx++)
        {
            Rule rule = RuleDatabase.GetAsset(ruleIndx);
            EditorUtility.SetDirty(rule);
            string additionalProperties = "";       //Addition - indicating Rule properties:
            if (rule.selectedInput)
            {
                additionalProperties += " -S ";     //Second input item does not need to be selected
            }
            if (rule.inventory)
            {
                additionalProperties += " -I ";     //First output item is spawned directly in the inventory
            }

            /*if (rule.automatic)
             *  additionalProperties += " -A ";  *///Such rules are excuted automatically
            if (rule.ruleNumber != GetFileNameShort(rule))
            {
                rule.ruleNumber = GetFileNameShort(rule);
            }
            string ruleNumber = "#" + rule.ruleNumber + ": ";
            foldedOut[ruleIndx] = EditorGUILayout.Foldout(foldedOut[ruleIndx], ruleNumber + rule.GetRuleAsString() + additionalProperties);

            if (foldedOut[ruleIndx])
            {
                // === OUTPUT ===
                EditorGUILayout.LabelField("Output:", EditorStyles.boldLabel);

                for (int outputIndx = 0; outputIndx < rule.outputs.Count; outputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term output = rule.outputs[outputIndx];
                    output.name = EditorGUILayout.TextArea(output.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteOutputAtIndex(outputIndx);
                    }
                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < output.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(output.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            output.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        output.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddOutput();
                }

                // === ACTION ===
                EditorGUILayout.LabelField("Action:", EditorStyles.boldLabel);
                rule.action = EditorGUILayout.TextArea(rule.action);

                // === INPUT ===
                EditorGUILayout.LabelField("Input:", EditorStyles.boldLabel);

                for (int inputIndx = 0; inputIndx < rule.inputs.Count; inputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term input = rule.inputs[inputIndx];
                    input.name = EditorGUILayout.TextArea(input.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteInputAtIndex(inputIndx);
                    }

                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < input.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(input.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            input.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        input.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }


                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddInput();
                }


                // === InIventory ===                   (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Input doesn't need to be selected:", EditorStyles.boldLabel);
                rule.selectedInput = EditorGUILayout.Toggle(rule.selectedInput);
                EditorGUILayout.EndHorizontal();

                // === Straight to Inventory ===        (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("First output goes straight to inventory:", EditorStyles.boldLabel);
                rule.inventory = EditorGUILayout.Toggle(rule.inventory);
                EditorGUILayout.EndHorizontal();

                /*// === Automatic Rule ===        (addition)       This is a starting point for including rules which can be executed without player interaction
                 * EditorGUILayout.BeginHorizontal();
                 * EditorGUILayout.LabelField("Automatically executed rule:", EditorStyles.boldLabel);
                 * rule.automatic = EditorGUILayout.Toggle(rule.automatic);
                 * EditorGUILayout.EndHorizontal();
                 */
                if (GUILayout.Button("Delete Rule", GUILayout.ExpandWidth(false)))
                {
                    RuleDatabase.DeleteAsset(ruleIndx);
                }
            }
        }

        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();
    }