Search in sources :

Example 1 with InsertQuery

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

the class DirectIsaTest method testInsertSyntax.

@Test
public void testInsertSyntax() {
    QueryBuilder queryBuilder = tx.graql();
    InsertQuery insertQuery;
    insertQuery = queryBuilder.insert(x.directIsa(thingy));
    assertEquals("insert $x isa! thingy;", insertQuery.toString());
    insertQuery = queryBuilder.parse("insert $x isa! thingy;");
    assertEquals(queryBuilder.insert(x.directIsa(thingy)), insertQuery);
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 2 with InsertQuery

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

the class AdminTest method testInsertQueryMatchPatternEmpty.

@Test
public void testInsertQueryMatchPatternEmpty() {
    InsertQuery query = qb.insert(var().id(ConceptId.of("123")).isa("movie"));
    assertFalse(query.admin().match().isPresent());
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Test(org.junit.Test)

Example 3 with InsertQuery

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

the class AdminTest method testInsertQueryWithMatch.

@Test
public void testInsertQueryWithMatch() {
    InsertQuery query = qb.match(var("x").isa("movie")).insert(var().id(ConceptId.of("123")).isa("movie"));
    assertEquals(Optional.of("match $x isa movie;"), query.admin().match().map(Object::toString));
    query = qb.match(var("x").directIsa("movie")).insert(var().id(ConceptId.of("123")).isa("movie"));
    assertEquals(Optional.of("match $x isa! movie;"), query.admin().match().map(Object::toString));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Test(org.junit.Test)

Example 4 with InsertQuery

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

the class AdminTest method testMatchInsertQueryGetTypes.

@Test
public void testMatchInsertQueryGetTypes() {
    InsertQuery query = qb.match(var("y").isa("movie")).insert(var("x").isa("person").has("name", var("z")), var().rel("actor", "x").isa("has-cast"));
    Set<SchemaConcept> types = Stream.of("movie", "person", "name", "actor", "has-cast").map(t -> rule.tx().<SchemaConcept>getSchemaConcept(Label.of(t))).collect(toSet());
    assertEquals(types, query.admin().getSchemaConcepts());
}
Also used : PatternAdmin(ai.grakn.graql.admin.PatternAdmin) DeleteQuery(ai.grakn.graql.DeleteQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) InsertQuery(ai.grakn.graql.InsertQuery) Graql(ai.grakn.graql.Graql) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) QueryBuilder(ai.grakn.graql.QueryBuilder) Graql.var(ai.grakn.graql.Graql.var) Conjunction(ai.grakn.graql.admin.Conjunction) Set(java.util.Set) Test(org.junit.Test) Graql.label(ai.grakn.graql.Graql.label) Sets(com.google.common.collect.Sets) MovieKB(ai.grakn.test.kbs.MovieKB) Match(ai.grakn.graql.Match) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) SampleKBContext(ai.grakn.test.rule.SampleKBContext) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) InsertQuery(ai.grakn.graql.InsertQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

Example 5 with InsertQuery

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

the class AdminTest method testInsertQueryGetTypes.

@Test
public void testInsertQueryGetTypes() {
    InsertQuery query = qb.insert(var("x").isa("person").has("name", var("y")), var().rel("actor", "x").isa("has-cast"));
    Set<SchemaConcept> types = Stream.of("person", "name", "actor", "has-cast").map(t -> rule.tx().<SchemaConcept>getSchemaConcept(Label.of(t))).collect(toSet());
    assertEquals(types, query.admin().getSchemaConcepts());
}
Also used : PatternAdmin(ai.grakn.graql.admin.PatternAdmin) DeleteQuery(ai.grakn.graql.DeleteQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) InsertQuery(ai.grakn.graql.InsertQuery) Graql(ai.grakn.graql.Graql) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) QueryBuilder(ai.grakn.graql.QueryBuilder) Graql.var(ai.grakn.graql.Graql.var) Conjunction(ai.grakn.graql.admin.Conjunction) Set(java.util.Set) Test(org.junit.Test) Graql.label(ai.grakn.graql.Graql.label) Sets(com.google.common.collect.Sets) MovieKB(ai.grakn.test.kbs.MovieKB) Match(ai.grakn.graql.Match) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) SampleKBContext(ai.grakn.test.rule.SampleKBContext) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) InsertQuery(ai.grakn.graql.InsertQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) 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