Search in sources :

Example 6 with QueryAnswers

use of ai.grakn.graql.internal.reasoner.query.QueryAnswers in project grakn by graknlabs.

the class QueryCacheTest method getUpdateRetrieveAnswerStream.

@Test
public void getUpdateRetrieveAnswerStream() {
    QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
    Answer answer = recordQuery.getQuery().stream().findFirst().orElse(null);
    Answer retrieveAnswer = answer.unify(recordToRetrieveUnifier);
    Answer retrieveSingleAnswer = singleAnswer.unify(recordToRetrieveUnifier);
    Stream<Answer> recordStream = cache.getAnswerStream(recordQuery);
    Stream<Answer> retrieveStream = cache.getAnswerStream(retrieveQuery);
    cache.recordAnswer(recordQuery, singleAnswer);
    QueryAnswers recordAnswers = new QueryAnswers(recordStream.collect(Collectors.toSet()));
    QueryAnswers retrieveAnswers = new QueryAnswers(retrieveStream.collect(Collectors.toSet()));
    // NB: not expecting the update in the stream
    assertTrue(recordAnswers.contains(answer));
    assertTrue(retrieveAnswers.contains(retrieveAnswer));
    assertFalse(recordAnswers.contains(singleAnswer));
    assertFalse(retrieveAnswers.contains(retrieveSingleAnswer));
    assertTrue(cache.getAnswers(recordQuery).contains(singleAnswer));
    assertTrue(cache.getAnswers(retrieveQuery).contains(retrieveSingleAnswer));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryCache(ai.grakn.graql.internal.reasoner.cache.QueryCache) LazyQueryCache(ai.grakn.graql.internal.reasoner.cache.LazyQueryCache) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) QueryAnswers(ai.grakn.graql.internal.reasoner.query.QueryAnswers) Test(org.junit.Test)

Example 7 with QueryAnswers

use of ai.grakn.graql.internal.reasoner.query.QueryAnswers in project grakn by graknlabs.

the class QueryCacheTest method recordUpdateRetrieveAnswers.

@Test
public void recordUpdateRetrieveAnswers() {
    QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
    cache.record(recordQuery, new QueryAnswers(recordQuery.getQuery().execute()));
    cache.recordAnswer(recordQuery, singleAnswer);
    assertTrue(cache.getAnswers(recordQuery).contains(singleAnswer));
    assertTrue(cache.getAnswers(retrieveQuery).contains(singleAnswer.unify(recordToRetrieveUnifier)));
}
Also used : QueryCache(ai.grakn.graql.internal.reasoner.cache.QueryCache) LazyQueryCache(ai.grakn.graql.internal.reasoner.cache.LazyQueryCache) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) QueryAnswers(ai.grakn.graql.internal.reasoner.query.QueryAnswers) Test(org.junit.Test)

Example 8 with QueryAnswers

use of ai.grakn.graql.internal.reasoner.query.QueryAnswers in project grakn by graknlabs.

the class QueryCacheTest method getRetrieveAnswerStream.

@Test
public void getRetrieveAnswerStream() {
    QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
    Answer answer = recordQuery.getQuery().stream().findFirst().orElse(null);
    Answer retrieveAnswer = answer.unify(recordToRetrieveUnifier);
    Stream<Answer> recordStream = cache.getAnswerStream(recordQuery);
    Stream<Answer> retrieveStream = cache.getAnswerStream(retrieveQuery);
    QueryAnswers recordAnswers = new QueryAnswers(recordStream.collect(Collectors.toSet()));
    QueryAnswers retrieveAnswers = new QueryAnswers(retrieveStream.collect(Collectors.toSet()));
    assertTrue(recordAnswers.contains(answer));
    assertTrue(retrieveAnswers.contains(retrieveAnswer));
}
Also used : Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryCache(ai.grakn.graql.internal.reasoner.cache.QueryCache) LazyQueryCache(ai.grakn.graql.internal.reasoner.cache.LazyQueryCache) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) QueryAnswers(ai.grakn.graql.internal.reasoner.query.QueryAnswers) Test(org.junit.Test)

Example 9 with QueryAnswers

use of ai.grakn.graql.internal.reasoner.query.QueryAnswers in project grakn by graknlabs.

the class QueryCacheTest method recordRetrieveAnswers.

@Test
public void recordRetrieveAnswers() {
    QueryCache<ReasonerAtomicQuery> cache = new QueryCache<>();
    QueryAnswers record = cache.record(recordQuery, new QueryAnswers(recordQuery.getQuery().execute()));
    assertEquals(record, cache.getAnswers(retrieveQuery).unify(retrieveToRecordUnifier));
    assertEquals(record, cache.getAnswers(recordQuery));
}
Also used : QueryCache(ai.grakn.graql.internal.reasoner.cache.QueryCache) LazyQueryCache(ai.grakn.graql.internal.reasoner.cache.LazyQueryCache) ReasonerAtomicQuery(ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery) QueryAnswers(ai.grakn.graql.internal.reasoner.query.QueryAnswers) Test(org.junit.Test)

Aggregations

QueryAnswers (ai.grakn.graql.internal.reasoner.query.QueryAnswers)9 LazyQueryCache (ai.grakn.graql.internal.reasoner.cache.LazyQueryCache)4 QueryCache (ai.grakn.graql.internal.reasoner.cache.QueryCache)4 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)4 Test (org.junit.Test)4 Answer (ai.grakn.graql.admin.Answer)3 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)3 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)3 MultiUnifierImpl (ai.grakn.graql.internal.reasoner.MultiUnifierImpl)2 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)2 ReasonerQueries (ai.grakn.graql.internal.reasoner.query.ReasonerQueries)1 ReasonerQueryImpl (ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1