Search in sources :

Example 11 with RoleType

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

the class ThingTypeSteps method thing_type_set_plays_role_throws_exception.

@When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label}; throws exception")
public void thing_type_set_plays_role_throws_exception(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) {
    RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.label());
    assertThrows(() -> get_thing_type(rootLabel, typeLabel).setPlays(roleType));
}
Also used : RoleType(com.vaticle.typedb.core.concept.type.RoleType) When(io.cucumber.java.en.When)

Example 12 with RoleType

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

the class UnifyRelationConcludableTest method addRolePlayer.

private void addRolePlayer(Relation relation, String role, Thing player) {
    RelationType relationType = relation.getType();
    RoleType roleType = relationType.getRelates(role);
    assert roleType != null : "Role type " + role + " does not exist in relation type " + relation.getType().getLabel();
    relation.addPlayer(roleType, player);
}
Also used : RoleType(com.vaticle.typedb.core.concept.type.RoleType) RelationType(com.vaticle.typedb.core.concept.type.RelationType)

Example 13 with RoleType

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

the class BasicTest method write_and_retrieve_relation_rule.

@Test
public void write_and_retrieve_relation_rule() throws IOException {
    Util.resetDirectory(dataDir);
    try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
        typedb.create(database);
        try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.SCHEMA)) {
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.WRITE)) {
                ConceptManager conceptMgr = txn.concepts();
                LogicManager logicMgr = txn.logic();
                EntityType person = conceptMgr.putEntityType("person");
                RelationType friendship = conceptMgr.putRelationType("friendship");
                friendship.setRelates("friend");
                RelationType marriage = conceptMgr.putRelationType("marriage");
                marriage.setRelates("spouse");
                person.setPlays(friendship.getRelates("friend"));
                person.setPlays(marriage.getRelates("spouse"));
                logicMgr.putRule("marriage-is-friendship", TypeQL.parsePattern("{$x isa person; $y isa person; (spouse: $x, spouse: $y) isa marriage; }").asConjunction(), TypeQL.parseVariable("(friend: $x, friend: $y) isa friendship").asThing());
                txn.commit();
            }
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.READ)) {
                ConceptManager conceptMgr = txn.concepts();
                LogicManager logicMgr = txn.logic();
                EntityType person = conceptMgr.getEntityType("person");
                RelationType friendship = conceptMgr.getRelationType("friendship");
                RoleType friend = friendship.getRelates("friend");
                RelationType marriage = conceptMgr.getRelationType("marriage");
                RoleType spouse = marriage.getRelates("spouse");
                Rule rule = logicMgr.getRule("marriage-is-friendship");
                Pattern when = rule.getWhenPreNormalised();
                ThingVariable<?> then = rule.getThenPreNormalised();
                assertEquals(TypeQL.parsePattern("{$x isa person; $y isa person; (spouse: $x, spouse: $y) isa marriage; }"), when);
                assertEquals(TypeQL.parseVariable("(friend: $x, friend: $y) isa friendship"), then);
            }
        }
    }
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) EntityType(com.vaticle.typedb.core.concept.type.EntityType) Pattern(com.vaticle.typeql.lang.pattern.Pattern) LogicManager(com.vaticle.typedb.core.logic.LogicManager) RoleType(com.vaticle.typedb.core.concept.type.RoleType) RelationType(com.vaticle.typedb.core.concept.type.RelationType) Rule(com.vaticle.typedb.core.logic.Rule) TypeDB(com.vaticle.typedb.core.TypeDB) Test(org.junit.Test)

Example 14 with RoleType

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

the class QueryTest method test_query_define.

