Search in sources :

Example 56 with Answer

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

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

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

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

Example 60 with Answer

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

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