Ejemplo n.º 1
0
        public void Validate(UtteranceValidationSet validator)
        {
            report_tagsAsTargets = new List<string>();
            report_tagsAsAnimations = new List<string>();
            report_tags = new List<string>();
            report_animations = new List<string>();
            report_gameInstructions = new List<string>();
            report_faceExpressions = new List<string>();
            report_targets = new List<string>();
            report_errors = new List<string>();
            report_TTS = new List<string>();
            int validUtterances = 0;
            for (int i = 0; i < utterances.Rows.Count; i++)
            {
                string text = utterances.Rows[i].Field<string>(FIELD_TEXT);
                if (VerifyUtterance(text, i + 2, validator))
                {
                    validUtterances++;
                }
            }
            string reportPath = Path.GetDirectoryName(libraryFilename) + "\\" + Path.GetFileNameWithoutExtension(libraryFilename) + "_validationReport.html";
            TextWriter tw = new StreamWriter(reportPath);
            tw.WriteLine("<html><head /><body><b>Skene Utterances Validation Report</b><br><br><b>Library:</b> {0}<br><b>Validation Set:</b> {5}<br><b>Total Utterances:</b> {1}<br><b>Valid Utterances:</b> {2}<br><b>Invalid Utterances:</b> {3}<br><b>Errors:</b> {4}<br><br><br><b>Error list:</b><br><br>", libraryFilename, utterances.Rows.Count, validUtterances, utterances.Rows.Count - validUtterances, report_errors.Count, validator.Filename);

            tw.WriteLine("<table border='1'>");
            foreach (string line in report_errors)
            {
                tw.WriteLine("<tr><td width=\"3%\" align=\"center\">-</td><td>");
                tw.WriteLine(String.Format(line));
                tw.WriteLine("</td></tr>");
            }
            tw.WriteLine("</table><br><br>");

            tw.WriteLine("<br><b>Tags used in Targets:</b><br>");
            foreach (string line in report_tagsAsTargets)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Tags used in Animations:</b><br>");
            foreach (string line in report_tagsAsAnimations)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Tags:</b><br>");
            foreach (string line in report_tags)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Targets:</b><br>");
            foreach (string line in report_targets)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Animations:</b><br>");
            foreach (string line in report_animations)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Face Expressions:</b><br>");
            foreach (string line in report_faceExpressions)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Game Instructions:</b><br>");
            foreach (string line in report_gameInstructions)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><b>Text-to-Speech Instructions:</b><br>");
            foreach (string line in report_TTS)
            {
                tw.WriteLine(HttpUtility.HtmlEncode(line) + "<br>");
            }

            tw.WriteLine("<br><br><b>End of validation report.</b><br>");
            tw.Close();
            Process process = new Process();
            process.StartInfo = new ProcessStartInfo()
            {
                UseShellExecute = true,
                FileName = reportPath
            };
            process.Start();
        }
