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);
}
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);
}
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);
}
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();
}
}
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();
}
Aggregations