Search in sources :

Example 46 with Answer

use of ai.grakn.graql.admin.Answer 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 47 with Answer

use of ai.grakn.graql.admin.Answer 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 48 with Answer

use of ai.grakn.graql.admin.Answer 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 49 with Answer

use of ai.grakn.graql.admin.Answer 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 50 with Answer

use of ai.grakn.graql.admin.Answer 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

Answer (ai.grakn.graql.admin.Answer)193 Test (org.junit.Test)164 QueryBuilder (ai.grakn.graql.QueryBuilder)104 GetQuery (ai.grakn.graql.GetQuery)69 GraknTx (ai.grakn.GraknTx)47 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)37 Concept (ai.grakn.concept.Concept)32 Var (ai.grakn.graql.Var)21 Set (java.util.Set)21 Unifier (ai.grakn.graql.admin.Unifier)19 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)18 Collectors (java.util.stream.Collectors)18 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)17 Sets (com.google.common.collect.Sets)16 List (java.util.List)16 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)15 Stream (java.util.stream.Stream)15 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)14 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)12