public override IAnswer Process(IQuestionProcessingContext context)
        {
            var allStatements = context.SemanticNetwork.Statements.Enumerate(context.ActiveContexts);

            IEnumerable <IStatement> statements;
            var parentChild = Statement as IParentChild <IConcept>;

            if (parentChild != null)
            {
                statements = allStatements.FindPath(Statement.GetType(), parentChild.Parent, parentChild.Child);
            }
            else
            {
                var statement = allStatements.FirstOrDefault(p => p.Equals(Statement));
                statements = statement != null ? new[] { statement } : Array.Empty <IStatement>();
            }

            var result = new UnstructuredContainer();

            System.Boolean isTrue = statements.Any();
            result.Append(
                language => Strings.ParamAnswer,
                new Dictionary <String, IKnowledge> {
                { Strings.ParamAnswer, isTrue.ToLogicalValue() }
            });
            result.Append(isTrue ? Statement.DescribeTrue() : Statement.DescribeFalse());
            return(new BooleanAnswer(
                       isTrue,
                       result,
                       new Explanation(statements)));
        }
Exemple #2
0
        public static IText DescribeRules(this ISemanticNetwork semanticNetwork)
        {
            var result = new UnstructuredContainer();

            foreach (var statement in semanticNetwork.Statements)
            {
                result.Append(statement.DescribeTrue());
            }
            return(result);
        }
Exemple #3
0
        public static IText GetDescriptionWithExplanation(this IAnswer answer)
        {
            if (answer.Explanation.Statements.Count > 0)
            {
                var explanedResult = new UnstructuredContainer(answer.Description);

                explanedResult.AppendLineBreak();
                explanedResult.Append(new Text.Primitives.FormattedText(language => language.Questions.Answers.Explanation));

                foreach (var statement in answer.Explanation.Statements)
                {
                    explanedResult.Append(statement.DescribeTrue());
                }

                return(explanedResult);
            }
            else
            {
                return(answer.Description);
            }
        }
        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));
        }
Exemple #5
0
        public static IText CheckConsistency(this ISemanticNetwork semanticNetwork)
        {
            var result = new UnstructuredContainer();

            // 1. check all duplicates
            checkStatementDuplicates(semanticNetwork, result);

            // 2. check specific statements
            foreach (var statementDefinition in Repositories.Statements.Definitions.Values)
            {
                statementDefinition.CheckConsistency(semanticNetwork, result);
            }

            if (result.Items.Count == 0)
            {
                result.Append(language => language.Statements.Consistency.CheckOk);
            }
            return(result);
        }
Exemple #6
0
        private static StatementsAnswer <ProcessesStatement> createAnswer(ICollection <ProcessesStatement> statements, IQuestionProcessingContext <ProcessesQuestion> context, ICollection <IStatement> transitiveStatements = null)
        {
            var resultStatements = new HashSet <ProcessesStatement>();
            var text             = new UnstructuredContainer();

            foreach (var statement in statements)
            {
                var resultStatement = statement.SwapOperandsToMatchOrder(context.Question);
                if (resultStatements.All(s => s.SequenceSign != resultStatement.SequenceSign))
                {
                    resultStatements.Add(resultStatement);
                    text.Append(resultStatement.DescribeTrue());
                }
                addStatementConsequences(resultStatements, resultStatement, context);
            }

            var explanation = transitiveStatements == null
                                ? new Explanation(statements)
                                : new Explanation(transitiveStatements);

            return(new StatementsAnswer <ProcessesStatement>(resultStatements, text, explanation));
        }