use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class QueryCacheTest method recordRetrieveSingleAnswer.
@Test
public void recordRetrieveSingleAnswer() {
QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
Answer answer = recordQuery.getQuery().stream().findFirst().orElse(null);
Answer retrieveAnswer = answer.unify(recordToRetrieveUnifier);
cache.recordAnswer(recordQuery, answer);
assertEquals(cache.getAnswer(recordQuery, new QueryAnswer()), new QueryAnswer());
assertEquals(cache.getAnswer(recordQuery, answer), answer);
assertEquals(cache.getAnswer(recordQuery, retrieveAnswer), answer);
assertEquals(cache.getAnswer(retrieveQuery, new QueryAnswer()), new QueryAnswer());
assertEquals(cache.getAnswer(retrieveQuery, retrieveAnswer), retrieveAnswer);
assertEquals(cache.getAnswer(retrieveQuery, answer), retrieveAnswer);
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class RecursiveInferenceTest method testNguyen.
/**
*test3 from Nguyen (similar to test 6.5 from Cao)
* N(x, y) :- R(x, y)
* N(x, y) :- P(x, z), N(z, w), Q(w, y)
*
* c -- P -- d -- R -- e -- Q -- a0
* \ /
* P Q
* \ \ /
* b0 -- Q -- a1
* \ /
* P Q
* \ /
* b1 -- Q -- a2
* .
* .
* .
* bN -- Q -- aN+1
*/
@Test
public void testNguyen() {
final int N = 9;
SampleKBContext kb = NguyenKB.context(N);
QueryBuilder qb = kb.tx().graql().infer(false);
QueryBuilder iqb = kb.tx().graql().infer(true);
String queryString = "match (N-rA: $x, N-rB: $y) isa N; $x has index 'c'; get $y;";
String explicitQuery = "match $y isa a-entity; get;";
List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
List<Answer> explicitAnswers = qb.<GetQuery>parse(explicitQuery).execute();
assertCollectionsEqual(answers, explicitAnswers);
List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
assertCollectionsEqual(answers, answers2);
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class GenealogyTest method testGrandParentship.
@Test
public void testGrandParentship() {
String queryString = "match " + "(grandchild: $x); (granddaughter: $x);$x has gender $g; get;";
GetQuery query = iqb.parse(queryString);
List<Answer> answers = query.execute();
assertEquals(answers.size(), 18);
assertTrue(checkResource(answers, "g", "female"));
assertCollectionsEqual(answers, qb.<GetQuery>parse(queryString).execute());
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class GenealogyTest method matchAllRelationsWithDocumentPlayingARole.
/*
test for first rule file:
match $x isa person has first-name $name;
match (child: $x, parent: $y) isa parentship;
match (spouse: $x, spouse: $y) isa marriage;
*/
@Test
public void matchAllRelationsWithDocumentPlayingARole() {
String queryString = "match $x isa document; ($x, $y); get;";
GetQuery query = iqb.parse(queryString);
List<Answer> answers = query.execute();
assertTrue(answers.isEmpty());
}
use of ai.grakn.graql.admin.Answer in project grakn by graknlabs.
the class GenealogyTest method testParentship.
@Test
public void testParentship() {
String queryString = "match (child: $c, parent: $p) isa parentship; get;";
GetQuery query = iqb.parse(queryString);
List<Answer> answers = query.execute();
assertEquals(answers.size(), 76);
assertTrue(!hasDuplicates(answers));
answers.forEach(answer -> assertEquals(answer.size(), 2));
}
Aggregations