Search in sources :

Example 21 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryWithNoRelationTypeWithRoles2.

@Test
public void testReasoningWithQueryWithNoRelationTypeWithRoles2() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa city;$y isa country;(geo-entity: $x, $y); get;";
    String queryString2 = "match $x isa city;$y isa country;" + "(geo-entity: $x, entity-location: $y) isa is-located-in; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 22 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryWithNoRelationTypeWithRoles.

@Test
public void testReasoningWithQueryWithNoRelationTypeWithRoles() {
    GraknTx graph = nonMaterialisedGeoKB.tx();
    String queryString = "match $x isa city;$y isa country;(geo-entity: $x, $y);$y has name 'Poland'; get;";
    String queryString2 = "match $x isa city;$y isa country;" + "(geo-entity: $x, entity-location: $y) isa is-located-in;$y has name 'Poland'; get;";
    QueryBuilder iqb = graph.graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 23 with QueryBuilder

use of ai.grakn.graql.QueryBuilder in project grakn by graknlabs.

the class ReasonerTest method testReasoningWithQueryContainingPlays2.

@Test
public void testReasoningWithQueryContainingPlays2() {
    String queryString = "match $x isa person;$y isa $type;$type plays recommended-product;($x, $y) isa recommendation; get;";
    String queryString2 = "match $x isa person;$y isa $type;{$type label 'product';} or {$type label 'tag';};($x, $y) isa recommendation; get;";
    QueryBuilder iqb = snbKB.tx().graql().infer(true);
    GetQuery query = iqb.parse(queryString);
    GetQuery query2 = iqb.parse(queryString2);
    assertQueriesEqual(query, query2);
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 24 with QueryBuilder

use of ai.grakn.graql.QueryBuilder 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);
}
Also used : GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 25 with QueryBuilder

use of ai.grakn.graql.QueryBuilder 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();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) QueryBuilder(ai.grakn.graql.QueryBuilder)

Aggregations

QueryBuilder (ai.grakn.graql.QueryBuilder)208 Test (org.junit.Test)202 Answer (ai.grakn.graql.admin.Answer)101 GetQuery (ai.grakn.graql.GetQuery)60 GraknTx (ai.grakn.GraknTx)51 SampleKBContext (ai.grakn.test.rule.SampleKBContext)20 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)18 Concept (ai.grakn.concept.Concept)16 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)9 Ignore (org.junit.Ignore)8 Var (ai.grakn.graql.Var)5 VarPattern (ai.grakn.graql.VarPattern)5 List (java.util.List)5 Label (ai.grakn.concept.Label)4 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)4 Sets (com.google.common.collect.Sets)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 RelationshipType (ai.grakn.concept.RelationshipType)3 Graql (ai.grakn.graql.Graql)3 Graql.var (ai.grakn.graql.Graql.var)3