use of com.vaticle.typedb.core.concept.type.RelationType in project grakn by graknlabs.
the class ConceptService method putRelationType.
private void putRelationType(String label, UUID reqID) {
RelationType relationType = conceptMgr.putRelationType(label);
transactionSvc.respond(putRelationTypeRes(reqID, relationType));
}
use of com.vaticle.typedb.core.concept.type.RelationType in project grakn by graknlabs.
the class ThingTypeSteps method thing_type_set_supertype_throws_exception.
@Then("{root_label}\\( ?{type_label} ?) set supertype: {type_label}; throws exception")
public void thing_type_set_supertype_throws_exception(RootLabel rootLabel, String typeLabel, String superLabel) {
switch(rootLabel) {
case ENTITY:
EntityType entitySuperType = tx().concepts().getEntityType(superLabel);
assertThrows(() -> tx().concepts().getEntityType(typeLabel).setSupertype(entitySuperType));
break;
case ATTRIBUTE:
AttributeType attributeSuperType = tx().concepts().getAttributeType(superLabel);
assertThrows(() -> tx().concepts().getAttributeType(typeLabel).setSupertype(attributeSuperType));
break;
case RELATION:
RelationType relationSuperType = tx().concepts().getRelationType(superLabel);
assertThrows(() -> tx().concepts().getRelationType(typeLabel).setSupertype(relationSuperType));
break;
}
}
use of com.vaticle.typedb.core.concept.type.RelationType 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.RelationType in project grakn by graknlabs.
the class ReasonerTest method test_relation_rule.
@Test
public void test_relation_rule() {
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.SCHEMA)) {
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
ConceptManager conceptMgr = txn.concepts();
LogicManager logicMgr = txn.logic();
EntityType person = conceptMgr.putEntityType("person");
AttributeType name = conceptMgr.putAttributeType("name", AttributeType.ValueType.STRING);
person.setOwns(name);
RelationType friendship = conceptMgr.putRelationType("friendship");
friendship.setRelates("friend");
RelationType marriage = conceptMgr.putRelationType("marriage");
marriage.setRelates("husband");
marriage.setRelates("wife");
person.setPlays(friendship.getRelates("friend"));
person.setPlays(marriage.getRelates("husband"));
person.setPlays(marriage.getRelates("wife"));
logicMgr.putRule("marriage-is-friendship", TypeQL.parsePattern("{ $x isa person; $y isa person; (husband: $x, wife: $y) isa marriage; }").asConjunction(), TypeQL.parseVariable("(friend: $x, friend: $y) isa friendship").asThing());
txn.commit();
}
}
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
txn.query().insert(TypeQL.parseQuery("insert $x isa person, has name 'Zack'; $y isa person, has name 'Yasmin'; (husband: $x, wife: $y) isa marriage;").asInsert());
txn.commit();
}
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.READ)) {
List<ConceptMap> ans = txn.query().match(TypeQL.parseQuery("match $f (friend: $p1, friend: $p2) isa friendship; $p1 has name $na;").asMatch()).toList();
ans.iterator().forEachRemaining(a -> {
assertEquals("friendship", a.get("f").asThing().getType().getLabel().scopedName());
assertEquals("person", a.get("p1").asThing().getType().getLabel().scopedName());
assertEquals("person", a.get("p2").asThing().getType().getLabel().scopedName());
assertEquals("name", a.get("na").asAttribute().getType().getLabel().scopedName());
});
assertEquals(2, ans.size());
}
}
}
use of com.vaticle.typedb.core.concept.type.RelationType in project grakn by graknlabs.
the class ExplanationTest method test_nested_explanations.
@Test
public void test_nested_explanations() {
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.SCHEMA)) {
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
ConceptManager conceptMgr = txn.concepts();
LogicManager logicMgr = txn.logic();
EntityType person = conceptMgr.putEntityType("person");
AttributeType name = conceptMgr.putAttributeType("name", AttributeType.ValueType.STRING);
AttributeType gender = conceptMgr.putAttributeType("gender", AttributeType.ValueType.STRING);
EntityType city = conceptMgr.putEntityType("city");
person.setOwns(name);
person.setOwns(gender);
RelationType friendship = conceptMgr.putRelationType("friendship");
friendship.setRelates("friend");
RelationType marriage = conceptMgr.putRelationType("marriage");
marriage.setRelates("husband");
marriage.setRelates("wife");
RelationType wedding = conceptMgr.putRelationType("wedding");
wedding.setRelates("male");
wedding.setRelates("female");
wedding.setRelates("location");
person.setPlays(friendship.getRelates("friend"));
person.setPlays(marriage.getRelates("husband"));
person.setPlays(marriage.getRelates("wife"));
person.setPlays(wedding.getRelates("male"));
person.setPlays(wedding.getRelates("female"));
city.setPlays(wedding.getRelates("location"));
logicMgr.putRule("wedding-implies-marriage", TypeQL.parsePattern("{ $x isa person, has gender \"male\"; $y isa person, has gender \"female\"; " + "$l isa city; (male: $x, female: $y, location: $l) isa wedding; }").asConjunction(), TypeQL.parseVariable("(husband: $x, wife: $y) isa marriage").asThing());
logicMgr.putRule("marriage-is-friendship", TypeQL.parsePattern("{ $a isa person; $b isa person; (husband: $a, wife: $b) isa marriage; }").asConjunction(), TypeQL.parseVariable("(friend: $a, friend: $b) isa friendship").asThing());
txn.commit();
}
}
try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
txn.query().insert(TypeQL.parseQuery("insert " + "(male: $x, female: $y, location: $l) isa wedding;" + "$x isa person, has gender \"male\";" + "$y isa person, has gender \"female\";" + "$l isa city;").asInsert());
txn.commit();
}
try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.READ, (new Options.Transaction().explain(true)))) {
List<ConceptMap> ans = txn.query().match(TypeQL.parseQuery("match ($x) isa friendship;").asMatch()).toList();
assertEquals(2, ans.size());
assertFalse(ans.get(0).explainables().isEmpty());
List<Explanation> explanations = assertSingleExplainableExplanations(ans.get(0), 1, 1, 1, txn);
Explanation explanation = explanations.get(0);
assertEquals(txn.logic().getRule("marriage-is-friendship"), explanation.rule());
assertEquals(2, explanation.variableMapping().size());
assertEquals(3, explanation.conclusionAnswer().concepts().size());
ConceptMap marriageIsFriendshipAnswer = explanation.conditionAnswer();
assertEquals(1, marriageIsFriendshipAnswer.explainables().iterator().count());
assertSingleExplainableExplanations(marriageIsFriendshipAnswer, 1, 1, 1, txn);
}
}
}
Aggregations