internal static FragmentQueryProcessor Merge(FragmentQueryProcessor qp1, FragmentQueryProcessor qp2)
        {
            var mergedKB = new FragmentQueryKBChaseSupport();

            mergedKB.AddKnowledgeBase(qp1.KnowledgeBase);
            mergedKB.AddKnowledgeBase(qp2.KnowledgeBase);
            return(new FragmentQueryProcessor(mergedKB));
        }
        internal static FragmentQueryProcessor Merge(
            FragmentQueryProcessor qp1,
            FragmentQueryProcessor qp2)
        {
            FragmentQueryKBChaseSupport kb = new FragmentQueryKBChaseSupport();

            kb.AddKnowledgeBase((System.Data.Entity.Core.Common.Utils.Boolean.KnowledgeBase <DomainConstraint <BoolLiteral, Constant> >)qp1.KnowledgeBase);
            kb.AddKnowledgeBase((System.Data.Entity.Core.Common.Utils.Boolean.KnowledgeBase <DomainConstraint <BoolLiteral, Constant> >)qp2.KnowledgeBase);
            return(new FragmentQueryProcessor(kb));
        }
        private void CacheNormalizedImplication(
            TermExpr <DomainConstraint <BoolLiteral, Constant> > condition,
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > implies)
        {
            foreach (TermExpr <DomainConstraint <BoolLiteral, Constant> > key in this.Implications.Keys)
            {
                if (key.Identifier.Variable.Equals((object)condition.Identifier.Variable) && !key.Identifier.Range.SetEquals(condition.Identifier.Range))
                {
                    this.CacheResidualFact((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >(new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[2]
                    {
                        (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new NotExpr <DomainConstraint <BoolLiteral, Constant> >((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)condition),
                        implies
                    }));
                    return;
                }
            }
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > expr1 = new Converter <DomainConstraint <BoolLiteral, Constant> >(this.Chase(implies), IdentifierService <DomainConstraint <BoolLiteral, Constant> > .Instance.CreateConversionContext()).Dnf.Expr;
            FragmentQueryKBChaseSupport queryKbChaseSupport            = new FragmentQueryKBChaseSupport();

            queryKbChaseSupport.Implications[condition] = expr1;
            bool flag = true;

            foreach (TermExpr <DomainConstraint <BoolLiteral, Constant> > index in new Set <TermExpr <DomainConstraint <BoolLiteral, Constant> > >((IEnumerable <TermExpr <DomainConstraint <BoolLiteral, Constant> > >) this.Implications.Keys))
            {
                BoolExpr <DomainConstraint <BoolLiteral, Constant> > expr2 = queryKbChaseSupport.Chase(this.Implications[index]);
                if (index.Equals(condition))
                {
                    flag  = false;
                    expr2 = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[2]
                    {
                        expr2,
                        expr1
                    });
                }
                this.Implications[index] = new Converter <DomainConstraint <BoolLiteral, Constant> >(expr2, IdentifierService <DomainConstraint <BoolLiteral, Constant> > .Instance.CreateConversionContext()).Dnf.Expr;
            }
            if (flag)
            {
                this.Implications[condition] = expr1;
            }
            this._residueSize = -1;
        }
 internal NonNegatedDomainConstraintTreeVisitor(FragmentQueryKBChaseSupport kb)
 {
     this._kb = kb;
 }
 internal AtomicConditionRuleChase(FragmentQueryKBChaseSupport kb)
 {
     this._visitor = new FragmentQueryKBChaseSupport.AtomicConditionRuleChase.NonNegatedDomainConstraintTreeVisitor(kb);
 }
 public FragmentQueryProcessor(FragmentQueryKBChaseSupport kb)
 {
     _kb = kb;
 }
Beispiel #7
0
        // Requires condition to be atomic
        private void CacheNormalizedImplication(
            DomainTermExpr condition, DomainBoolExpr implies)
        {
            // Check that we do not have a rule with an inconsistent condition yet
            // such rules cannot be accommodated: we require rule premises to be pair wise
            // variable disjoint (note that the rules with coinciding conditions are merged)
            // rules with inconsistent conditions may make the chase incomplete:
            // For instance, consider the KB {c->a, b->c, !b->a} and the condition "!a".
            // chase(!a, KB) = !a, but !a ^ KB is unsatisfiable.

            foreach (var premise in Implications.Keys)
            {
                if (premise.Identifier.Variable.Equals(condition.Identifier.Variable)
                    &&
                    !premise.Identifier.Range.SetEquals(condition.Identifier.Range))
                {
                    CacheResidualFact(new OrExpr <DomainConstraint>(new NotExpr <DomainConstraint>(condition), implies));
                    return;
                }
            }

            // We first chase the implication with all the existing facts, and then
            // chase implications of all existing rules, and all residual facts with the
            // resulting enhanced rule

            var dnfImpl = new Converter <DomainConstraint>(
                Chase(implies),
                IdentifierService <DomainConstraint> .Instance.CreateConversionContext()).Dnf.Expr;

            // Now chase all our knowledge with the rule "condition => dnfImpl"

            // Construct a fake knowledge base for this sake
            var kb = new FragmentQueryKBChaseSupport();

            kb.Implications[condition] = dnfImpl;

            var newKey = true;

            foreach (var key in new Set <TermExpr <DomainConstraint> >(Implications.Keys))
            {
                var chasedRuleImpl = kb.Chase(Implications[key]);

                if (key.Equals(condition))
                {
                    newKey         = false;
                    chasedRuleImpl = new AndExpr <DomainConstraint>(chasedRuleImpl, dnfImpl);
                }

                // Simplify using the solver
                Implications[key] = new Converter <DomainConstraint>(
                    chasedRuleImpl,
                    IdentifierService <DomainConstraint> .Instance.CreateConversionContext()).Dnf.Expr;
            }

            if (newKey)
            {
                Implications[condition] = dnfImpl;
            }

            // Invalidate residue
            _residueSize = -1;
        }