Search in sources :

Example 51 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class ReasoningTests method reusingResources_queryingForGenericRelation.

// Expected result: When the head of a rule contains resource assertions, the respective unique resources should be generated or reused.
@Test
public void reusingResources_queryingForGenericRelation() {
    QueryBuilder qb = testSet14.tx().graql().infer(true);
    String queryString = "match $x isa entity1;($x, $y); get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 3);
    assertEquals(answers.stream().filter(answer -> answer.get("y").isAttribute()).count(), 2);
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 52 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class ReasoningTests method reusingResources_usingExistingResourceToDefineResource.

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

Example 53 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class ReasoningTests method reasoningOverRelationHierarchy.

// Expected result: Both queries should return a single equal match as they trigger the same rule.
@Test
public void reasoningOverRelationHierarchy() {
    QueryBuilder qb = testSet20.tx().graql().infer(true);
    String queryString = "match (role1: $x, role2: $y) isa relation1; get;";
    String queryString2 = "match (role1: $x, role2: $y) isa sub-relation1; get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    List<Answer> answers2 = qb.<GetQuery>parse(queryString2).execute();
    assertEquals(answers.size(), 1);
    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 54 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class ReasoningTests method relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent.

@Test
public void relationTypesAreCorrectlyInferredInConjunction_TypesAreAbsent() {
    QueryBuilder qb = testSet28b.tx().graql().infer(true);
    String queryString = "match " + "$a isa entity1;" + "($a, $b); $b isa entity3;" + "($b, $c);" + "get;";
    List<Answer> answers = qb.<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 4);
    answers.forEach(ans -> assertEquals(ans.size(), 3));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 55 with Answer

use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.

the class SNBInferenceTest method testRecommendation.

@Test
public void testRecommendation() {
    QueryBuilder qb = snbGraph.tx().graql().infer(false);
    QueryBuilder iqb = snbGraph.tx().graql().infer(true);
    String queryString = "match $x isa person;($x, $y) isa recommendation; get;";
    String limitedQueryString = "match $x isa person;($x, $y) isa recommendation; limit 1; get;";
    GetQuery query = iqb.parse(queryString);
    GetQuery limitedQuery = iqb.parse(limitedQueryString);
    String explicitQuery = "match $x isa person;" + "{$x has name 'Alice';$y has name 'War of the Worlds';} or" + "{$x has name 'Bob';{$y has name 'Ducatti 1299';} or {$y has name 'The Good the Bad the Ugly';};} or" + "{$x has name 'Charlie';{$y has name 'Blizzard of Ozz';} or {$y has name 'Stratocaster';};} or " + "{$x has name 'Denis';{$y has name 'Colour of Magic';} or {$y has name 'Dorian Gray';};} or" + "{$x has name 'Frank';$y has name 'Nocturnes';} or" + "{$x has name 'Karl Fischer';{$y has name 'Faust';} or {$y has name 'Nocturnes';};} or " + "{$x has name 'Gary';$y has name 'The Wall';} or" + "{$x has name 'Charlie';" + "{$y has name 'Yngwie Malmsteen';} or {$y has name 'Cacophony';} or {$y has name 'Steve Vai';} or {$y has name 'Black Sabbath';};} or " + "{$x has name 'Gary';$y has name 'Pink Floyd';}; get;";
    long startTime = System.nanoTime();
    List<Answer> limitedAnswers = limitedQuery.execute();
    System.out.println("limited time: " + (System.nanoTime() - startTime) / 1e6);
    startTime = System.nanoTime();
    List<Answer> answers = query.execute();
    System.out.println("full time: " + (System.nanoTime() - startTime) / 1e6);
    assertCollectionsEqual(answers, qb.<GetQuery>parse(explicitQuery).execute());
    assertTrue(answers.containsAll(limitedAnswers));
}
Also used : Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) 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