Search in sources :

Example 56 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.

the class Rule method whenPattern.

private Conjunction whenPattern(com.vaticle.typeql.lang.pattern.Conjunction<? extends Pattern> conjunction, com.vaticle.typeql.lang.pattern.variable.ThingVariable<?> then, LogicManager logicMgr) {
    Disjunction when = Disjunction.create(conjunction.normalise(), VariableRegistry.createFromThings(list(then)));
    assert when.conjunctions().size() == 1;
    if (iterate(when.conjunctions().get(0).negations()).filter(neg -> neg.disjunction().conjunctions().size() != 1).hasNext()) {
        throw TypeDBException.of(INVALID_NEGATION_CONTAINS_DISJUNCTION, getLabel());
    }
    logicMgr.typeInference().applyCombination(when);
    return when.conjunctions().get(0);
}
Also used : RULE_THEN_INVALID_VALUE_ASSIGNMENT(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_THEN_INVALID_VALUE_ASSIGNMENT) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) LoggerFactory(org.slf4j.LoggerFactory) RelationType(com.vaticle.typedb.core.concept.type.RelationType) RULE_CONCLUSION_AMBIGUOUS_LABELLED_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_CONCLUSION_AMBIGUOUS_LABELLED_TYPE) COLON(com.vaticle.typeql.lang.common.TypeQLToken.Char.COLON) Map(java.util.Map) ValueConstraint(com.vaticle.typedb.core.pattern.constraint.thing.ValueConstraint) ThingConstraint(com.vaticle.typedb.core.pattern.constraint.thing.ThingConstraint) Collections.list(com.vaticle.typedb.common.collection.Collections.list) Thing(com.vaticle.typedb.core.concept.thing.Thing) THEN(com.vaticle.typeql.lang.common.TypeQLToken.Schema.THEN) NEW_LINE(com.vaticle.typeql.lang.common.TypeQLToken.Char.NEW_LINE) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) Negation(com.vaticle.typedb.core.pattern.Negation) IsaConstraint(com.vaticle.typedb.core.pattern.constraint.thing.IsaConstraint) Set(java.util.Set) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Pattern(com.vaticle.typeql.lang.pattern.Pattern) HasConstraint(com.vaticle.typedb.core.pattern.constraint.thing.HasConstraint) CURLY_OPEN(com.vaticle.typeql.lang.common.TypeQLToken.Char.CURLY_OPEN) List(java.util.List) RelationConstraint(com.vaticle.typedb.core.pattern.constraint.thing.RelationConstraint) Optional(java.util.Optional) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) RULE(com.vaticle.typeql.lang.common.TypeQLToken.Schema.RULE) ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) TraversalEngine(com.vaticle.typedb.core.traversal.TraversalEngine) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Variable(com.vaticle.typedb.core.pattern.variable.Variable) SEMICOLON(com.vaticle.typeql.lang.common.TypeQLToken.Char.SEMICOLON) HashMap(java.util.HashMap) Objects.className(com.vaticle.typedb.common.util.Objects.className) RULE_THEN_CANNOT_BE_SATISFIED(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_THEN_CANNOT_BE_SATISFIED) SPACE(com.vaticle.typeql.lang.common.TypeQLToken.Char.SPACE) RULE_CONCLUSION_ILLEGAL_INSERT(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_CONCLUSION_ILLEGAL_INSERT) Reference(com.vaticle.typeql.lang.pattern.variable.Reference) Concept(com.vaticle.typedb.core.concept.Concept) HashSet(java.util.HashSet) Concludable(com.vaticle.typedb.core.logic.resolvable.Concludable) Label(com.vaticle.typedb.core.common.parameters.Label) GraphManager(com.vaticle.typedb.core.graph.GraphManager) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) RelationTraversal(com.vaticle.typedb.core.traversal.RelationTraversal) Logger(org.slf4j.Logger) ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) Iterators(com.vaticle.typedb.core.common.iterator.Iterators) RULE_WHEN_CANNOT_BE_SATISFIED(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_WHEN_CANNOT_BE_SATISFIED) RoleType(com.vaticle.typedb.core.concept.type.RoleType) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) CURLY_CLOSE(com.vaticle.typeql.lang.common.TypeQLToken.Char.CURLY_CLOSE) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) INVALID_CASTING(com.vaticle.typedb.core.common.exception.ErrorMessage.Pattern.INVALID_CASTING) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) INVALID_NEGATION_CONTAINS_DISJUNCTION(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.INVALID_NEGATION_CONTAINS_DISJUNCTION) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) WHEN(com.vaticle.typeql.lang.common.TypeQLToken.Schema.WHEN) Disjunction(com.vaticle.typedb.core.pattern.Disjunction)

Example 57 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.

the class NegationResolver method initialiseDownstreamResolvers.

@Override
protected void initialiseDownstreamResolvers() {
    LOG.debug("{}: initialising downstream resolvers", name());
    Disjunction disjunction = negated.pattern();
    if (disjunction.conjunctions().size() == 1) {
        try {
            downstream = registry.nested(disjunction.conjunctions().get(0));
        } catch (TypeDBException e) {
            terminate(e);
        }
    } else {
        downstream = registry.nested(disjunction);
    }
    isInitialised = true;
}
Also used : Disjunction(com.vaticle.typedb.core.pattern.Disjunction) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException)

Aggregations

Disjunction (com.vaticle.typedb.core.pattern.Disjunction)57 Test (org.junit.Test)50 Set (java.util.Set)44 HashMap (java.util.HashMap)43 TypeInference (com.vaticle.typedb.core.logic.tool.TypeInference)42 Conjunction (com.vaticle.typedb.core.pattern.Conjunction)5 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)4 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)4 Collections.set (com.vaticle.typedb.common.collection.Collections.set)3 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)3 CoreTransaction (com.vaticle.typedb.core.database.CoreTransaction)3 Variable (com.vaticle.typedb.core.pattern.variable.Variable)3 Collections.list (com.vaticle.typedb.common.collection.Collections.list)2 Iterators (com.vaticle.typedb.core.common.iterator.Iterators)2 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)2 Context (com.vaticle.typedb.core.common.parameters.Context)2 Label (com.vaticle.typedb.core.common.parameters.Label)2 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)2