Search in sources :

Example 46 with QueryBuilder

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

the class ReasoningTests method reusingResources_queryingForGenericRelation.

// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_queryingForGenericRelation() {
    QueryBuilder qb = testSet14.tx().graql().infer(true);
    String queryString = "match $x isa entity1;($x, $y); get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 3);
    assertEquals(answers.stream().filter(answer -> answer.get("y").isAttribute()).count(), 2);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 47 with QueryBuilder

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

the class ReasoningTests method reusingResources_usingExistingResourceToDefineResource.

// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_usingExistingResourceToDefineResource() {
    QueryBuilder qb = testSet14.tx().graql().infer(true);
    String queryString = "match $x isa entity1, has resource $y; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    String queryString2 = "match $x isa resource; get;";
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(answers.size(), 2);
    assertEquals(answers2.size(), 1);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 48 with QueryBuilder

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

the class ReasoningTests method reasoningOverRelationHierarchy.

// Expected result: Both queries should return a single equal match as they trigger the same rule.
@Test
public void reasoningOverRelationHierarchy() {
    QueryBuilder qb = testSet20.tx().graql().infer(true);
    String queryString = "match (role1: $x, role2: $y) isa relation1; get;";
    String queryString2 = "match (role1: $x, role2: $y) isa sub-relation1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(answers.size(), 1);
    assertTrue(answers.containsAll(answers2));
    assertTrue(answers2.containsAll(answers));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 49 with QueryBuilder

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

the class ReasoningTests method relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent.

@Test
public void relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent() {
    QueryBuilder qb = testSet28b.tx().graql().infer(true);
    String queryString = "match " + "$a isa entity1;" + "($a, $b); $b isa entity3;" + "($b, $c);" + "get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 4);
    answers.forEach(ans -> assertEquals(ans.size(), 3));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 50 with QueryBuilder

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

the class SNBInferenceTest method testBand.

@Test
public void testBand() {
    QueryBuilder qb = snbGraph.tx().graql().infer(false);
    QueryBuilder iqb = snbGraph.tx().graql().infer(true);
    String queryString = "match $x isa person;" + "($x, $y) isa recommendation;" + "$c isa category;$c has name 'Band';" + "($y, $c) isa grouping;" + "get $x, $y;";
    String explicitQuery = "match " + "{$x has name 'Charlie';{$y has name 'Cacophony';} or {$y has name 'Black Sabbath';};} or " + "{$x has name 'Gary';$y has name 'Pink Floyd';}; get $x, $y;";
    assertQueriesEqual(iqb.materialise(false).parse(queryString), qb.parse(explicitQuery));
    assertQueriesEqual(iqb.materialise(true).parse(queryString), qb.parse(explicitQuery));
}
Also used : QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

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