예제 #1
0
        private static void GenerateReferenceFile(FileInfo dialogFileInfo)
        {
            Console.WriteLine("Generate reference file :");
            Console.WriteLine();


            // Load dialog file
            string sourceOrDialogFileName;
            Dialog dialog = LoadDialogFile(dialogFileInfo, out sourceOrDialogFileName);

            // Reference file path
            var referenceFilePath = @"result/" + "ref-" + sourceOrDialogFileName + ".xlsx";

            Console.Write("Writing " + referenceFilePath + " ... ");

            List <string> mappingURISet = new List <string>();

            foreach (DialogNode node in dialog.Intents.Values)
            {
                GetUris(node, mappingURISet);
            }


            Dictionary <string, string> intentCanonical = new DialogFile(dialogFileInfo).ReadIntentCanonical();

            ReferenceFile.Write(mappingURISet, referenceFilePath, intentCanonical);
            Console.WriteLine("OK");
        }
예제 #2
0
    public void StartDialog(Dialog d, string npcName)
    {
        ResetDialog();

        _currentDialog = d.dialog;
        _invokeEvent   = false;

        SetDialog(npcName);
    }
예제 #3
0
        private static Dialog LoadDialogFile(FileInfo sourceOrDialogFileInfo, out string sourceOrDialogFileName, bool isInternalTest = false)
        {
            sourceOrDialogFileName = sourceOrDialogFileInfo.Name;
            Console.Write("Reading " + sourceOrDialogFileName + " ... ");
            var    dialogFile = new DialogFile(sourceOrDialogFileInfo);
            Dialog dialog     = dialogFile.Read(isInternalTest);

            Console.WriteLine("OK");
            Console.WriteLine();
            return(dialog);
        }
예제 #4
0
    public void StartDialog(QuestDialog q, string npcName)
    {
        ResetDialog();

        _currentDialog = q.dialog;

        _dialogEvent = q.onDialogEnd;
        _invokeEvent = true;

        SetDialog(npcName);
    }
예제 #5
0
 private void LoadDialog()
 {
     if (Selection.activeObject && Selection.activeObject is DialogFile)
     {
         _currentDialog = (DialogFile)Selection.activeObject;
     }
     else
     {
         _currentDialog = null;
         Debug.Log("No object is currently selected");
     }
 }
예제 #6
0
    public void StartDialog(EventDialog e, string npcName)
    {
        ResetDialog();

        _currentDialog = e.dialog;

        if (e.onDialogEnd != null)
        {
            _invokeEvent = !(e.invokeEventOnce && e.wasEventInvoked);

            if (_invokeEvent)
            {
                _dialogEvent      = e.onDialogEnd;
                e.wasEventInvoked = true;
            }
        }

        SetDialog(npcName);
    }
예제 #7
0
    public static string OpenFile(string type = "All files(*.*)|*.*", string title = "选择")
    {
        DialogFile pth = new DialogFile();

        pth.structSize   = System.Runtime.InteropServices.Marshal.SizeOf(pth);
        pth.filter       = type;// "All files(*.*)|*.*";
        pth.file         = new string(new char[256]);
        pth.maxFile      = pth.file.Length;
        pth.fileTitle    = new string(new char[64]);
        pth.maxFileTitle = pth.fileTitle.Length;
        pth.initialDir   = Application.dataPath; // default path
        pth.title        = title;
        pth.defExt       = "*.*";
        pth.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        if (DllOpenFileDialog.GetOpenFileName(pth))
        {
            string filepath = pth.file;//选择的文件路径;
            return(filepath);
        }
        return(null);
    }
