use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class DiagonalKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx tx, int n, int m) {
Role relFrom = tx.getRole("rel-from");
Role relTo = tx.getRole("rel-to");
EntityType entity1 = tx.getEntityType("entity1");
RelationshipType horizontal = tx.getRelationshipType("horizontal");
RelationshipType vertical = tx.getRelationshipType("vertical");
ConceptId[][] instanceIds = new ConceptId[n][m];
long inserts = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
instanceIds[i][j] = putEntityWithResource(tx, "a" + i + "," + j, entity1, key).getId();
inserts++;
if (inserts % 100 == 0)
System.out.println("inst inserts: " + inserts);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i < n - 1) {
vertical.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i + 1][j]));
inserts++;
}
if (j < m - 1) {
horizontal.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i][j + 1]));
inserts++;
}
if (inserts % 100 == 0)
System.out.println("rel inserts: " + inserts);
}
}
System.out.println("Extensional DB loaded.");
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class NguyenKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx graph, int n) {
Role Rfrom = graph.getRole("R-rA");
Role Rto = graph.getRole("R-rB");
Role qfrom = graph.getRole("Q-rA");
Role qto = graph.getRole("Q-rB");
Role Pfrom = graph.getRole("P-rA");
Role Pto = graph.getRole("P-rB");
EntityType entity = graph.getEntityType("entity2");
EntityType aEntity = graph.getEntityType("a-entity");
EntityType bEntity = graph.getEntityType("b-entity");
RelationshipType r = graph.getRelationshipType("R");
RelationshipType p = graph.getRelationshipType("P");
RelationshipType q = graph.getRelationshipType("Q");
ConceptId cId = putEntityWithResource(graph, "c", entity, key).getId();
ConceptId dId = putEntityWithResource(graph, "d", entity, key).getId();
ConceptId eId = putEntityWithResource(graph, "e", entity, key).getId();
ConceptId[] aInstancesIds = new ConceptId[n + 2];
ConceptId[] bInstancesIds = new ConceptId[n + 2];
aInstancesIds[n + 1] = putEntityWithResource(graph, "a" + (n + 1), aEntity, key).getId();
for (int i = 0; i <= n; i++) {
aInstancesIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
bInstancesIds[i] = putEntityWithResource(graph, "b" + i, bEntity, key).getId();
}
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(dId));
r.addRelationship().addRolePlayer(Rfrom, graph.getConcept(dId)).addRolePlayer(Rto, graph.getConcept(eId));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(eId)).addRolePlayer(qto, graph.getConcept(aInstancesIds[0]));
for (int i = 0; i <= n; i++) {
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(Pto, graph.getConcept(cId));
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstancesIds[i])).addRolePlayer(qto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(qto, graph.getConcept(aInstancesIds[i + 1]));
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class ShortestPathTest method testMultiplePathsSharing1Instance.
@Test
public void testMultiplePathsSharing1Instance() throws InvalidKBException {
ConceptId startId;
ConceptId endId;
Set<List<ConceptId>> correctPaths = new HashSet<>();
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 relationshipType1 = graph.putRelationshipType(related).relates(role1).relates(role2);
Role role3 = graph.putRole("role3");
Role role4 = graph.putRole("role4");
entityType.plays(role3).plays(role4);
RelationshipType relationshipType2 = graph.putRelationshipType(veryRelated).relates(role3).relates(role4);
Entity start = entityType.addEntity();
Entity end = entityType.addEntity();
Entity middle = entityType.addEntity();
startId = start.getId();
endId = end.getId();
ConceptId middleId = middle.getId();
ConceptId assertion11 = relationshipType1.addRelationship().addRolePlayer(role1, start).addRolePlayer(role2, middle).getId();
ConceptId assertion12 = relationshipType1.addRelationship().addRolePlayer(role1, middle).addRolePlayer(role2, end).getId();
ConceptId assertion21 = relationshipType2.addRelationship().addRolePlayer(role3, start).addRolePlayer(role4, middle).getId();
ConceptId assertion22 = relationshipType2.addRelationship().addRolePlayer(role3, middle).addRolePlayer(role4, end).getId();
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion22, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion22, endId));
graph.commit();
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
List<List<Concept>> allPaths = graph.graql().compute().paths().from(startId).to(endId).execute();
assertEquals(correctPaths.size(), allPaths.size());
Set<List<ConceptId>> computedPaths = allPaths.stream().map(path -> path.stream().map(Concept::getId).collect(Collectors.toList())).collect(Collectors.toSet());
assertEquals(correctPaths, computedPaths);
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class ShortestPathTest method testMultiplePathInSubGraph.
@Test
public void testMultiplePathInSubGraph() {
Set<List<ConceptId>> correctPaths = new HashSet<>();
List<List<Concept>> allPaths;
addSchemaAndEntities();
try (GraknTx graph = session.open(GraknTxType.READ)) {
if (GraknTestUtil.usingJanus()) {
// If no path is found in the vertex program, NoResultException is thrown to skip map reduce.
// Tinker doesn't handle this well, so the next graql query would find the graph is empty.
allPaths = graph.graql().compute().paths().in(thing, anotherThing).to(entityId1).from(entityId4).execute();
assertEquals(0, allPaths.size());
}
correctPaths.add(Lists.newArrayList(entityId1, relationId12, entityId2, relationId24, entityId4));
correctPaths.add(Lists.newArrayList(entityId1, relationId13, entityId3, relationId34, entityId4));
allPaths = graph.graql().compute().paths().from(entityId1).to(entityId4).execute();
assertEquals(correctPaths.size(), allPaths.size());
Set<List<ConceptId>> computedPaths = allPaths.stream().map(path -> path.stream().map(Concept::getId).collect(Collectors.toList())).collect(Collectors.toSet());
assertEquals(correctPaths, computedPaths);
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class DefineQueryTest method whenModifyingAThingInADefineQuery_Throw.
@Test
public void whenModifyingAThingInADefineQuery_Throw() {
ConceptId id = movies.tx().getEntityType("movie").instances().iterator().next().getId();
exception.expect(GraqlQueryException.class);
exception.expectMessage(anyOf(is(GraqlQueryException.defineUnsupportedProperty(HasAttributeProperty.NAME).getMessage()), is(GraqlQueryException.defineUnsupportedProperty(ValueProperty.NAME).getMessage())));
qb.define(var().id(id).has("title", "Bob")).execute();
}
Aggregations