Search in sources :

Example 41 with QueryBuilder

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

the class ReasoningTests method reasoningWithNeqProperty.

// Expected result: 2 relations obtained by correctly finding reified relations
@Test
public void reasoningWithNeqProperty() {
    QueryBuilder qb = testSet27.tx().graql().infer(true);
    String queryString = "match (related-state: $s) isa holds; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> exact = qb.<GetQuery>parse("match $s isa state, has name 's2'; get;").execute();
    assertTrue(answers.containsAll(exact));
    assertTrue(exact.containsAll(answers));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 42 with QueryBuilder

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

the class ReasoningTests method ternaryRelationsRequiryingDifferentMultiunifiers.

@Test
public void ternaryRelationsRequiryingDifferentMultiunifiers() {
    QueryBuilder qb = testSet29.tx().graql().infer(true);
    String queryString = "match " + "(role1: $a, role2: $b, role3: $c) isa ternary-base;" + "get;";
    String queryString2 = "match " + "(role: $a, role2: $b, role: $c) isa ternary-base;" + "$b has name 'b';" + "get;";
    String queryString3 = "match " + "($r: $a) isa ternary-base;" + "get;";
    String queryString4 = "match " + "($r: $b) isa ternary-base;" + "$b has name 'b';" + "get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 27);
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(answers2.size(), 9);
    List<Answer> answers3 = qb.<GetQuery>parse(queryString3).execute();
    assertEquals(answers3.size(), 12);
    List<Answer> answers4 = qb.<GetQuery>parse(queryString4).execute();
    assertEquals(answers4.size(), 4);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 43 with QueryBuilder

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

the class ReasoningTests method reasoningWithEntityTypes.

// Expected result: Relations between all entity instances including relation between each instance and itself
@Test
public void reasoningWithEntityTypes() {
    QueryBuilder qb = testSet24.tx().graql().infer(true);
    QueryBuilder qbm = testSet24.tx().graql().infer(true);
    String queryString = "match (role1:$x1, role2:$x2) isa relation1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = qbm.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 9);
    assertEquals(answers2.size(), 9);
    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 44 with QueryBuilder

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

the class ReasoningTests method unificationWithVarDuplicates_SymmetricRelation.

// Expected result: Both queries should return a non-empty result, with $x/$y mapped to a unique entity.
@Test
public void unificationWithVarDuplicates_SymmetricRelation() {
    QueryBuilder qb = testSet1b.tx().graql().infer(true);
    String queryString = "match (symmetricRole: $x, symmetricRole: $x) isa relation1; get;";
    String queryString2 = "match (symmetricRole: $x, symmetricRole: $y) isa relation1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(2, answers.size());
    assertEquals(8, answers2.size());
    assertNotEquals(answers.size() * answers2.size(), 0);
    answers.forEach(x -> assertEquals(x.size(), 1));
    answers2.forEach(x -> assertEquals(x.size(), 2));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 45 with QueryBuilder

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

the class ReasoningTests method instanceTypeHierarchyRespected_queryOverwritesTypes.

// Expected result: Single answer obtained only if the rule query containing super type is correctly executed.
@Test
public void instanceTypeHierarchyRespected_queryOverwritesTypes() {
    QueryBuilder qb = testSet19.tx().graql().infer(true);
    String queryString = "match " + "$x isa subEntity1;" + "$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