예제 #8
0
        public TestUI(UIStyle style, GraphicsDevice graphicsDevice)
        {
            UISystem = new UISystem(graphicsDevice);
            // panel 1
            UIPanel panel = new UIPanel(25, 25, 150, 150, hastitle: true, title: "Test Panel 1", titlesize: 16);

            UISystem.Add(panel);

            UILabel label1 = new UILabel(0, 0, panel.Width - 10, 10, "text goes here let's see if it will wrap automatically, which it should if everything is working properly.", fontsize: 12,
                                         font: "NotoSans_regular"); // test spritefont

            panel.AddAuto(label1);

            // panel 2
            UIPanel panel2 = new UIPanel(225, 25, 150, 150, hastitle: true, title: "Test Panel 2", titlesize: 16);

            UISystem.Add(panel2);

            UIButton button1 = new UIButton(5, 5, 75, 25, "Test Button");

            panel2.AddAuto(button1);

            UICheckbox chk1 = new UICheckbox(5, 40, 20, 20);

            panel2.Add(chk1);
            UILabel chk1label = new UILabel(30, 40, 100, 20, "unchecked");

            panel2.Add(chk1label);
            chk1.EventCheckChanged += (sender, args) =>
            {
                if (chk1.Checked)
                {
                    chk1label.Text = "checked";
                }
                else
                {
                    chk1label.Text = "unchecked";
                }
                chk1label.ProcessText();
            };


            // panel 3
            UIPanel panel3 = new UIPanel(425, 25, 150, 150, hastitle: true, title: "Test Panel 3", titlesize: 12);

            UISystem.Add(panel3);

            UITextField textfield1 = new UITextField(5, 5, 135, 25, "", fontsize: 16, placeholdertext: "Try Typing...");

            panel3.AddAuto(textfield1);

            UINumberField numfield1 = new UINumberField(5, 5, 135, 35, 40, "0", true, fontsize: 16);

            panel3.AddAuto(numfield1);

            UINumberField numfield2 = new UINumberField(5, 5, 135, 35, 40, "0.0", false, fontsize: 16);

            panel3.AddAuto(numfield2);

            // panel 4
            UIPanel panel4 = new UIPanel(625, 25, 150, 150, hastitle: true, title: "Test Panel 4", titlesize: 14);

            UISystem.Add(panel4);

            UILabel label2 = new UILabel(0, 0, panel4.Width - 10, 10, "text goes here let's see if it will wrap automatically, which it should if everything is working properly.", fontsize: 18);

            label2.TextSplitWords = true;
            panel4.AddAuto(label2);
            UILabel label3 = new UILabel(0, 10, panel4.Width - 10, 10, "A second auto-label. This gal should automatically get cut off when it goes too long", fontsize: 16);

            label3.TextSplitWords = true;
            panel4.AddAuto(label3);

            // panel 5
            UIPanel panel5 = new UIPanel(25, 200, 150, 150, true, "Dropdown Test");

            UISystem.Add(panel5);

            UIDropdown drop1 = new UIDropdown(0, 0, 80, 30, "droptest");

            drop1.AddItem("log A", (uid, args) => { drop1.Text = "AAAA"; drop1.ProcessText(); });
            drop1.AddItem("log B", (uid, args) => { drop1.Text = "BBBB"; drop1.ProcessText(); });
            panel5.AddAuto(drop1);

            // panel 6
            UIPanel panel6 = new UIPanel(200, 200, 150, 150, true, "Scroll Vert Test", hasscrolling: true, scrollh: 400);

            UISystem.Add(panel6);
            UILabel label4 = new UILabel(0, 10, panel6.Width - 20, 350, "newlines \n should be auto processed 1\n 2\n 3\n 4\n 5\n test the bottom \n test", fontsize: 16);

            panel6.AddAuto(label4);

            // panel 7
            UIPanel panel7 = new UIPanel(400, 200, 150, 150, true, "Scroll Horz Test", hasscrolling: true, scrollw: 400);

            UISystem.Add(panel7);
            UILabel label5 = new UILabel(0, 10, panel7.ScrollWidth - 10, 10, "a very long bit a text. It just goes on and on and doesn't end. A very long line that should be much smaller. But it's not, it's very large, instead.", fontsize: 18);

            panel7.AddAuto(label5);

            // panel 8
            UIPanel panel8 = new UIPanel(600, 200, 150, 150, true, "Dialogs Test");

            UISystem.Add(panel8);
            UIButton popupbtn = new UIButton(0, 0, 100, 30, "pop up");

            panel8.AddAuto(popupbtn);
            UIButton filebtn = new UIButton(0, 0, 100, 30, "open file");

            panel8.AddAuto(filebtn);

            popupbtn.EventFocused += (sender, args) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = args as UIComponent.EventFocusedHandlerArgs;
                DialogPopup popup = new DialogPopup("Popup", "time elapsed: " + eargs.ElapsedMS);
                popup.Popup(UISystem);
                popup.EventClosed += (innersender, innerargs) =>
                {
                    popup.Dispose();
                };
            };
            filebtn.EventFocused += (sender, args) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = args as UIComponent.EventFocusedHandlerArgs;
                DialogFile filepopup = new DialogFile(DialogFile.eMode.SELECT_FILE, ".\\", "file.txt", "Select a File");
                filepopup.Popup(UISystem);
                filepopup.EventClosed += (innersender, innerargs) =>
                {
                    filepopup.Dispose();
                };
            };

            // panel 9
            UIPanel panel9 = new UIPanel(100, 350, 220, 100);

            UISystem.Add(panel9);
            UITextField multiLineText = new UITextField(0, 0, 200, 80, "", autoheight: false, placeholdertext: "try typing multi lines", fontsize: 11)
            {
                MultiLine = true
            };

            multiLineText.SetTextStyler(new TextStylerTest());
            panel9.Add(multiLineText);

            // panel 10
            UIPanel panel10 = new UIPanel(20, 20, 400, 400, true, "RelaScript", titlesize: 12, hasclose: true);

            panel10.CloseButton.EventFocused += (sender, eargs) =>
            {
                panel10.Visible = false;
            };
            UISystem.Add(panel10);
            UITextField relaMultiText = new UITextField(5, 5, 380, 350, "", autoheight: false,
                                                        fontsize: 18, font: "NotoMono-Regular")
            {
                MultiLine = true
            };

            relaMultiText.EventPostInit += (sender, eargs) =>
            {
                relaMultiText.TextColor = new Microsoft.Xna.Framework.Color(218, 218, 218, 255);
            };
            relaMultiText.SetTextStyler(new TextStylerRelaScript());
            panel10.Add(relaMultiText);

            UISystem.Init(style);
        }
