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));
}
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);
}
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);
}
}
}
}
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());
}
}
}
}
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);
}
Aggregations