Search in sources :

Example 11 with Type

use of com.vaticle.typedb.core.concept.type.Type in project grakn by graknlabs.

the class UnifyRelationConcludableTest method relation_variable_multiple_identical_unifiers.

// [REFLEXIVE rule, Fewer roleplayers in parent]
@Test
public void relation_variable_multiple_identical_unifiers() {
    String conjunction = "{ (employee: $p) isa employment; }";
    Set<Concludable> concludables = Concludable.create(resolvedConjunction(conjunction, logicMgr));
    Concludable.Relation queryConcludable = concludables.iterator().next().asRelation();
    Rule rule = createRule("the-same-person-is-employed-twice", "{ $x isa person; $y isa person; $employment type employment; $employee type employment:employee; }", "($employee: $x, $employee: $x) isa $employment", logicMgr);
    FunctionalIterator<Unifier> unifier = queryConcludable.unify(rule.conclusion(), conceptMgr);
    Set<Map<String, Set<String>>> result = unifier.map(u -> getStringMapping(u.mapping())).toSet();
    Set<Map<String, Set<String>>> expected = set(new HashMap<String, Set<String>>() {

        {
            put("$p", set("$x"));
            put("$_0", set("$_0"));
        }
    });
    assertEquals(expected, result);
}
Also used : Variable(com.vaticle.typedb.core.traversal.common.Identifier.Variable) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) RelationType(com.vaticle.typedb.core.concept.type.RelationType) Util.getStringMapping(com.vaticle.typedb.core.logic.resolvable.Util.getStringMapping) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) LogicManager(com.vaticle.typedb.core.logic.LogicManager) ThingType(com.vaticle.typedb.core.concept.type.ThingType) After(org.junit.After) Map(java.util.Map) Collections.list(com.vaticle.typedb.common.collection.Collections.list) Thing(com.vaticle.typedb.core.concept.thing.Thing) Path(java.nio.file.Path) TypeQL(com.vaticle.typeql.lang.TypeQL) AfterClass(org.junit.AfterClass) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Options(com.vaticle.typedb.core.common.parameters.Options) Set(java.util.Set) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Collections.map(com.vaticle.typedb.common.collection.Collections.map) ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) ILLEGAL_STATE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE) Util.resolvedConjunction(com.vaticle.typedb.core.logic.resolvable.Util.resolvedConjunction) BeforeClass(org.junit.BeforeClass) Collections.set(com.vaticle.typedb.common.collection.Collections.set) HashMap(java.util.HashMap) Concept(com.vaticle.typedb.core.concept.Concept) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) Rule(com.vaticle.typedb.core.logic.Rule) Collections.pair(com.vaticle.typedb.common.collection.Collections.pair) Util.createRule(com.vaticle.typedb.core.logic.resolvable.Util.createRule) Label(com.vaticle.typedb.core.common.parameters.Label) Before(org.junit.Before) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) Iterator(java.util.Iterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) RoleType(com.vaticle.typedb.core.concept.type.RoleType) CoreSession(com.vaticle.typedb.core.database.CoreSession) Relation(com.vaticle.typedb.core.concept.thing.Relation) Paths(java.nio.file.Paths) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Type(com.vaticle.typedb.core.concept.type.Type) Util(com.vaticle.typedb.core.test.integration.util.Util) Set(java.util.Set) HashSet(java.util.HashSet) Rule(com.vaticle.typedb.core.logic.Rule) Util.createRule(com.vaticle.typedb.core.logic.resolvable.Util.createRule) Map(java.util.Map) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Type (com.vaticle.typedb.core.concept.type.Type)11 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)10 RelationType (com.vaticle.typedb.core.concept.type.RelationType)10 RoleType (com.vaticle.typedb.core.concept.type.RoleType)10 ThingType (com.vaticle.typedb.core.concept.type.ThingType)10 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)9 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)9 Collections.set (com.vaticle.typedb.common.collection.Collections.set)8 Label (com.vaticle.typedb.core.common.parameters.Label)8 Concept (com.vaticle.typedb.core.concept.Concept)8 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)8 Relation (com.vaticle.typedb.core.concept.thing.Relation)8 Variable (com.vaticle.typedb.core.traversal.common.Identifier.Variable)8 Collections (java.util.Collections)8 Lists (com.google.common.collect.Lists)7 Collections.list (com.vaticle.typedb.common.collection.Collections.list)7 Collections.map (com.vaticle.typedb.common.collection.Collections.map)7 Collections.pair (com.vaticle.typedb.common.collection.Collections.pair)7 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)7 ILLEGAL_STATE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.ILLEGAL_STATE)7