예제 #9
0
 public static extern bool GetSaveFileName([In, Out] DialogFile ofn);
예제 #10
0
    // dialog coroutine
    IEnumerator RunDialog(IDialogUI ui, string path)
    {
        DialogFile f = new DialogFile(path, Flags);

        // wait a tick so that we update ourselves as active
        yield return(null);

        // run dialog
        foreach (object o in f)
        {
            // check for events
            if (CheckStatement(o, "event"))
            {
                DialogEvents events = DialogEvents.GetInstance();
                if (events == null)
                {
                    throw new DialogError("DialogEvents GameObject does not exist or does not have 'DialogEvents' tag.");
                }
                events.HandleEvent(o);
            }
            // output to DialogUI
            else if (o is string)
            {
                ui.DisplayText(null, (string)o);
            }
            else if (CheckStatement(o, "show"))
            {
                Dictionary <string, object> args = GetStatementArgs(o, "show");
                if (args == null)
                {
                    throw new DialogError($"Invalid 'show' statement. 'show' statement must contain a map.\nYAML: {Reserialize(o)}");
                }
                if (!args.ContainsKey("id"))
                {
                    throw new DialogError($"Invalid 'show' statement. 'show' statement must contain an 'id' field.\nYAML: {Reserialize(o)}");
                }
                if (!args.ContainsKey("image"))
                {
                    throw new DialogError($"Invalid 'show' statement. 'show' statement must contain an 'image' field.\nYAML: {Reserialize(o)}");
                }
                ui.ShowCharacter((string)args["id"], (string)args["image"], new DialogImageOptions(o));
            }
            else if (CheckStatement(o, "hide"))
            {
                Dictionary <string, object> args = GetStatementArgs(o, "hide");
                if (args == null)
                {
                    throw new DialogError($"Invalid 'hide' statement. 'hide' statement must contain a map.\nYAML: {Reserialize(o)}");
                }
                if (!args.ContainsKey("id"))
                {
                    throw new DialogError($"Invalid 'hide' statement. 'hide' statement must contain an 'id' field.\nYAML: {Reserialize(o)}");
                }
                ui.HideCharacter((string)args["id"]);
            }
            // 1 item in dictionary means it is dialog such as "E: Very good code."
            else if (o is Dictionary <object, object> && ((Dictionary <object, object>)o).Count == 1)
            {
                Dictionary <string, object> args = CastArgs((Dictionary <object, object>)o);
                string chr = args.Keys.First();
                if (!f.Characters.ContainsKey(chr))
                {
                    throw new DialogError($"Invalid dialog statement. Character ID '{chr}' is not defined.\nYAML: {Reserialize(o)}");
                }
                object val = args[args.Keys.First()];
                // unknown statement type (error)
                if (!(val is string))
                {
                    throw new DialogError($"Unknown statement type: {Reserialize(o)}");
                }
                ui.DisplayText(f.Characters[chr].name, (string)val);
            }
            // unknown statement type (error)
            else
            {
                throw new DialogError($"Unknown statement type: {Reserialize(o)}");
            }
            // wait until RequestAdvance has been called
            while (!advance)
            {
                yield return(null);
            }
            advance = false;
        }
        // at end of dialog, mark that dialog is finished
        ui.Finish();
        dialog = null;
    }
