use of ai.grakn.GraknTx in project grakn by graknlabs.
the class ReasonerTest method testReasoningWithQueryContainingRelationTypeVar.
@Test
public void testReasoningWithQueryContainingRelationTypeVar() {
GraknTx graph = nonMaterialisedGeoKB.tx();
String queryString = "match (geo-entity: $x) isa $type;$type label 'is-located-in'; get $x;";
String queryString2 = "match (geo-entity: $x, entity-location: $y)isa is-located-in; get $x;";
QueryBuilder iqb = graph.graql().infer(true);
GetQuery query = iqb.parse(queryString);
GetQuery query2 = iqb.parse(queryString2);
assertQueriesEqual(query, query2);
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class MigrationCLI method printWholeCompletionMessage.
public static void printWholeCompletionMessage(MigrationOptions options) {
System.out.println("Migration complete.");
if (options.isVerbose()) {
System.out.println("Gathering information about migrated data. If in a hurry, you can ctrl+c now.");
GraknTx graph = Grakn.session(options.getUri(), options.getKeyspace()).open(GraknTxType.WRITE);
QueryBuilder qb = graph.graql();
StringBuilder builder = new StringBuilder();
builder.append("Graph schema contains:\n");
builder.append("\t ").append(graph.admin().getMetaEntityType().instances().count()).append(" entity types\n");
builder.append("\t ").append(graph.admin().getMetaRelationType().instances().count()).append(" relation types\n");
builder.append("\t ").append(graph.admin().getMetaRole().subs().count()).append(" roles\n\n");
builder.append("\t ").append(graph.admin().getMetaAttributeType().instances().count()).append(" resource types\n");
builder.append("\t ").append(graph.admin().getMetaRule().subs().count()).append(" rules\n\n");
builder.append("Graph data contains:\n");
builder.append("\t ").append(qb.match(var("x").isa(label(ENTITY.getLabel()))).aggregate(count()).execute()).append(" entities\n");
builder.append("\t ").append(qb.match(var("x").isa(label(RELATIONSHIP.getLabel()))).aggregate(count()).execute()).append(" relations\n");
builder.append("\t ").append(qb.match(var("x").isa(label(ATTRIBUTE.getLabel()))).aggregate(count()).execute()).append(" resources\n");
builder.append("\t ").append(qb.match(var("x").isa(label(RULE.getLabel()))).aggregate(count()).execute()).append(" rules\n\n");
System.out.println(builder);
graph.close();
}
}
use of ai.grakn.GraknTx 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.GraknTx in project grakn by graknlabs.
the class BenchmarkIT method loadOntology.
private void loadOntology(String fileName, GraknSession session) {
try {
File graqlFile = new File(GraknSystemProperty.PROJECT_RELATIVE_DIR.value() + "/grakn-test-tools/src/main/graql/" + fileName);
String s = Files.toString(graqlFile, Charset.forName("UTF-8"));
GraknTx tx = session.open(GraknTxType.WRITE);
tx.graql().parser().parseQuery(s).execute();
tx.commit();
tx.close();
} catch (Exception e) {
System.err.println(e);
}
}
use of ai.grakn.GraknTx in project grakn by graknlabs.
the class MigratorTestUtils method getResources.
public static Stream<Attribute> getResources(GraknTx graph, Thing thing, Label label) {
Role roleOwner = graph.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(label));
Role roleOther = graph.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(label));
Stream<Relationship> relations = thing.relationships(roleOwner);
return relations.flatMap(r -> r.rolePlayers(roleOther)).map(Concept::asAttribute);
}
Aggregations