Search in sources :

Example 51 with Match

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);
}
Also used : PatternAdmin(ai.grakn.graql.admin.PatternAdmin) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) MatchBase(ai.grakn.graql.internal.query.match.MatchBase) Match(ai.grakn.graql.Match)

Example 52 with 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));
}
Also used : Var(ai.grakn.graql.Var) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 53 with Match

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"))));
}
Also used : Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 54 with Match

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());
    });
}
Also used : Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 55 with Match

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)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Aggregations

Match (ai.grakn.graql.Match)103 Test (org.junit.Test)98 Var (ai.grakn.graql.Var)8 ConceptId (ai.grakn.concept.ConceptId)5 Concept (ai.grakn.concept.Concept)4 SchemaConcept (ai.grakn.concept.SchemaConcept)4 PatternAdmin (ai.grakn.graql.admin.PatternAdmin)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 AttributeType (ai.grakn.concept.AttributeType)3 Label (ai.grakn.concept.Label)3 Relationship (ai.grakn.concept.Relationship)3 Printer (ai.grakn.graql.Printer)3 QueryBuilder (ai.grakn.graql.QueryBuilder)3 Answer (ai.grakn.graql.admin.Answer)3 MatchableConcept (ai.grakn.matcher.MatchableConcept)3 Matcher (org.hamcrest.Matcher)3 RelationshipType (ai.grakn.concept.RelationshipType)2 Role (ai.grakn.concept.Role)2 Thing (ai.grakn.concept.Thing)2 GraqlQueryException (ai.grakn.exception.GraqlQueryException)2