use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method whenParsingContainsPredicateWithAVariable_ResultMatchesJavaGraql.
@Test
public void whenParsingContainsPredicateWithAVariable_ResultMatchesJavaGraql() {
GetQuery expected = match(var("x").val(contains(var("y")))).get();
GetQuery parsed = parse("match $x val contains $y; get;");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method whenParsingAQueryAndDefiningAllVars_AllVarsExceptLabelsAreDefined.
@Test
public void whenParsingAQueryAndDefiningAllVars_AllVarsExceptLabelsAreDefined() {
QueryParser parser = Graql.parser();
parser.defineAllVars(true);
GetQuery query = parser.parseQuery("match ($x, $y) isa foo; get;");
System.out.println(query);
Conjunction<PatternAdmin> conjunction = query.match().admin().getPattern();
Set<PatternAdmin> patterns = conjunction.getPatterns();
VarPatternAdmin pattern = Iterables.getOnlyElement(patterns).asVarPattern();
assertTrue(pattern.var().isUserDefinedName());
IsaProperty property = pattern.getProperty(IsaProperty.class).get();
assertFalse(property.type().var().isUserDefinedName());
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method whenParsingDate_HandleSmallYears.
@Test
public void whenParsingDate_HandleSmallYears() {
GetQuery expected = match(var("x").has("release-date", LocalDate.of(867, 1, 1).atStartOfDay())).get();
GetQuery parsed = parse("match $x has release-date 0867-01-01; get;");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method whenParsingAsInMatch_ResultIsSameAsSub.
@Test
public void whenParsingAsInMatch_ResultIsSameAsSub() {
GetQuery expected = match(label("fatherhood").sub("parenthood").relates(var("x"), label("parent")).relates(label("son"), var("y"))).get();
GetQuery parsed = parse("match " + "fatherhood sub parenthood, relates $x as parent, relates son as $y; get;");
assertEquals(expected, parsed);
assertEquals(expected, parse(expected.toString()));
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class QueryParserTest method testPredicateQuery3.
@Test
public void testPredicateQuery3() {
GetQuery expected = match(var().rel("x").rel("y"), var("y").isa("person").has("name", var("n")), or(var("n").val(contains("ar")), var("n").val(regex("^M.*$")))).get();
GetQuery parsed = parse("match ($x, $y); $y isa person, has name $n;" + "$n val contains 'ar' or $n val /^M.*$/; get;");
assertEquals(expected, parsed);
}
Aggregations