use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class QueryParserTest method testMatchInsertQuery.
@Test
public void testMatchInsertQuery() {
InsertQuery expected = match(var("x").isa("language")).insert(var("x").has("name", "HELLO"));
InsertQuery parsed = parse("match $x isa language; insert $x has name \"HELLO\";");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class QueryParserTest method testEscapeString.
@Test
public void testEscapeString() {
String unescaped = "This has \"double quotes\" and a single-quoted backslash: '\\'";
String escaped = "This has \\\"double quotes\\\" and a single-quoted backslash: \\'\\\\\\'";
InsertQuery expected = insert(var().isa("movie").has("title", unescaped));
InsertQuery parsed = parse("insert isa movie has title '" + escaped + "';");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class QueryParserTest method testInsertRules.
@Test
public void testInsertRules() {
String when = "$x isa movie;";
String then = "id '123' isa movie;";
Pattern whenPattern = and(var("x").isa("movie"));
Pattern thenPattern = and(var().id(ConceptId.of("123")).isa("movie"));
InsertQuery expected = insert(label("my-rule-thing").sub("rule"), var().isa("my-rule-thing").when(whenPattern).then(thenPattern));
InsertQuery parsed = parse("insert 'my-rule-thing' sub rule; \n" + "isa my-rule-thing, when {" + when + "}, then {" + then + "};");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class QueryParserTest method whenParsingInsertQuery_ResultIsSameAsJavaGraql.
@Test
public void whenParsingInsertQuery_ResultIsSameAsJavaGraql() {
InsertQuery expected = insert(var("x").has("name", "Pichu").isa("pokemon"), var("y").has("name", "Pikachu").isa("pokemon"), var("z").has("name", "Raichu").isa("pokemon"), var().rel("evolves-from", "x").rel("evolves-to", "y").isa("evolution"), var().rel("evolves-from", "y").rel("evolves-to", "z").isa("evolution"));
InsertQuery parsed = parse("insert " + "$x has name 'Pichu' isa pokemon;" + "$y has name 'Pikachu' isa pokemon;" + "$z has name 'Raichu' isa pokemon;" + "(evolves-from: $x ,evolves-to: $y) isa evolution;" + "(evolves-from: $y, evolves-to: $z) isa evolution;");
assertEquals(expected, parsed);
}
use of ai.grakn.graql.InsertQuery in project grakn by graknlabs.
the class InsertQueryTest method whenExecutingAnInsertQuery_ResultContainsAllInsertedVars.
@Test
public void whenExecutingAnInsertQuery_ResultContainsAllInsertedVars() {
Var x = var("x");
Var type = var("type");
// Note that two variables refer to the same type. They should both be in the result
InsertQuery query = qb.insert(x.isa(type), type.label("movie"));
Answer result = Iterables.getOnlyElement(query);
assertThat(result.vars(), containsInAnyOrder(x, type));
assertEquals(result.get(type), result.get(x).asEntity().type());
assertEquals(result.get(type).asType().getLabel(), Label.of("movie"));
}
Aggregations