Search in sources :

Example 31 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class GeoInferenceTest method testTransitiveQuery_variableRoles_withSubstitution_withRelationVar.

@Test
public void testTransitiveQuery_variableRoles_withSubstitution_withRelationVar() {
    GraknTx graph = geoKB.tx();
    QueryBuilder iqb = geoKB.tx().graql().infer(true);
    Concept masovia = getConcept(graph, "name", "Masovia");
    String queryString = "match " + "$x ($r1: $x1, $r2: $x2) isa is-located-in;" + "$x2 id '" + masovia.getId().getValue() + "'; get;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    assertEquals(answers.size(), 20);
    answers.forEach(ans -> assertEquals(ans.size(), 5));
    List<Answer> answers2 = iqb.materialise(true).<GetQuery>parse(queryString).execute();
    answers2.forEach(ans -> assertEquals(ans.size(), 5));
    assertCollectionsEqual(answers, answers2);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 32 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class GeoInferenceTest method testTransitiveQuery_withSpecificResource.

@Test
public void testTransitiveQuery_withSpecificResource() {
    GraknTx graph = geoKB.tx();
    QueryBuilder iqb = graph.graql().infer(true);
    String queryString = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y has name 'Poland'; get;";
    String queryString2 = "match " + "(geo-entity: $x, entity-location: $y) isa is-located-in;" + "$y has name 'Europe'; get;";
    Concept poland = getConcept(graph, "name", "Poland");
    Concept europe = getConcept(graph, "name", "Europe");
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    answers.forEach(ans -> assertEquals(ans.size(), 2));
    answers.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), poland.getId().getValue()));
    assertEquals(answers.size(), 6);
    List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
    answers2.forEach(ans -> assertEquals(ans.size(), 2));
    answers2.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), europe.getId().getValue()));
    assertEquals(answers2.size(), 21);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 33 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class GeoInferenceTest method testTransitiveQuery_withSubstitution_noRoles.

@Test
public void testTransitiveQuery_withSubstitution_noRoles() {
    GraknTx graph = geoKB.tx();
    QueryBuilder iqb = graph.graql().infer(true);
    Concept masovia = getConcept(graph, "name", "Masovia");
    String queryString = "match " + "($x, $y) isa is-located-in;" + "$y id '" + masovia.getId().getValue() + "'; get;";
    String queryString2 = "match " + "{(geo-entity: $x, entity-location: $y) isa is-located-in or " + "(geo-entity: $y, entity-location: $x) isa is-located-in;};" + "$y id '" + masovia.getId().getValue() + "'; get;";
    List<Answer> answers = iqb.materialise(false).<GetQuery>parse(queryString).execute();
    answers.forEach(ans -> assertEquals(ans.size(), 2));
    answers.forEach(ans -> assertEquals(ans.get(var("y")).getId().getValue(), masovia.getId().getValue()));
    assertEquals(answers.size(), 5);
    List<Answer> answers2 = iqb.materialise(false).<GetQuery>parse(queryString2).execute();
    assertCollectionsEqual(answers, answers2);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 34 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class TinkerQueryRunner method deleteResult.

private void deleteResult(Answer result, Collection<? extends Var> vars) {
    Collection<? extends Var> toDelete = vars.isEmpty() ? result.vars() : vars;
    for (Var var : toDelete) {
        Concept concept = result.get(var);
        if (concept.isSchemaConcept()) {
            throw GraqlQueryException.deleteSchemaConcept(concept.asSchemaConcept());
        }
        concept.delete();
    }
}
Also used : Concept(ai.grakn.concept.Concept) Var(ai.grakn.graql.Var)

Example 35 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class InsertQueryTest method whenSpecifyingExistingConceptIdWithIncorrectType_Throw.

@Test
public void whenSpecifyingExistingConceptIdWithIncorrectType_Throw() {
    EntityType movie = movieKB.tx().getEntityType("movie");
    EntityType person = movieKB.tx().getEntityType("person");
    Concept aMovie = movie.instances().iterator().next();
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(GraqlQueryException.insertPropertyOnExistingConcept("isa", person, aMovie).getMessage());
    movieKB.tx().graql().insert(var("x").id(aMovie.getId()).isa("person")).execute();
}
Also used : EntityType(ai.grakn.concept.EntityType) Concept(ai.grakn.concept.Concept) Test(org.junit.Test)

Aggregations

Concept (ai.grakn.concept.Concept)91 Test (org.junit.Test)56 ConceptId (ai.grakn.concept.ConceptId)26 GraknTx (ai.grakn.GraknTx)25 Answer (ai.grakn.graql.admin.Answer)25 SchemaConcept (ai.grakn.concept.SchemaConcept)19 Label (ai.grakn.concept.Label)18 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)18 QueryBuilder (ai.grakn.graql.QueryBuilder)17 Var (ai.grakn.graql.Var)15 Set (java.util.Set)15 Role (ai.grakn.concept.Role)14 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 HashSet (java.util.HashSet)13 List (java.util.List)12 AttributeType (ai.grakn.concept.AttributeType)11 EntityType (ai.grakn.concept.EntityType)11 Schema (ai.grakn.util.Schema)10 Collectors (java.util.stream.Collectors)10 Stream (java.util.stream.Stream)10