Exemple #1
0
        private static void checkMultiValues(
            ICollection <SignValueStatement> statements,
            ITextContainer result,
            ISemanticNetwork semanticNetwork)
        {
            var clasifications = semanticNetwork.Statements.OfType <IsStatement>().ToList();

            foreach (var concept in semanticNetwork.Concepts)
            {
                var parents = clasifications.GetParentsOneLevel(concept);
                foreach (var sign in HasSignStatement.GetSigns(semanticNetwork.Statements, concept, true))
                {
                    if (statements.FirstOrDefault(sv => sv.Concept == concept && sv.Sign == sign.Sign) == null &&
                        parents.Select(p => SignValueStatement.GetSignValue(semanticNetwork.Statements, p, sign.Sign)).Count(r => r != null) > 1)
                    {
                        result.Append(
                            language => language.GetExtension <ILanguageSetModule>().Statements.Consistency.ErrorMultipleSignValue,
                            new Dictionary <String, IKnowledge>
                        {
                            { Semantics.Localization.Strings.ParamConcept, concept },
                            { Strings.ParamSign, sign.Sign },
                        });
                    }
                }
            }
        }
Exemple #2
0
 private static void writeSignDifference(ITextContainer result, SignValueStatement diff)
 {
     result.Append(language => language.GetExtension <ILanguageSetModule>().Questions.Answers.IsDescriptionWithSignValue, new Dictionary <String, IKnowledge>
     {
         { Strings.ParamSign, diff.Sign },
         { Strings.ParamValue, diff.Value },
     });
 }
Exemple #3
0
        private List <SignValueStatement> getDifferenceBetweenAncestorAndDescendant(List <IStatement> allStatements, IsStatement isStatement)
        {
            var difference = new List <SignValueStatement>();

            foreach (var sign in HasSignStatement.GetSigns(allStatements, isStatement.Ancestor, false))
            {
                var signValue = SignValueStatement.GetSignValue(allStatements, Concept, sign.Sign);
                if (signValue != null)
                {
                    difference.Add(signValue);
                }
            }
            return(difference);
        }
        public void TestBuildingSignValueStatement()
        {
            // arrange
            var language        = Language.Default;
            var semanticNetwork = new SemanticNetwork(language);

            var concept = ConceptCreationHelper.CreateConcept();
            var sign    = ConceptCreationHelper.CreateConcept();

            sign.WithAttribute(IsSignAttribute.Value);
            var value = ConceptCreationHelper.CreateConcept();

            value.WithAttribute(IsValueAttribute.Value);

            // act
            var statementByConstuctor         = new SignValueStatement(null, concept, sign, value);
            var statementByBuilderFromConcept = semanticNetwork.DeclareThat(concept).HasSignValue(sign, value);
            var statementByBuilderFromValue   = semanticNetwork.DeclareThat(value).IsSignValue(concept, sign);

            // assert
            Assert.AreEqual(statementByConstuctor, statementByBuilderFromConcept);
            Assert.AreEqual(statementByConstuctor, statementByBuilderFromValue);
        }
        public override IAnswer Process(IQuestionProcessingContext context)
        {
            var allStatements = context.SemanticNetwork.Statements.Enumerate(context.ActiveContexts).ToList();

            // get hierarchies
            var isStatements1 = new List <IsStatement>();
            var isStatements2 = new List <IsStatement>();
            var parents1      = allStatements.GetParentsAllLevels(Concept1, isStatements1);
            var parents2      = allStatements.GetParentsAllLevels(Concept2, isStatements2);

            // intersect parents
            var isStatements = new List <IsStatement>();
            var parents      = intersect(parents1, parents2, isStatements1, isStatements2, isStatements);

            if (parents.Count == 0)
            {
                return(new Semantics.Answers.Answer(
                           new FormattedText(
                               language => language.GetExtension <ILanguageSetModule>().Questions.Answers.CanNotCompareConcepts,
                               new Dictionary <String, IKnowledge>
                {
                    { Strings.ParamConcept1, Concept1 },
                    { Strings.ParamConcept2, Concept2 },
                }),
                           new Explanation(Array.Empty <IStatement>()),
                           true));
            }

            // get signs
            var allSignStatements = allStatements.OfType <HasSignStatement>().ToList();
            var signStatements1   = getAllSigns(allSignStatements, parents1);
            var signStatements2   = getAllSigns(allSignStatements, parents2);

            var signs = new HashSet <IConcept>(signStatements1.Select(s => s.Sign).Intersect(signStatements2.Select(s => s.Sign)));

            var signStatements = new List <HasSignStatement>();

            signStatements.AddRange(signStatements1.Where(s => signs.Contains(s.Sign)));
            signStatements.AddRange(signStatements2.Where(s => signs.Contains(s.Sign) && !signStatements.Contains(s)));

            // compare sign values
            var resultSignValues    = new Dictionary <IConcept, Tuple <IConcept, IConcept> >();
            var signValueStatements = new List <SignValueStatement>();

            foreach (var sign in signs)
            {
                var valueStatement1 = SignValueStatement.GetSignValue(allStatements, Concept1, sign);
                var valueStatement2 = SignValueStatement.GetSignValue(allStatements, Concept2, sign);
                var value1          = valueStatement1?.Value;
                var value2          = valueStatement2?.Value;

                if (NeedToTakeIntoAccount(value1, value2))
                {
                    resultSignValues[sign] = new Tuple <IConcept, IConcept>(value1, value2);
                    signValueStatements.Add(valueStatement1);
                    signValueStatements.Add(valueStatement2);
                }
            }

            // format final result
            var explanation = new List <IStatement>();

            explanation.AddRange(isStatements);
            explanation.AddRange(signStatements);
            explanation.AddRange(signValueStatements);

            return(new Semantics.Answers.ConceptsAnswer(
                       resultSignValues.Keys,
                       formatAnswer(parents, resultSignValues),
                       new Explanation(explanation)));
        }