use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method testResourceMatch.
@Test
public void testResourceMatch() throws ParseException {
Match query = qb.match(x.has("release-date", LocalDate.of(1986, 3, 3).atStartOfDay()));
assertThat(query, variable(x, contains(spy)));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method testMovieQuery.
@Test
public void testMovieQuery() {
Match query = qb.match(x.isa("movie"));
assertThat(query, variable(x, containsAllMovies));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method testMatchAllPairs.
@Test
public void testMatchAllPairs() {
int numConcepts = (int) qb.match(x).stream().count();
Match pairs = qb.match(x, y);
// We expect there to be a result for every pair of concepts
assertThat(pairs, iterableWithSize(numConcepts * numConcepts));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class QueryToStringTest method whenCallingToStringOnAQueryWithAContainsPredicate_ResultIsCorrect.
@Test
public void whenCallingToStringOnAQueryWithAContainsPredicate_ResultIsCorrect() {
Match match = match(var("x").val(contains(var("y"))));
assertEquals("match $x val contains $y;", match.toString());
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchInfer method stream.
@Override
public Stream<Answer> stream(Optional<EmbeddedGraknTx<?>> optionalGraph) {
// If the tx is not embedded, treat it like there is no transaction
// TODO: this is dodgy - when queries don't contain transactions this can be fixed
EmbeddedGraknTx<?> tx = optionalOr(optionalGraph, inner.tx().filter(t -> t instanceof EmbeddedGraknTx).map(t -> (EmbeddedGraknTx<?>) t)).orElseThrow(GraqlQueryException::noTx);
if (!RuleUtils.hasRules(tx))
return inner.stream(optionalGraph);
validatePattern(tx);
try {
Iterator<Conjunction<VarPatternAdmin>> conjIt = getPattern().getDisjunctiveNormalForm().getPatterns().iterator();
Conjunction<VarPatternAdmin> conj = conjIt.next();
ReasonerQuery conjQuery = ReasonerQueries.create(conj, tx);
conjQuery.checkValid();
Stream<Answer> answerStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
while (conjIt.hasNext()) {
conj = conjIt.next();
conjQuery = ReasonerQueries.create(conj, tx);
Stream<Answer> localStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
answerStream = Stream.concat(answerStream, localStream);
}
return answerStream.map(result -> result.project(getSelectedNames()));
} catch (GraqlQueryException e) {
System.err.println(e.getMessage());
return Stream.empty();
}
}
Aggregations