Esempio n. 1
0
        private static void ExecuteFatHeadNode(Dialog dialog, IDictionary <string, string> variablesValues, FatHeadAnswers fatHeadAnswerNode, DialogExecutionResult result)
        {
            // Adjust variables values
            ExecuteVariableAssignments(fatHeadAnswerNode, variablesValues);

            // Build the mapping URI
            bool redirectToLongTail;
            bool directAnswserValueNotSupportedInFederation;
            var  mappingUri = MappingUriGenerator.ComputeMappingURI(variablesValues, dialog.MappingUriConfig, out redirectToLongTail, out directAnswserValueNotSupportedInFederation);

            // Store the result of this execution
            DialogNodeExecution nodeExecution = null;

            if (redirectToLongTail || directAnswserValueNotSupportedInFederation || String.IsNullOrEmpty(mappingUri))
            {
                nodeExecution = new DialogNodeExecution(fatHeadAnswerNode);
            }
            else
            {
                nodeExecution = new FatHeadAnswerNodeExecution(fatHeadAnswerNode, mappingUri);
            }
            result.AddDialogNodeExecution(nodeExecution);
        }
Esempio n. 2
0
        private static void CompareResultsAcrossDialogVersions(FileInfo newSourceOrDialogFileInfo, FileInfo oldSourceOrDialogFileInfo, FileInfo annotatedQuestionsFileInfo)
        {
            Console.WriteLine("Compare results for two dialog files :");
            Console.WriteLine();

            // Load new dialog file
            string newSourceOrDialogFileName;
            Dialog newDialog = LoadDialogFile(newSourceOrDialogFileInfo, out newSourceOrDialogFileName);

            // Load old dialog file
            string oldSourceOrDialogFileName;
            Dialog oldDialog = LoadDialogFile(oldSourceOrDialogFileInfo, out oldSourceOrDialogFileName);

            // Load all questions
            Console.WriteLine("Reading " + annotatedQuestionsFileInfo.Name + " ... ");
            int            questionCount = 0;
            IList <string> impacts       = new List <string>();

            impacts.Add("id;question;intent;diff;new result;old result;new trace;old trace");
            using (StreamReader sr = new StreamReader(annotatedQuestionsFileInfo.FullName, Encoding.GetEncoding("iso8859-1")))
            {
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] columns      = line.Split(';');
                    string   questionId   = columns[0];
                    string   questionText = columns[1];
                    string   intentName   = columns[2];

                    // Simulate new dialog execution
                    var newResult = DialogInterpreter.AnalyzeInitialQuestion(newDialog, questionId, questionText, intentName);

                    // Simulate old dialog execution
                    var oldResult = DialogInterpreter.AnalyzeInitialQuestion(oldDialog, questionId, questionText, intentName);

                    // Compare results
                    if (!newResult.ReturnsSameResultAs(oldResult))
                    {
                        var newType = newResult.ExecutionResult != null?newResult.ExecutionResult.DialogNode.Type.ToString() : "[no result]";

                        var oldType = oldResult.ExecutionResult != null?oldResult.ExecutionResult.DialogNode.Type.ToString() : "[no result]";

                        string diff = null;
                        if (newType != oldType)
                        {
                            diff = oldType + " => " + newType;
                        }
                        else
                        {
                            if (newType == "FatHeadAnswers")
                            {
                                var newURI = ((FatHeadAnswerNodeExecution)newResult.ExecutionResult).MappingURI;
                                var oldURI = ((FatHeadAnswerNodeExecution)oldResult.ExecutionResult).MappingURI;
                                diff = "FH: " + FatHeadAnswerNodeExecution.CompareMappingURIs(newURI, oldURI);
                            }
                            else
                            {
                                diff = oldType + " changed";
                            }
                        }

                        impacts.Add(newResult.QuestionId + ";" + newResult.QuestionText + ";" + newResult.IntentName + ";" + diff + ";" + newResult.ResultString + ";" + oldResult.ResultString + ";" + newResult.ToString() + ";" + oldResult.ToString());
                    }

                    questionCount++;
                    if (questionCount % 500 == 0)
                    {
                        Console.WriteLine(questionCount + " test set questions analyzed");
                    }
                }

                // TO DO : do the same thing with all DisambiguationQuestion nodes found in the tree
            }
            Console.WriteLine("OK");

            Console.WriteLine("Analysis completed :");
            Console.WriteLine("- impacts found on " + impacts.Count + " questions of the test set");
            Console.WriteLine("");

            // Write comparison results file
            var comparisonFilePath = @"result\" + newSourceOrDialogFileName + "." + oldSourceOrDialogFileName + "." + annotatedQuestionsFileInfo.Name + ".compare.csv";

            Console.Write("Writing " + comparisonFilePath + " ... ");
            HashSet <string> mappingURISet = new HashSet <string>();

            using (StreamWriter sw = new StreamWriter(comparisonFilePath, false, Encoding.GetEncoding("iso8859-1")))
            {
                foreach (var impact in impacts)
                {
                    sw.WriteLine(impact);
                }
            }
            Console.WriteLine("OK");
            Console.WriteLine("");
        }