private static StatementAnswer createAnswer(ComparisonStatement statement, IQuestionProcessingContext <ComparisonQuestion> context, ICollection <IStatement> transitiveStatements = null) { var resultStatement = statement.SwapOperandsToMatchOrder(context.Question); var text = new UnstructuredContainer(); text.Append(resultStatement.DescribeTrue()); var explanation = transitiveStatements == null ? new Explanation(statement) : new Explanation(transitiveStatements); return(new StatementAnswer(resultStatement, text, explanation)); }
public void ExplainPreconditions() { // arrange var language = Language.Default; var semanticNetwork = new SemanticNetwork(language); var concept1 = ConceptCreationHelper.CreateConcept(); concept1.WithAttribute(IsValueAttribute.Value); var concept2 = ConceptCreationHelper.CreateConcept(); concept2.WithAttribute(IsValueAttribute.Value); var concept3 = ConceptCreationHelper.CreateConcept(); concept3.WithAttribute(IsValueAttribute.Value); semanticNetwork.Concepts.Add(concept1); semanticNetwork.Concepts.Add(concept2); semanticNetwork.Concepts.Add(concept3); var initialComparison = semanticNetwork.DeclareThat(concept1).IsEqualTo(concept2); var preconditionComparison = new ComparisonStatement(null, concept2, concept3, ComparisonSigns.IsEqualTo); // ... and do not add it to semantic network // act var answerWithoutPreconditions = semanticNetwork.Ask().HowCompared(concept1, concept3); var answerWithPreconditions = semanticNetwork.Supposing(new IStatement[] { preconditionComparison }).Ask().HowCompared(concept1, concept3); // assert Assert.IsTrue(answerWithoutPreconditions.IsEmpty); Assert.AreEqual(0, answerWithoutPreconditions.Explanation.Statements.Count); Assert.IsFalse(answerWithPreconditions.IsEmpty); var resultComparison = (ComparisonStatement)((StatementAnswer)answerWithPreconditions).Result; Assert.AreSame(concept1, resultComparison.LeftValue); Assert.AreSame(concept3, resultComparison.RightValue); Assert.AreSame(ComparisonSigns.IsEqualTo, resultComparison.ComparisonSign); Assert.AreEqual(2, answerWithPreconditions.Explanation.Statements.Count); Assert.IsTrue(answerWithPreconditions.Explanation.Statements.Contains(initialComparison)); Assert.IsTrue(answerWithPreconditions.Explanation.Statements.Contains(preconditionComparison)); Assert.AreSame(initialComparison, semanticNetwork.Statements.Single()); }
public void TestBuildingPreconditions() { // arrange var language = Language.Default; var semanticNetwork = new TestSemanticNetwork(language); var numberMinus1 = ConceptCreationHelper.CreateConcept(); numberMinus1.WithAttribute(IsValueAttribute.Value); var precondition = new ComparisonStatement(null, numberMinus1, semanticNetwork.Number0, ComparisonSigns.IsLessThan); var preconditions = new IStatement[] { precondition }; // act var questionRegular = new ComparisonQuestion(numberMinus1, semanticNetwork.Number1, preconditions); var answerRegular = (StatementAnswer)questionRegular.Ask(semanticNetwork.SemanticNetwork.Context); var answerBuilder = (StatementAnswer)semanticNetwork.SemanticNetwork.Supposing(preconditions).Ask().HowCompared(numberMinus1, semanticNetwork.Number1); // assert Assert.AreEqual(answerRegular.Result, answerBuilder.Result); Assert.IsTrue(answerRegular.Explanation.Statements.SequenceEqual(answerBuilder.Explanation.Statements)); }