private (List <string> questions, List <Error> errors) ExtractMoreQuestions(LUFileParser.QnaSectionContext parseTree) { var questions = new List <string>(); var errors = new List <Error>(); var questionsBody = parseTree.qnaDefinition().moreQuestionsBody(); foreach (var errorQuestionStr in questionsBody.errorQuestionString()) { if (!string.IsNullOrEmpty(errorQuestionStr.GetText().Trim())) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Invalid QnA question line, did you miss '-' at line begin", context: errorQuestionStr)); } } foreach (var question in questionsBody.moreQuestion()) { var questionText = question.GetText().Trim(); questions.Add(questionText.Substring(1).Trim()); } return(questions, errors); }
private string ExtractAnswer(LUFileParser.QnaSectionContext parseTree) { var multiLineAnswer = parseTree.qnaDefinition().qnaAnswerBody().multiLineAnswer().GetText().Trim(); // trim first and last line // TODO: validate this regex var answerRegexp = new Regex(@"^```(markdown)?\r*\n(?<answer>(.|\n|\r\n|\t| )*)\r?\n.*?```$", RegexOptions.IgnoreCase | RegexOptions.Multiline); var answer_match = answerRegexp.Match(multiLineAnswer); var answer_group = answer_match.Groups["answer"]; return(answer_group.Success ? answer_group.Value : string.Empty); }
private (List <PromptDefinition> promptDefinitions, List <string> promptTextList, List <Error> errors) ExtractPrompts(LUFileParser.QnaSectionContext parseTree) { var promptDefinitions = new List <PromptDefinition>(); var promptTextList = new List <string>(); var errors = new List <Error>(); var promptSection = parseTree.qnaDefinition().promptSection(); if (promptSection == null) { return(promptDefinitions, promptTextList : null, errors); } if (promptSection.errorFilterLine() != null) { foreach (var errorFilterLineStr in promptSection.errorFilterLine()) { if (!string.IsNullOrEmpty(errorFilterLineStr.GetText().Trim())) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Invalid QnA prompt line, expecting '-' prefix for each line.", context: errorFilterLineStr)); } } } foreach (var promptLine in promptSection.filterLine()) { var filterLineText = promptLine.GetText().Trim(); filterLineText = filterLineText.Substring(1).Trim(); promptTextList.Add(filterLineText); var promptConfigurationRegExp = new Regex(@"^\[(?<displayText>.*?)]\([ ]*\#[ ]*[ ?]*(?<linkedQuestion>.*?)\)[ ]*(?<contextOnly>\`context-only\`)?.*?$", RegexOptions.Multiline | RegexOptions.IgnoreCase); var splitLineMatch = promptConfigurationRegExp.Match(filterLineText); if (!splitLineMatch.Success) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Invalid QnA prompt definition. Unable to parse prompt. Please verify syntax as well as question link.", context: promptLine)); } promptDefinitions.Add( new PromptDefinition() { DisplayText = splitLineMatch.Groups["displayText"].Value, LinkedQuestion = splitLineMatch.Groups["linkedQuestion"].Value, ContextOnly = splitLineMatch.Groups["linkedQuestion"].Value }); } return(promptDefinitions, promptTextList, errors); }
private string ExtractSourceInfo(LUFileParser.QnaSectionContext parseTree) { var srcAssignment = parseTree.qnaDefinition().qnaSourceInfo(); if (srcAssignment != null) { var srcRegExp = new Regex(@"^[ ]*\>[ ]*!#[ ]*@qna.pair.source[ ]*=[ ]*(?<sourceInfo>.*?)$", RegexOptions.Multiline | RegexOptions.IgnoreCase); var srcMatch = srcRegExp.Match(srcAssignment.GetText().Trim()); return(srcMatch.Groups["sourceInfo"].Success ? srcMatch.Groups["sourceInfo"].Value : QNAGENERICSOURCE); } return(QNAGENERICSOURCE); }
private string ExtractAssignedId(LUFileParser.QnaSectionContext parseTree) { var idAssignment = parseTree.qnaDefinition().qnaIdMark(); if (idAssignment != null) { var idTextRegExp = new Regex(@"^\<a[ ]*id[ ]*=[ ]*[""\'](?<idCaptured>.*?)[""\'][ ]*>[ ]*\<\/a\>$", RegexOptions.Multiline | RegexOptions.IgnoreCase); var idTextMatch = idTextRegExp.Match(idAssignment.GetText().Trim()); return(idTextMatch.Groups["idCaptured"].Success ? idTextMatch.Groups["idCaptured"].Value : null); } return(null); }
private (List <QnaTuple> filterPairs, List <Error> errors) ExtractFilterPairs(LUFileParser.QnaSectionContext parseTree) { var filterPairs = new List <QnaTuple>(); var errors = new List <Error>(); var filterSection = parseTree.qnaDefinition().qnaAnswerBody().filterSection(); if (filterSection != null) { if (filterSection.errorFilterLine() != null) { foreach (var errorFilterLineStr in filterSection.errorFilterLine()) { if (!string.IsNullOrEmpty(errorFilterLineStr.GetText().Trim())) { errors.Add( Diagnostic.BuildDiagnostic( message: $"Invalid QnA filter line, did you miss '-' at line begin", context: errorFilterLineStr)); } } } foreach (var filterLine in filterSection.filterLine()) { var filterLineText = filterLine.GetText().Trim(); filterLineText = filterLineText.Substring(1).Trim(); var filterPair = filterLineText.Split('='); var key = filterPair[0].Trim(); var value = filterPair[1].Trim(); filterPairs.Add(new QnaTuple { Key = key, Value = value }); } } return(filterPairs, errors); }
private string ExtractQuestion(LUFileParser.QnaSectionContext parseTree) { return(parseTree.qnaDefinition().qnaQuestion().questionText().GetText().Trim()); }