private (List <UtteranceAndEntitiesMap> utterances, List <Error> errors) ExtractUtterancesAndEntitiesMap(LUFileParser.SimpleIntentSectionContext parseTree) { var utterancesAndEntitiesMap = new List <UtteranceAndEntitiesMap>(); var errors = new List <Error>(); if (parseTree.intentDefinition().intentBody() != null && parseTree.intentDefinition().intentBody().normalIntentBody() != null) { foreach (var errorIntentStr in parseTree.intentDefinition().intentBody().normalIntentBody().errorString()) { if (!string.IsNullOrEmpty(errorIntentStr.GetText().Trim())) { errors.Add( Diagnostic.BuildDiagnostic( message: "Invalid intent body line, did you miss '-' at line begin?", context: errorIntentStr)); } } foreach (var normalIntentStr in parseTree.intentDefinition().intentBody().normalIntentBody().normalIntentString()) { UtteranceAndEntitiesMap utteranceAndEntities = null; try { utteranceAndEntities = Visitor.VisitNormalIntentStringContext(normalIntentStr); } catch { errors.Add( Diagnostic.BuildDiagnostic( message: "Invalid utterance definition found. Did you miss a '{' or '}'?", context: normalIntentStr)); } if (utteranceAndEntities != null) { utteranceAndEntities.ContextText = normalIntentStr.GetText(); var startPos = new Position { Line = normalIntentStr.Start.Line, Character = normalIntentStr.Start.Column }; var stopPos = new Position { Line = normalIntentStr.Stop.Line, Character = normalIntentStr.Stop.Column + normalIntentStr.Stop.Text.Length }; utteranceAndEntities.Range = new Range { Start = startPos, End = stopPos }; var markdownUrlMatch = Regex.Match(utteranceAndEntities.Utterance, @"^\[(?:[^\[]+)\]\((.*)\)$"); if (markdownUrlMatch.Success) { utteranceAndEntities.References = new Reference() { Source = markdownUrlMatch.Groups[1].Value }; } utterancesAndEntitiesMap.Add(utteranceAndEntities); foreach (var errorMsg in utteranceAndEntities.ErrorMsgs) { errors.Add( Diagnostic.BuildDiagnostic( message: errorMsg, context: normalIntentStr)); } } } } if (utterancesAndEntitiesMap.Count == 0) { var errorMsg = $"no utterances found for intent definition: \"# {this.Name}\""; var error = Diagnostic.BuildDiagnostic( message: errorMsg, context: parseTree.intentDefinition().intentNameLine(), severity: Diagnostic.WARN); errors.Add(error); } return(utterances : utterancesAndEntitiesMap, errors); }
private string ExtractIntentNameLine(LUFileParser.SimpleIntentSectionContext parseTree) { return(parseTree.intentDefinition().intentNameLine().GetText().Trim()); }