예제 #11
0
        static void Main(string[] args)
        {
            var selectInsurance  = false;
            var displayDebugInfo = true;

            var INTENTS_INSURANCE_MODEL_FILE_NAME = "model_demo_insurance.ftz";
            var INTENTS_SAVINGS_MODEL_FILE_NAME   = "model_demo_savings.ftz";

            var DIALOG_INSURANCE_FILE_NAME = "MCT-Account-ins_ded_prod_patch2_0703.xml";
            var DIALOG_SAVINGS_FILE_NAME   = "MCT-Account-sav_ded_uat_cmne_1105.xml";

            var ANSWERS_INSURANCE_FILE_NAME = "au_assurance.json";
            var ANSWERS_SAVINGS_FILE_NAME   = "au_epargne.json";

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.Write("EURO ");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("INFORMATION");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(" - Démo Assistant Virtuel " + (selectInsurance?"Assurance Auto-IRD":"Epargne") + " autonome");

            Stopwatch chrono = new Stopwatch();

            chrono.Start();
            using (SentenceClassifier classifier = new SentenceClassifier(selectInsurance ? INTENTS_INSURANCE_MODEL_FILE_NAME : INTENTS_SAVINGS_MODEL_FILE_NAME))
            {
                classifier.PredictLabels("test");
                chrono.Stop();
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("Intents model loaded in " + chrono.ElapsedMilliseconds + " ms, C++ memory usage " + classifier.GetWorkingSetMo() + " Mo");

                chrono.Restart();
                var    dialogFile = new DialogFile(new FileInfo(DIALOG_DIR + (selectInsurance ? DIALOG_INSURANCE_FILE_NAME : DIALOG_SAVINGS_FILE_NAME)));
                Dialog dialog     = dialogFile.Read();
                chrono.Stop();
                Console.WriteLine("Dialog configuration loaded in " + chrono.ElapsedMilliseconds + " ms, C# memory usage " + (Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024) + " Mo");

                chrono.Restart();
                var answerStore = new AnswerStoreSimulator(selectInsurance ? ANSWERS_INSURANCE_FILE_NAME : ANSWERS_SAVINGS_FILE_NAME);
                chrono.Stop();
                Console.WriteLine(answerStore.AnswerUnits.Count + " Answer units loaded in " + chrono.ElapsedMilliseconds + " ms, C# memory usage " + (Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024) + " Mo");
                Console.WriteLine("");

                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("@ Bonjour, vous pouvez me poser des questions dans le domaine de l'épargne.");
                Console.WriteLine("@ (puis saisissez \"exit\" pour sortir du programme)");
                Console.WriteLine();
                for (;;)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("@ Quelle est votre question ?");
                    Console.WriteLine();

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("> ");
                    string userInputText = Console.ReadLine();
                    Console.WriteLine();
                    if (userInputText == "exit")
                    {
                        break;
                    }

                    chrono.Restart();
                    var intentResult = classifier.PredictLabels(userInputText);
                    chrono.Stop();
                    if (displayDebugInfo)
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("Classifier results :");
                        Console.WriteLine("1. " + intentResult.Label1 + " -> " + (intentResult.Proba1 * 100).ToString("00.00") + "%");
                        Console.WriteLine("2. " + intentResult.Label2 + " -> " + (intentResult.Proba2 * 100).ToString("00.00") + "%");
                        Console.WriteLine();
                    }

                    bool isFatHead = intentResult.Proba1 > 0.5;
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    if (isFatHead)
                    {
                        Console.WriteLine("@ J'ai compris que votre intention est : ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("  " + intentResult.Label1);
                    }
                    else
                    {
                        Console.WriteLine("@ Je pense que votre intention est : ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("  " + intentResult.Label1);
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine("@  ou peut-être ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("  " + intentResult.Label2);
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine("@  mais je n'en suis pas sûr -> je vous redirige vers le mode Recherche ...");
                    }
                    Console.ForegroundColor = ConsoleColor.Gray;
                    long timeInMicrosec = (chrono.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L)));
                    Console.WriteLine("Intents detected in " + (timeInMicrosec > 1000?(timeInMicrosec / 1000).ToString():("0." + timeInMicrosec)) + " ms");
                    Console.WriteLine();

                    if (isFatHead)
                    {
                        DialogExecutionResult  dialogResult = null;
                        DisambiguationQuestion lastDisambiguationQuestion = null;
                        do
                        {
                            chrono.Restart();
                            if (dialogResult == null)
                            {
                                dialogResult = DialogInterpreter.AnalyzeInitialQuestion(dialog, String.Empty, userInputText, intentResult.Label1);
                            }
                            else
                            {
                                dialogResult = DialogInterpreter.ExecuteUserInputNode(dialog, lastDisambiguationQuestion, userInputText, dialogResult);
                                lastDisambiguationQuestion = null;
                            }
                            chrono.Stop();

                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            var nodeExecution = dialogResult.ExecutionResult;
                            if (nodeExecution is FatHeadAnswerNodeExecution)
                            {
                                var mappingUri = ((FatHeadAnswerNodeExecution)nodeExecution).MappingURI;
                                if (!selectInsurance)
                                {
                                    mappingUri = "/federationGroup/CM" + mappingUri;
                                }
                                Console.WriteLine("@ J'ai trouvé une réponse exacte à cette question : ");
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("  " + mappingUri);

                                var answerUnit = answerStore.GetAnswerUnitForMappingUri(mappingUri);
                                if (answerUnit != null)
                                {
                                    Console.ForegroundColor = ConsoleColor.White;
                                    Console.WriteLine();
                                    foreach (string title in answerUnit.content.title)
                                    {
                                        if (title != "no-title")
                                        {
                                            Console.WriteLine("# " + title);
                                        }
                                    }
                                    var text = answerUnit.content.plainText;
                                    if (text.Length > 800)
                                    {
                                        text = text.Substring(0, 795) + " ...";
                                    }
                                    Console.WriteLine(text);
                                    Console.WriteLine();
                                }
                            }
                            else if (nodeExecution.DialogNode is DisambiguationQuestion)
                            {
                                lastDisambiguationQuestion = ((DisambiguationQuestion)nodeExecution.DialogNode);
                                Console.WriteLine("@ Votre question est ambigüe, je dois vous demander en complément : ");
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("  " + lastDisambiguationQuestion.QuestionText);
                                if (lastDisambiguationQuestion.DisambiguationOptions != null)
                                {
                                    foreach (var option in lastDisambiguationQuestion.DisambiguationOptions)
                                    {
                                        Console.WriteLine("  - " + option.Text + " [" + option.EntityValue.CanonicalValue + "]");
                                    }
                                }
                                Console.WriteLine();

                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.Write("> ");
                                userInputText = Console.ReadLine();
                                Console.WriteLine();
                            }
                            else if (nodeExecution.DialogNode.Type == DialogNodeType.RedirectToLongTail)
                            {
                                Console.WriteLine("@ Dans ce cas de figure, le dialogue vous redirige vers le mode Recherche ...");
                            }
                            else if (nodeExecution.DialogNode is DirectAnswer)
                            {
                                var direct = ((DirectAnswer)nodeExecution.DialogNode);
                                Console.WriteLine("@ Je dois afficher le message suivant : ");
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("  " + direct.MessageText);
                            }
                            else
                            {
                                Console.WriteLine("@ ERREUR - résultat de dialogue inattendu");
                            }
                            Console.ForegroundColor = ConsoleColor.Gray;
                            timeInMicrosec          = (chrono.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L)));
                            Console.WriteLine("Dialog interpreted in " + (timeInMicrosec > 1000 ? (timeInMicrosec / 1000).ToString() : ("0." + timeInMicrosec)) + " ms");
                            Console.WriteLine();

                            if (displayDebugInfo && !(nodeExecution.DialogNode is DisambiguationQuestion))
                            {
                                Console.ForegroundColor = ConsoleColor.Gray;
                                Console.WriteLine("Dialog execution trace :");
                                int i = 0;
                                foreach (var nodeExec in dialogResult.DialogNodesExecutionPath)
                                {
                                    i++;
                                    Console.Write(i + ". ");
                                    switch (nodeExec.DialogNode.Type)
                                    {
                                    default:
                                        Console.Write(nodeExec.ToString());
                                        break;
                                    }
                                    Console.WriteLine(" (l:" + nodeExec.DialogNode.LineNumber + ")");
                                }
                                Console.WriteLine();
                            }
                        } while (lastDisambiguationQuestion != null);
                    }
                }

                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("@ Aurevoir.");
            }
        }