use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class BenchmarkIT method testMultiJoin.
/**
* Scalable multi-join test defined as a non-recursive tree of binary joins,
* which is expressed using the following inference rules:
*
* a(X,Y) :- b1(X,Z), b2(Z,Y).
* b1(X,Y) :- c1(X,Z), c2(Z,Y).
* b2(X,Y) :- c3(X,Z), c4(Z,Y).
* c1(X,Y) :- d1(X,Z), d2(Z,Y).
*
* The base relations, c2, c3, c4, d1 and d2 are randomly generated
* with 1/5 * N instances (reaching a total of N instances) each defined over 1/5 * N entities.
* The query is based on the final derived predicate.
*/
@Test
public void testMultiJoin() {
final int N = 10000;
final int limit = 100;
LOG.debug(new Object() {
}.getClass().getEnclosingMethod().getName());
loadJoinData(N);
try (GraknTx tx = session.open(GraknTxType.READ)) {
ConceptId entityId = tx.getEntityType("genericEntity").instances().findFirst().get().getId();
String queryPattern = "(fromRole: $x, toRole: $y) isa A;";
String queryString = "match " + queryPattern + " get;";
String subbedQueryString = "match " + queryPattern + "$x id '" + entityId.getValue() + "';" + "get;";
String subbedQueryString2 = "match " + queryPattern + "$y id '" + entityId.getValue() + "';" + "get;";
String limitedQueryString = "match " + queryPattern + "limit " + limit + ";" + "get;";
executeQuery(queryString, tx, "full");
executeQuery(subbedQueryString, tx, "first argument bound");
executeQuery(subbedQueryString2, tx, "second argument bound");
executeQuery(limitedQueryString, tx, "limit " + limit);
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class DegreeTest method testDegreesSimple.
@Test
public void testDegreesSimple() {
// create instances
EntityType thingy = tx.putEntityType("thingy");
EntityType anotherThing = tx.putEntityType("another");
ConceptId entity1 = thingy.addEntity().getId();
ConceptId entity2 = thingy.addEntity().getId();
ConceptId entity3 = thingy.addEntity().getId();
ConceptId entity4 = anotherThing.addEntity().getId();
Role role1 = tx.putRole("role1");
Role role2 = tx.putRole("role2");
thingy.plays(role1).plays(role2);
anotherThing.plays(role1).plays(role2);
RelationshipType related = tx.putRelationshipType("related").relates(role1).relates(role2);
// relate them
related.addRelationship().addRolePlayer(role1, tx.getConcept(entity1)).addRolePlayer(role2, tx.getConcept(entity2));
related.addRelationship().addRolePlayer(role1, tx.getConcept(entity2)).addRolePlayer(role2, tx.getConcept(entity3));
related.addRelationship().addRolePlayer(role1, tx.getConcept(entity2)).addRolePlayer(role2, tx.getConcept(entity4));
tx.commit();
tx = session.open(GraknTxType.READ);
Map<ConceptId, Long> correctDegrees = new HashMap<>();
correctDegrees.put(entity1, 1L);
correctDegrees.put(entity2, 3L);
correctDegrees.put(entity3, 1L);
correctDegrees.put(entity4, 1L);
// compute degrees
List<Long> list = new ArrayList<>(4);
long workerNumber = 4L;
if (GraknTestUtil.usingTinker())
workerNumber = 1L;
for (long i = 0L; i < workerNumber; i++) {
list.add(i);
}
tx.close();
Set<Map<Long, Set<String>>> result = list.parallelStream().map(i -> {
try (GraknTx graph = session.open(GraknTxType.READ)) {
return graph.graql().compute().centrality().usingDegree().execute();
}
}).collect(Collectors.toSet());
assertEquals(1, result.size());
Map<Long, Set<String>> degrees0 = result.iterator().next();
assertEquals(2, degrees0.size());
degrees0.forEach((key, value) -> value.forEach(id -> {
assertTrue(correctDegrees.containsKey(ConceptId.of(id)));
assertEquals(correctDegrees.get(ConceptId.of(id)), key);
}));
try (GraknTx graph = session.open(GraknTxType.READ)) {
Map<Long, Set<String>> degrees1 = graph.graql().compute().centrality().usingDegree().of("thingy").execute();
assertEquals(2, degrees1.size());
assertEquals(2, degrees1.get(1L).size());
assertEquals(1, degrees1.get(3L).size());
degrees1.forEach((key, value) -> value.forEach(id -> {
assertTrue(correctDegrees.containsKey(ConceptId.of(id)));
assertEquals(correctDegrees.get(ConceptId.of(id)), key);
}));
Map<Long, Set<String>> degrees2 = graph.graql().compute().centrality().usingDegree().of("thingy", "related").execute();
assertEquals(degrees1, degrees2);
degrees2 = graph.graql().compute().centrality().usingDegree().of().execute();
assertEquals(degrees0, degrees2);
// compute degrees on subgraph
Map<Long, Set<String>> degrees3 = graph.graql().compute().centrality().usingDegree().in("thingy", "related").execute();
assertEquals(degrees1, degrees3);
degrees3 = graph.graql().compute().centrality().usingDegree().of("thingy").in("related").execute();
assertEquals(degrees1, degrees3);
}
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class ConceptController method getConceptById.
private String getConceptById(Request request, Response response) throws JsonProcessingException {
Requests.validateRequest(request, APPLICATION_ALL, APPLICATION_JSON);
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
ConceptId conceptId = ConceptId.of(mandatoryPathParameter(request, ID_PARAMETER));
return getConcept(response, keyspace, (tx) -> tx.getConcept(conceptId));
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class CountPostProcessorTest method whenBreachingTheShardingThreshold_ShardingHappens.
@Test
public void whenBreachingTheShardingThreshold_ShardingHappens() {
// Configure mock to return value which breaches threshold
ConceptId id = ConceptId.of("e");
newInstanceCounts.put(id, 6L);
when(countStorage.incrementInstanceCount(keyspace, id, 6L)).thenReturn(6L);
when(countStorage.incrementInstanceCount(keyspace, id, 0L)).thenReturn(6L);
// Create fake commit log
CommitLog commitLog = CommitLog.create(keyspace, newInstanceCounts, Collections.emptyMap());
// Update The Counts
countPostProcessor.updateCounts(commitLog);
// Check Sharding Takes Place
verify(factoryMock, Mockito.times(1)).tx(keyspace, GraknTxType.WRITE);
verify(countStorage, Mockito.times(1)).incrementShardCount(keyspace, id, 1);
}
use of ai.grakn.concept.ConceptId in project grakn by graknlabs.
the class RemoteGraknTxTest method whenPuttingRole_EnsureCorrectRequestIsSent.
@Test
public void whenPuttingRole_EnsureCorrectRequestIsSent() {
ConceptId id = ConceptId.of(V123.getValue());
Label label = Label.of("foo");
try (RemoteGraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.READ))) {
// The open request
verify(server.requests()).onNext(any());
Concept concept = RemoteConcepts.createRole(tx, id);
server.setResponse(GrpcUtil.putRoleRequest(label), GrpcUtil.conceptResponse(concept));
assertEquals(concept, tx.putRole(label));
}
}
Aggregations