Search in sources :

Example 1 with WHEN

use of com.vaticle.typeql.lang.common.TypeQLToken.Schema.WHEN in project grakn by graknlabs.

the class Rule method pruneThenResolvedTypes.

/**
 * Remove type hints in the `then` pattern that are not valid in the `when` pattern
 */
private void pruneThenResolvedTypes() {
    then.variables().stream().filter(variable -> variable.id().isName()).forEach(thenVar -> {
        Variable whenVar = when.variable(thenVar.id());
        thenVar.retainInferredTypes(whenVar.inferredTypes());
        if (thenVar.inferredTypes().isEmpty())
            then.setCoherent(false);
    });
}
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) Variable(com.vaticle.typedb.core.pattern.variable.Variable) ThingVariable(com.vaticle.typedb.core.pattern.variable.ThingVariable) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 2 with WHEN

use of com.vaticle.typeql.lang.common.TypeQLToken.Schema.WHEN 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)

Aggregations

Collections.list (com.vaticle.typedb.common.collection.Collections.list)2 Collections.set (com.vaticle.typedb.common.collection.Collections.set)2 Objects.className (com.vaticle.typedb.common.util.Objects.className)2 ILLEGAL_STATE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE)2 INVALID_CASTING (com.vaticle.typedb.core.common.exception.ErrorMessage.Pattern.INVALID_CASTING)2 INVALID_NEGATION_CONTAINS_DISJUNCTION (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.INVALID_NEGATION_CONTAINS_DISJUNCTION)2 RULE_CONCLUSION_AMBIGUOUS_LABELLED_TYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_CONCLUSION_AMBIGUOUS_LABELLED_TYPE)2 RULE_CONCLUSION_ILLEGAL_INSERT (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_CONCLUSION_ILLEGAL_INSERT)2 RULE_THEN_CANNOT_BE_SATISFIED (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_THEN_CANNOT_BE_SATISFIED)2 RULE_THEN_INVALID_VALUE_ASSIGNMENT (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_THEN_INVALID_VALUE_ASSIGNMENT)2 RULE_WHEN_CANNOT_BE_SATISFIED (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.RULE_WHEN_CANNOT_BE_SATISFIED)2 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)2 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)2 Iterators (com.vaticle.typedb.core.common.iterator.Iterators)2 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)2 Label (com.vaticle.typedb.core.common.parameters.Label)2 Concept (com.vaticle.typedb.core.concept.Concept)2 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)2 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)2 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)2