use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class DeleteQueryTest method testDeleteAllRolePlayers.
@Test
public void testDeleteAllRolePlayers() {
ConceptId id = kurtzCastRelation.get("a").findFirst().get().getId();
Match relation = qb.match(var().id(id));
assertExists(kurtz);
assertExists(marlonBrando);
assertExists(apocalypseNow);
assertExists(relation);
kurtz.delete(x).execute();
assertNotExists(kurtz);
assertExists(marlonBrando);
assertExists(apocalypseNow);
assertExists(relation);
marlonBrando.delete(x).execute();
assertNotExists(kurtz);
assertNotExists(marlonBrando);
assertExists(apocalypseNow);
assertExists(relation);
apocalypseNow.delete(x).execute();
assertNotExists(kurtz);
assertNotExists(marlonBrando);
assertNotExists(apocalypseNow);
assertNotExists(relation);
}
use of ai.grakn.concept.ConceptId 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.ConceptId in project grakn by graknlabs.
the class GraknTxPropertyTest method whenCallingGetConceptWithAnIncorrectGeneric_ItThrows.
@Property
public void whenCallingGetConceptWithAnIncorrectGeneric_ItThrows(@Open GraknTx graph, @FromTx Concept concept) {
assumeFalse(concept.isRole());
ConceptId id = concept.getId();
exception.expect(ClassCastException.class);
// We have to assign the result for the cast to happen
// noinspection unused
Role role = graph.getConcept(id);
}
use of ai.grakn.concept.ConceptId 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);
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class ShortestPathTest method testResourceEdges.
@Test
public void testResourceEdges() {
ConceptId startId;
ConceptId endId;
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
EntityType person = graph.putEntityType("person");
AttributeType<String> name = graph.putAttributeType("name", AttributeType.DataType.STRING);
person.attribute(name);
Entity aPerson = person.addEntity();
startId = aPerson.getId();
Attribute<String> jason = name.putAttribute("jason");
aPerson.attribute(jason);
endId = jason.getId();
graph.commit();
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
List<List<Concept>> allPaths = graph.graql().compute().paths().from(startId).includeAttribute().to(endId).execute();
assertEquals(1, allPaths.size());
assertEquals(3, allPaths.get(0).size());
assertEquals("@has-name", allPaths.get(0).get(1).asRelationship().type().getLabel().getValue());
}
}
Aggregations