Search in sources :

Example 61 with QueryBuilder

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

the class ReasoningTests method relationTypesAreCorrectlyInferredInConjunction_TypeArePresent.

// Expected result: no answers (if types were incorrectly inferred the query would yield answers)
@Test
public void relationTypesAreCorrectlyInferredInConjunction_TypeArePresent() {
    QueryBuilder qb = testSet28.tx().graql().infer(true);
    String queryString = "match " + "(role1: $x, role2: $y) isa relation1;" + "(role1: $y, role2: $z) isa relation1;" + "(role3: $z, role4: $w) isa relation3; get;";
    assertThat(qb.<GetQuery>parse(queryString).execute(), empty());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 62 with QueryBuilder

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

the class ReasoningTests method generatingFreshEntity.

// TODO: currently disallowed by rule validation
@Ignore
// Expected result: The queries should return different matches, unique per query.
@Test
public void generatingFreshEntity() {
    QueryBuilder qb = testSet3.tx().graql().infer(true);
    String queryString = "match $x isa entity1; get;";
    String queryString2 = "match $x isa entity2; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(answers.size(), answers2.size());
    assertFalse(answers.containsAll(answers2));
    assertFalse(answers2.containsAll(answers));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 63 with QueryBuilder

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

the class ReasoningTests method circularRuleDependencies.

// Expected result: The query should return two unique matches
@Test
public void circularRuleDependencies() {
    QueryBuilder qb = testSet12.tx().graql().infer(true);
    String queryString = "match (role1:$x, role2:$y) isa relation3; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 2);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 64 with QueryBuilder

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

the class ReasoningTests method roleUnificationWithRoleHierarchiesInvolved.

// Expected result: The query should not return any matches (or possibly return a single match with $x=$y)
@Test
public void roleUnificationWithRoleHierarchiesInvolved() {
    QueryBuilder qb = testSet8.tx().graql().infer(true);
    String queryString = "match (role2:$x, role3:$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)

Example 65 with QueryBuilder

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

the class ReasoningTests method instanceTypeHierarchyRespected_queryHasSuperTypes_recursiveRule.

// Expected result: Two answers obtained only if the rule query containing sub type is correctly executed.
@Test
public void instanceTypeHierarchyRespected_queryHasSuperTypes_recursiveRule() {
    QueryBuilder qb = testSet19recursive.tx().graql().infer(true);
    String queryString = "match " + "$x isa entity1;" + "$y isa entity1;" + "(role1: $x, role2: $y) isa relation1;";
    String queryString2 = queryString + "$y has name 'a';";
    List<Answer> answers = qb.<GetQuery>parse(queryString + " get;").execute();
    assertEquals(answers.size(), 2);
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2 + " get;").execute();
    assertEquals(answers2.size(), 2);
}
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