Search in sources :

Example 56 with QueryBuilder

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

the class SNBInferenceTest method testVarConsistency3.

@Test
public void testVarConsistency3() {
    QueryBuilder qb = snbGraph.tx().graql().infer(false);
    QueryBuilder iqb = snbGraph.tx().graql().infer(true);
    String queryString = "match $x isa person;$pr isa product, has name 'Nocturnes';($x, $pr) isa recommendation; get $x;";
    String explicitQuery = "match {$x has name 'Frank';} or {$x has name 'Karl Fischer';}; get $x;";
    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)

Example 57 with QueryBuilder

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

the class ReasoningTests method reusingResources_definingResourceThroughOtherResourceWithConditionalValue.

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

Example 58 with QueryBuilder

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

the class ReasoningTests method reasoningWithRepeatingRoles.

// Expected result: Returns db and inferred relations + their inverses and relations with self for all entities
@Test
public void reasoningWithRepeatingRoles() {
    QueryBuilder qb = testSet22.tx().graql().infer(true);
    String queryString = "match (friend:$x1, friend:$x2) isa knows-trans; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 16);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 59 with QueryBuilder

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

the class ReasoningTests method whenReasoningWithResourcesWithRelationVar_ResultsAreComplete.

@Test
public void whenReasoningWithResourcesWithRelationVar_ResultsAreComplete() {
    QueryBuilder qb = testSet14.tx().graql().infer(true);
    VarPattern has = var("x").has(Label.of("resource"), var("y"), var("r"));
    List<Answer> answers = qb.match(has).get().execute();
    assertEquals(answers.size(), 3);
    answers.forEach(a -> assertTrue(a.vars().contains(var("r"))));
}
Also used : Answer(ai.grakn.graql.admin.Answer) VarPattern(ai.grakn.graql.VarPattern) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 60 with QueryBuilder

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

the class ReasoningTests method roleUnificationWithRepeatingRoleTypes.

// Expected result: The query should not return any matches (or possibly return a single match with $x=$y)
@Test
public void roleUnificationWithRepeatingRoleTypes() {
    QueryBuilder qb = testSet9.tx().graql().infer(true);
    String queryString = "match (role1:$x, role1:$y) isa relation2; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertThat(answers.stream().collect(toSet()), empty());
}
Also used : Answer(ai.grakn.graql.admin.Answer) 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