public string Run( string template, IDictionary <string, object> model) { if (template == null) { throw new ArgumentNullException(nameof(template)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } var output = new StringBuilder(); var reader = new StringReader(template); var currentLine = reader.ReadLine(); while (currentLine != null) { var statement = Statements.FirstOrDefault(_ => _.Accept(currentLine)); if (statement == null) { throw new Exception($"Not recognized statement: `{ statement }`."); } (output, reader) = statement.Execute(currentLine, reader, output, model); currentLine = reader.ReadLine(); } return(output.ToString().TrimEnd()); }
public IAnswer SelectFirstConcept( Func <StatementT, IConcept> resultConceptSelector, Func <ILanguage, String> answerFormat, Func <StatementT, IDictionary <String, IKnowledge> > getParameters) { ProcessChildrenIfNeed(); IAnswer answer = null; var statement = Statements.FirstOrDefault(); if (statement != null) { answer = new ConceptAnswer( resultConceptSelector(statement), new FormattedText( answerFormat, getParameters(statement)), new Explanation(Statements.OfType <IStatement>())); answer.Explanation.Expand(AdditionalTransitives); } if (answer == null) { var childAnswer = ChildAnswers.FirstOrDefault(); if (childAnswer != null) { childAnswer.Answer.Explanation.Expand(childAnswer.TransitiveStatements); answer = childAnswer.Answer; } } return(answer ?? Answer.CreateUnknown()); }
/// <summary> /// The first statement in the list or null if the list is empty. /// </summary> /// <returns></returns> public StatementSyntax FirstOrDefault() { return(Statements.FirstOrDefault()); }