use of ai.grakn.graql.Match in project grakn by graknlabs.
the class DefineQueryTest method testDefineReferenceByName.
@Test
public void testDefineReferenceByName() {
String roleTypeLabel = HAS_OWNER.getLabel("title").getValue();
qb.define(label("new-type").sub(Schema.MetaSchema.ENTITY.getLabel().getValue()), label("new-type").plays(roleTypeLabel)).execute();
qb.insert(var("x").isa("new-type")).execute();
Match typeQuery = qb.match(var("n").label("new-type"));
assertEquals(1, typeQuery.stream().count());
// We checked count ahead of time
// noinspection OptionalGetWithoutIsPresent
EntityType newType = typeQuery.get("n").findFirst().get().asEntityType();
assertTrue(newType.plays().anyMatch(role -> role.equals(movies.tx().getRole(roleTypeLabel))));
assertExists(qb, var().isa("new-type"));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class DefineQueryTest method testDefineSubResourceType.
@Test
public void testDefineSubResourceType() {
qb.define(label("my-type").sub(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue()).datatype(AttributeType.DataType.STRING), label("sub-type").sub("my-type")).execute();
Match match = qb.match(var("x").label("sub-type"));
AttributeType.DataType datatype = match.iterator().next().get("x").asAttributeType().getDataType();
Assert.assertEquals(AttributeType.DataType.STRING, datatype);
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class DefineQueryTest method testResourceTypeRegex.
@Test
public void testResourceTypeRegex() {
qb.define(label("greeting").sub(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue()).datatype(AttributeType.DataType.STRING).regex("hello|good day")).execute();
Match match = qb.match(var("x").label("greeting"));
assertEquals("hello|good day", match.get("x").findFirst().get().asAttributeType().getRegex());
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class DeleteQueryTest method afterDeletingAllInstances_TheTypeCanBeUndefined.
@Test
public void afterDeletingAllInstances_TheTypeCanBeUndefined() {
Match movie = qb.match(x.isa("movie"));
assertNotNull(movieKB.tx().getEntityType("movie"));
assertExists(movie);
movie.delete(x).execute();
assertNotNull(movieKB.tx().getEntityType("movie"));
assertNotExists(movie);
qb.undefine(label("movie").sub("production")).execute();
assertNull(movieKB.tx().getEntityType("movie"));
}
use of ai.grakn.graql.Match in project grakn by graknlabs.
the class QueryErrorTest method testGetNonExistentVariable.
@Test
public void testGetNonExistentVariable() {
Match match = qb.match(var("x").isa("movie"));
Stream<Concept> concepts = match.get("y");
exception.expect(GraqlQueryException.class);
exception.expectMessage(ErrorMessage.VARIABLE_NOT_IN_QUERY.getMessage(Graql.var("y")));
// noinspection ResultOfMethodCallIgnored
concepts.count();
}
Aggregations