use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class MatchTest method whenQueryingForHas_AllowReferringToTheImplicitRelation.
@Test
public void whenQueryingForHas_AllowReferringToTheImplicitRelation() {
Label title = Label.of("title");
RelationshipType hasTitle = movieKB.tx().getType(HAS.getLabel(title));
Role titleOwner = movieKB.tx().getSchemaConcept(HAS_OWNER.getLabel(title));
Role titleValue = movieKB.tx().getSchemaConcept(HAS_VALUE.getLabel(title));
Relationship implicitRelation = hasTitle.instances().iterator().next();
ConceptId owner = implicitRelation.rolePlayers(titleOwner).iterator().next().getId();
ConceptId value = implicitRelation.rolePlayers(titleValue).iterator().next().getId();
Match query = qb.match(x.id(owner).has(title, y.id(value), r));
assertThat(query, variable(r, contains(MatchableConcept.of(implicitRelation))));
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenRelatingARole_TheDirectSubTypeRelatedRolesAreUnchanged.
@Property
public void whenRelatingARole_TheDirectSubTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
RelationshipType superType = subType.sup();
assumeFalse(isMetaLabel(superType.getLabel()));
Set<Role> previousHasRoles = subType.relates().collect(toSet());
superType.relates(role);
Set<Role> newHasRoles = subType.relates().collect(toSet());
assertEquals(previousHasRoles, newHasRoles);
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenDeletingARelatedRole_TheDirectSubTypeRelatedRolesAreUnchanged.
@Property
public void whenDeletingARelatedRole_TheDirectSubTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
RelationshipType superType = subType.sup();
assumeFalse(isMetaLabel(superType.getLabel()));
Set<Role> previousHasRoles = subType.relates().collect(toSet());
superType.deleteRelates(role);
Set<Role> newHasRoles = subType.relates().collect(toSet());
assertEquals(previousHasRoles, newHasRoles);
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class RelationshipTypePropertyTest method whenRelatingARole_TheDirectSuperTypeRelatedRolesAreUnchanged.
@Property
public void whenRelatingARole_TheDirectSuperTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
RelationshipType superType = subType.sup();
Set<Role> previousHasRoles = superType.relates().collect(toSet());
subType.relates(role);
Set<Role> newHasRoles = superType.relates().collect(toSet());
assertEquals(previousHasRoles, newHasRoles);
}
use of ai.grakn.concept.RelationshipType in project grakn by graknlabs.
the class ShortestPathTest method testMultipleIndependentShortestPaths.
@Test
public void testMultipleIndependentShortestPaths() throws InvalidKBException {
Set<List<ConceptId>> validPaths = new HashSet<>();
ConceptId startId;
ConceptId endId;
int numberOfPaths = 3;
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
EntityType entityType = graph.putEntityType(thing);
Role role1 = graph.putRole("role1");
Role role2 = graph.putRole("role2");
entityType.plays(role1).plays(role2);
RelationshipType relationshipType = graph.putRelationshipType(related).relates(role1).relates(role2);
Entity start = entityType.addEntity();
Entity end = entityType.addEntity();
startId = start.getId();
endId = end.getId();
// create N identical length paths
for (int i = 0; i < numberOfPaths; i++) {
List<ConceptId> validPath = new ArrayList<>();
validPath.add(startId);
Entity middle = entityType.addEntity();
ConceptId middleId = middle.getId();
ConceptId assertion1 = relationshipType.addRelationship().addRolePlayer(role1, start).addRolePlayer(role2, middle).getId();
validPath.add(assertion1);
validPath.add(middleId);
ConceptId assertion2 = relationshipType.addRelationship().addRolePlayer(role1, middle).addRolePlayer(role2, end).getId();
validPath.add(assertion2);
validPath.add(endId);
validPaths.add(validPath);
}
graph.commit();
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
List<List<Concept>> allPaths = graph.graql().compute().paths().from(startId).to(endId).execute();
assertEquals(numberOfPaths, allPaths.size());
Set<List<ConceptId>> computedPaths = allPaths.stream().map(path -> path.stream().map(Concept::getId).collect(Collectors.toList())).collect(Collectors.toSet());
assertEquals(validPaths, computedPaths);
}
}
Aggregations