Ejemplo n.º 2
0
        private bool VerifyUtterance(string text, int line, UtteranceValidationSet validator)
        {
            if (text == null || text.Length == 0) return true;
            bool result = true;
            Regex regex = new Regex(regexAllInstructions, RegexOptions.IgnoreCase);
            MatchCollection matches = regex.Matches(text);
            if (matches.Count != StringCount(text, "<"))
            {
                report_errors.Add(string.Format("Missing or Extra '<' in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
                result = false;
            }
            if (matches.Count != StringCount(text, ">"))
            {
                report_errors.Add(string.Format("Missing or Extra '>' in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
                result = false;
            }
            if (matches.Count != StringCount(text, "("))
            {
                report_errors.Add(string.Format("Missing or Extra '(' in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
                result = false;
            }
            if (matches.Count != StringCount(text, ")"))
            {
                report_errors.Add(string.Format("Missing or Extra ')' in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
                result = false;
            }
            
            if (matches.Count > 1)
            {
                foreach (Match match in matches)
                {
                    string instruction = match.Value.Substring(1, match.Value.IndexOf('(') - 1);
                    if (!validator.TargetInstructionValidator.IsValid(instruction) && !validator.NonTargetInstructionValidator.IsValid(instruction))
                    {
                        report_errors.Add(string.Format("Invalid instruction <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", instruction, line, HttpUtility.HtmlEncode(text)));
                        result = false;
                    }
                }
            }

            Regex hnall = new Regex(regexHeadNodAllInstructions, RegexOptions.IgnoreCase);
            MatchCollection hnallmatches = hnall.Matches(text);
            Regex hnv = new Regex(regexHeadNodValidInstructions, RegexOptions.IgnoreCase);
            MatchCollection hnvmatches = hnv.Matches(text);
            if (hnallmatches.Count != hnvmatches.Count)
            {
                report_errors.Add(string.Format("Invalid parameter in HEADNOD or HEADNODNEGATIVE in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
            }

            regex = new Regex(validator.TargetInstructionValidator.BuildRegexParameterString(regexTargetNames), RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.TargetsValidator.IsValid(match.Value))
                {
                    if (StringCount(match.Value, "/") == 2)
                    {
                        string tag = match.Value.Substring(match.Value.IndexOf('/')+1, match.Value.LastIndexOf('/') - match.Value.IndexOf('/') - 1);
                        if (!validator.TagsValidator.IsValid(tag))
                        {
                            report_errors.Add(string.Format("Invalid Tag as Target <b>{0} in utterance in <b>line {1}: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                        }
                        if (!report_tagsAsTargets.Contains(match.Value)) report_tagsAsTargets.Add(match.Value);
                    }
                    else
                    {
                        report_errors.Add(string.Format("Invalid Target <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                        result = false;
                    }
                }
                if (!report_targets.Contains(match.Value)) report_targets.Add(match.Value);
            }

            regex = new Regex(regexAnimationNames, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.AnimationValidator.IsValid(match.Value))
                {
                    if (StringCount(match.Value, "/") == 2)
                    {
                        string tag = match.Value.Substring(match.Value.IndexOf('/') + 1, match.Value.LastIndexOf('/') - match.Value.IndexOf('/') - 1);
                        if (validator.TagsValidator.IsValid(tag))
                        {
                            if (!report_tagsAsAnimations.Contains(match.Value)) report_tagsAsAnimations.Add(match.Value);
                        }
                        else
                        {
                            report_errors.Add(string.Format("Invalid Tag as Animation <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                        }
                    }
                    else
                    {
                        report_errors.Add(string.Format("Invalid Animation <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                        result = false;
                    }
                }
                if (!report_animations.Contains(match.Value)) report_animations.Add(match.Value);
            }

            regex = new Regex(regexFaceExpressions, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.FaceExpressionsValidator.IsValid(match.Value))
                {
                    report_errors.Add(string.Format("Invalid Face Expression <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                    result = false;
                }
                if (!report_faceExpressions.Contains(match.Value)) report_faceExpressions.Add(match.Value);
            }

            regex = new Regex(regexGameInstructions, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.GameInstructions.IsValid(match.Value.IndexOf(',') != -1 ? match.Value.Substring(0, match.Value.IndexOf(',')) : match.Value))
                {
                    report_errors.Add(string.Format("Invalid Game Instruction <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                    result = false;
                }
                if (!report_gameInstructions.Contains(match.Value)) report_gameInstructions.Add(match.Value);
            }

            regex = new Regex(regexTags, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.TagsValidator.IsValid(match.Value))
                {
                    report_errors.Add(string.Format("Invalid Tag <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                    result = false;
                }
                if (!report_tags.Contains(match.Value)) report_tags.Add(match.Value);
            }

            regex = new Regex(regexTTS, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            foreach (Match match in matches)
            {
                if (!validator.TTSValidator.IsValid(match.Value))
                {
                    report_errors.Add(string.Format("Invalid TTS instruction <b>{0}</b> in utterance in <b>line {1}</b>: '{2}'", match.Value, line, HttpUtility.HtmlEncode(text)));
                    result = false;
                }
                if (!report_TTS.Contains(match.Value)) report_TTS.Add(match.Value);
            }

            regex = new Regex(regexTTSPauRspd, RegexOptions.IgnoreCase);
            matches = regex.Matches(text);
            Regex ttsall1 = new Regex(regexTTSAll1, RegexOptions.IgnoreCase);
            MatchCollection tts1matches = ttsall1.Matches(text);
            Regex ttsall2 = new Regex(regexTTSAll2, RegexOptions.IgnoreCase);
            MatchCollection tts2matches = ttsall2.Matches(text);
            if (matches.Count != tts1matches.Count || matches.Count != tts2matches.Count)
            {
                report_errors.Add(string.Format("Invalid TTS pause instruction in utterance in <b>line {0}</b>: '{1}'", line, HttpUtility.HtmlEncode(text)));
            }           

            return result;
        }