@Test
public void test_query_define() throws IOException {
    Util.resetDirectory(dataDir);
    try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
        typedb.create(database);
        try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.SCHEMA)) {
            try (TypeDB.Transaction transaction = session.transaction(Arguments.Transaction.Type.WRITE)) {
                TypeQLDefine query = TypeQL.parseQuery(new String(Files.readAllBytes(Paths.get("test/integration/schema.tql")), UTF_8));
                transaction.query().define(query);
                transaction.commit();
            }
            try (TypeDB.Transaction tx = session.transaction(Arguments.Transaction.Type.READ)) {
                AttributeType.String name = tx.concepts().getAttributeType("name").asString();
                AttributeType.String symbol = tx.concepts().getAttributeType("symbol").asString();
                AttributeType.Boolean active = tx.concepts().getAttributeType("active").asBoolean();
                AttributeType.Long priority = tx.concepts().getAttributeType("priority").asLong();
                assertNotNulls(name, symbol, active, priority);
                EntityType organisation = tx.concepts().getEntityType("organisation");
                EntityType team = tx.concepts().getEntityType("team");
                EntityType user = tx.concepts().getEntityType("user");
                EntityType repository = tx.concepts().getEntityType("repository");
                EntityType branchRule = tx.concepts().getEntityType("branch-rule");
                EntityType commit = tx.concepts().getEntityType("commit");
                assertNotNulls(organisation, team, user, repository, branchRule, commit);
                assertTrue(organisation.getOwns().anyMatch(a -> a.equals(name)));
                assertTrue(team.getOwns().anyMatch(a -> a.equals(symbol)));
                assertTrue(user.getOwns().anyMatch(a -> a.equals(name)));
                assertTrue(repository.getOwns().anyMatch(a -> a.equals(active)));
                assertTrue(branchRule.getOwns().anyMatch(a -> a.equals(priority)));
                assertTrue(commit.getOwns().anyMatch(a -> a.equals(symbol)));
                RelationType orgTeam = tx.concepts().getRelationType("org-team");
                RelationType teamMember = tx.concepts().getRelationType("team-member");
                RelationType repoDependency = tx.concepts().getRelationType("repo-dependency");
                assertNotNulls(orgTeam, teamMember, repoDependency);
                RoleType orgTeam_org = orgTeam.getRelates("org");
                RoleType orgTeam_team = orgTeam.getRelates("team");
                RoleType teamMember_team = teamMember.getRelates("team");
                RoleType teamMember_member = teamMember.getRelates("member");
                assertNotNulls(orgTeam_org, orgTeam_team, teamMember_team, teamMember_member);
                assertTrue(organisation.getPlays().anyMatch(r -> r.equals(orgTeam_org)));
                assertTrue(team.getPlays().anyMatch(r -> r.equals(orgTeam_team)));
                assertTrue(team.getPlays().anyMatch(r -> r.equals(teamMember_team)));
                assertTrue(user.getPlays().anyMatch(r -> r.equals(teamMember_member)));
                // check first 4 rules
                assertNotNull(tx.logic().getRule("repo-fork-rule"));
                assertNotNull(tx.logic().getRule("repo-dependency-transitive-rule"));
                assertNotNull(tx.logic().getRule("repo-dependency-transitive-type-rule"));
                assertNotNull(tx.logic().getRule("repo-collaborator-org-rule"));
                // check total count
                assertEquals(15, tx.logic().rules().toList().size());
            }
        }
    }
}
Also used : TypeQLDelete(com.vaticle.typeql.lang.query.TypeQLDelete) TypeQLInsert(com.vaticle.typeql.lang.query.TypeQLInsert) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) Util.assertNotNulls(com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls) RelationType(com.vaticle.typedb.core.concept.type.RelationType) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) Path(java.nio.file.Path) TypeQLDefine(com.vaticle.typeql.lang.query.TypeQLDefine) TypeQL(com.vaticle.typeql.lang.TypeQL) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test) IOException(java.io.IOException) RoleType(com.vaticle.typedb.core.concept.type.RoleType) TypeDB(com.vaticle.typedb.core.TypeDB) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Database(com.vaticle.typedb.core.common.parameters.Options.Database) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) EntityType(com.vaticle.typedb.core.concept.type.EntityType) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) Entity(com.vaticle.typedb.core.concept.thing.Entity) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) RoleType(com.vaticle.typedb.core.concept.type.RoleType) TypeDB(com.vaticle.typedb.core.TypeDB) EntityType(com.vaticle.typedb.core.concept.type.EntityType) TypeQLDefine(com.vaticle.typeql.lang.query.TypeQLDefine) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) RelationType(com.vaticle.typedb.core.concept.type.RelationType) Test(org.junit.Test)

Example 15 with RoleType

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

the class ThingTypeSteps method thing_type_unset_plays_role.

@When("{root_label}\\( ?{type_label} ?) unset plays role: {scoped_label}")
public void thing_type_unset_plays_role(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) {
    RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.label());
    get_thing_type(rootLabel, typeLabel).unsetPlays(roleType);
}
Also used : RoleType(com.vaticle.typedb.core.concept.type.RoleType) When(io.cucumber.java.en.When)

Aggregations

RoleType (com.vaticle.typedb.core.concept.type.RoleType)21 RelationType (com.vaticle.typedb.core.concept.type.RelationType)11 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)7 TypeDB (com.vaticle.typedb.core.TypeDB)6 EntityType (com.vaticle.typedb.core.concept.type.EntityType)5 When (io.cucumber.java.en.When)5 List (java.util.List)5 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)4 Relation (com.vaticle.typedb.core.concept.thing.Relation)4 ThingType (com.vaticle.typedb.core.concept.type.ThingType)4 Test (org.junit.Test)4 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)2 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)2 TYPE_ROOT_MISMATCH (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_ROOT_MISMATCH)2 RELATION_ABSTRACT_ROLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_ABSTRACT_ROLE)2 RELATION_NO_ROLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_NO_ROLE)2 RELATION_RELATES_ROLE_FROM_SUPERTYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_FROM_SUPERTYPE)2 RELATION_RELATES_ROLE_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_NOT_AVAILABLE)2 ROOT_TYPE_MUTATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION)2