Search in sources :

Example 1 with RuleStructure

use of com.vaticle.typedb.core.graph.structure.RuleStructure in project grakn by graknlabs.

the class LogicManager method getRule.

public Rule getRule(String label) {
    Rule rule = logicCache.rule().getIfPresent(label);
    if (rule != null)
        return rule;
    RuleStructure structure = graphMgr.schema().rules().get(label);
    if (structure != null)
        return logicCache.rule().get(structure.label(), l -> Rule.of(this, structure));
    return null;
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) TraversalEngine(com.vaticle.typedb.core.traversal.TraversalEngine) HashMap(java.util.HashMap) Map(java.util.Map) Collections.list(com.vaticle.typedb.common.collection.Collections.list) Comparator.comparing(java.util.Comparator.comparing) LinkedList(java.util.LinkedList) Label(com.vaticle.typedb.core.common.parameters.Label) Nullable(javax.annotation.Nullable) GraphManager(com.vaticle.typedb.core.graph.GraphManager) StringBuilders(com.vaticle.typedb.core.common.util.StringBuilders) TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) Set(java.util.Set) Pattern(com.vaticle.typeql.lang.pattern.Pattern) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) RuleExporter.writeRule(com.vaticle.typedb.core.logic.LogicManager.RuleExporter.writeRule) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) CONTRADICTORY_RULE_CYCLE(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.CONTRADICTORY_RULE_CYCLE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Conjunction(com.vaticle.typeql.lang.pattern.Conjunction) RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure) RuleExporter.writeRule(com.vaticle.typedb.core.logic.LogicManager.RuleExporter.writeRule)

Example 2 with RuleStructure

use of com.vaticle.typedb.core.graph.structure.RuleStructure in project grakn by graknlabs.

the class Rule method of.

public static Rule of(String label, com.vaticle.typeql.lang.pattern.Conjunction<? extends Pattern> when, com.vaticle.typeql.lang.pattern.variable.ThingVariable<?> then, GraphManager graphMgr, ConceptManager conceptMgr, LogicManager logicMgr) {
    RuleStructure structure = graphMgr.schema().rules().create(label, when, then);
    Rule rule = new Rule(structure, logicMgr);
    rule.conclusion().index();
    rule.validate(logicMgr, conceptMgr);
    return rule;
}
Also used : RuleStructure(com.vaticle.typedb.core.graph.structure.RuleStructure)

Aggregations

RuleStructure (com.vaticle.typedb.core.graph.structure.RuleStructure)2 Collections.list (com.vaticle.typedb.common.collection.Collections.list)1 ILLEGAL_STATE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE)1 CONTRADICTORY_RULE_CYCLE (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.CONTRADICTORY_RULE_CYCLE)1 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)1 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)1 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)1 Iterators.link (com.vaticle.typedb.core.common.iterator.Iterators.link)1 Label (com.vaticle.typedb.core.common.parameters.Label)1 StringBuilders (com.vaticle.typedb.core.common.util.StringBuilders)1 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)1 GraphManager (com.vaticle.typedb.core.graph.GraphManager)1 RuleExporter.writeRule (com.vaticle.typedb.core.logic.LogicManager.RuleExporter.writeRule)1 TypeInference (com.vaticle.typedb.core.logic.tool.TypeInference)1 TraversalEngine (com.vaticle.typedb.core.traversal.TraversalEngine)1 Conjunction (com.vaticle.typeql.lang.pattern.Conjunction)1 Pattern (com.vaticle.typeql.lang.pattern.Pattern)1 ThingVariable (com.vaticle.typeql.lang.pattern.variable.ThingVariable)1 Comparator.comparing (java.util.Comparator.comparing)1 HashMap (java.util.HashMap)1