use of ai.grakn.graql.Match in project grakn by graknlabs.
the class QueryBuilderImpl method match.
/**
* @param patterns a collection of patterns to match in the knowledge base
* @return a {@link Match} that will find matches of the given patterns
*/
@Override
public Match match(Collection<? extends Pattern> patterns) {
Conjunction<PatternAdmin> conjunction = Patterns.conjunction(Sets.newHashSet(AdminConverter.getPatternAdmins(patterns)));
MatchBase base = new MatchBase(conjunction);
Match match = infer ? base.infer(materialise).admin() : base;
return tx.map(match::withTx).orElse(match);
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchModifierTest method testValueOrderedQuery.
@Test
public void testValueOrderedQuery() {
Var theMovie = var("the-movie");
Match match = qb.match(theMovie.isa("movie").has("title", n)).orderBy(n, desc);
assertResultsOrderedByValue(match, n, false);
// Make sure all results are included
assertThat(match, variable(theMovie, containsAllMovies));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method testLookupResourcesOnId.
@Test
public void testLookupResourcesOnId() {
Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
ConceptId id = godfather.getId();
Match query = qb.match(var().id(id).has("title", x));
assertThat(query, variable(x, contains(hasValue("Godfather"))));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method whenQueryingForResourcesWithEqualValues_ResultsAreCorrect.
@Test
public void whenQueryingForResourcesWithEqualValues_ResultsAreCorrect() {
Match query = qb.match(x.val(y));
assertThat(query, iterableWithSize(greaterThan(10)));
query.forEach(result -> {
Concept cx = result.get(x);
Concept cy = result.get(y);
assertEquals(cx.asAttribute().getValue(), cy.asAttribute().getValue());
});
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class MatchTest method testContainsQuery.
@Test
public void testContainsQuery() {
Match query = qb.match(x.isa("character").has("name", contains("ar")));
assertThat(query, variable(x, containsInAnyOrder(sarah, benjaminLWillard, harry)));
}
Aggregations