Search in sources :

Example 36 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method whenQueryingForHas_AllowReferringToTheImplicitRelation.

@Test
public void whenQueryingForHas_AllowReferringToTheImplicitRelation() {
    Label title = Label.of("title");
    RelationshipType hasTitle = movieKB.tx().getType(HAS.getLabel(title));
    Role titleOwner = movieKB.tx().getSchemaConcept(HAS_OWNER.getLabel(title));
    Role titleValue = movieKB.tx().getSchemaConcept(HAS_VALUE.getLabel(title));
    Relationship implicitRelation = hasTitle.instances().iterator().next();
    ConceptId owner = implicitRelation.rolePlayers(titleOwner).iterator().next().getId();
    ConceptId value = implicitRelation.rolePlayers(titleValue).iterator().next().getId();
    Match query = qb.match(x.id(owner).has(title, y.id(value), r));
    assertThat(query, variable(r, contains(MatchableConcept.of(implicitRelation))));
}
Also used : Role(ai.grakn.concept.Role) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) RelationshipType(ai.grakn.concept.RelationshipType) ConceptId(ai.grakn.concept.ConceptId) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 37 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testMoviesHasHigherTmdbCount.

@Test
public void testMoviesHasHigherTmdbCount() {
    Match query = qb.match(x.has("tmdb-vote-count", lt(r)), var().has("title", "The Muppets").has("tmdb-vote-count", r));
    assertThat(query, variable(x, contains(chineseCoffee)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 38 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testDontHideImplicitTypesIfExplicitlyMentioned.

@Test
public void testDontHideImplicitTypesIfExplicitlyMentioned() {
    Match query = qb.match(x.sub(Schema.MetaSchema.THING.getLabel().getValue()).label(HAS.getLabel("title")));
    assertThat(query, variable(x, (Matcher) hasItem(hasTitle)));
}
Also used : Matcher(org.hamcrest.Matcher) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 39 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method whenQueryingForAResourceWhichHasItselfAsAResource_ReturnTheResource.

@Test
public void whenQueryingForAResourceWhichHasItselfAsAResource_ReturnTheResource() {
    Match query = weirdKB.tx().graql().match(var("x").has("name", var("x")));
    assertThat(query, variable(x, contains(hasValue("weird"))));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 40 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testHasVariable.

@Test
public void testHasVariable() {
    Match query = qb.match(var().has("title", "Godfather").has("tmdb-vote-count", x));
    assertThat(query, variable(x, contains(hasValue(1000L))));
}
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