Search in sources :

Example 6 with InsertQuery

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

Example 7 with InsertQuery

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

Example 8 with InsertQuery

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);
}
Also used : Pattern(ai.grakn.graql.Pattern) InsertQuery(ai.grakn.graql.InsertQuery) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 9 with InsertQuery

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

Example 10 with InsertQuery

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"));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Answer(ai.grakn.graql.admin.Answer) Var(ai.grakn.graql.Var) Test(org.junit.Test)

Aggregations

InsertQuery (ai.grakn.graql.InsertQuery)31 Test (org.junit.Test)29 Answer (ai.grakn.graql.admin.Answer)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 QueryBuilder (ai.grakn.graql.QueryBuilder)3 GraknTx (ai.grakn.GraknTx)2 ConceptId (ai.grakn.concept.ConceptId)2 Entity (ai.grakn.concept.Entity)2 Label (ai.grakn.concept.Label)2 Relationship (ai.grakn.concept.Relationship)2 SchemaConcept (ai.grakn.concept.SchemaConcept)2 DeleteQuery (ai.grakn.graql.DeleteQuery)2 Graql (ai.grakn.graql.Graql)2 Graql.label (ai.grakn.graql.Graql.label)2 Graql.var (ai.grakn.graql.Graql.var)2 Match (ai.grakn.graql.Match)2 VarPattern (ai.grakn.graql.VarPattern)2 Conjunction (ai.grakn.graql.admin.Conjunction)2 PatternAdmin (ai.grakn.graql.admin.PatternAdmin)2 MovieKB (ai.grakn.test.kbs.MovieKB)2