use of ai.grakn.graql.internal.query.QueryAnswer in project grakn by graknlabs.
the class AtomicQueryTest method testWhenMaterialisingResources_MaterialisedInformationIsCorrectlyFlaggedAsInferred.
@Test
public void testWhenMaterialisingResources_MaterialisedInformationIsCorrectlyFlaggedAsInferred() {
EmbeddedGraknTx<?> graph = materialisationTestSet.tx();
QueryBuilder qb = graph.graql().infer(false);
Concept firstEntity = Iterables.getOnlyElement(qb.<GetQuery>parse("match $x isa entity1; get;").execute()).get("x");
Concept secondEntity = Iterables.getOnlyElement(qb.<GetQuery>parse("match $x isa entity2; get;").execute()).get("x");
Concept resource = Iterables.getOnlyElement(qb.<GetQuery>parse("match $x isa resource; get;").execute()).get("x");
ReasonerAtomicQuery resourceQuery = ReasonerQueries.atomic(conjunction("{$x has resource $r;$r val 'inferred';$x id " + firstEntity.getId().getValue() + ";}", graph), graph);
String reuseResourcePatternString = "{" + "$x has resource $r;" + "$x id " + secondEntity.getId().getValue() + ";" + "$r id " + resource.getId().getValue() + ";" + "}";
ReasonerAtomicQuery reuseResourceQuery = ReasonerQueries.atomic(conjunction(reuseResourcePatternString, graph), graph);
assertEquals(resourceQuery.materialise(new QueryAnswer()).findFirst().orElse(null).get("r").asAttribute().isInferred(), true);
reuseResourceQuery.materialise(new QueryAnswer()).collect(Collectors.toList());
assertEquals(Iterables.getOnlyElement(qb.<GetQuery>parse("match" + "$x has resource $r via $rel;" + "$x id " + secondEntity.getId().getValue() + ";" + "$r id " + resource.getId().getValue() + ";" + "get;").execute()).get("rel").asRelationship().isInferred(), true);
assertEquals(Iterables.getOnlyElement(qb.<GetQuery>parse("match" + "$x has resource $r via $rel;" + "$x id " + firstEntity.getId().getValue() + ";" + "$r id " + resource.getId().getValue() + ";" + "get;").execute()).get("rel").asRelationship().isInferred(), false);
}
use of ai.grakn.graql.internal.query.QueryAnswer in project grakn by graknlabs.
the class AtomicQueryTest method testWhenMaterialising_MaterialisedInformationIsPresentInGraph.
@Test
public void testWhenMaterialising_MaterialisedInformationIsPresentInGraph() {
EmbeddedGraknTx<?> graph = geoKB.tx();
QueryBuilder qb = graph.graql().infer(false);
String explicitQuery = "match (geo-entity: $x, entity-location: $y) isa is-located-in;$x has name 'Warsaw';$y has name 'Poland'; get;";
assertTrue(!qb.<GetQuery>parse(explicitQuery).iterator().hasNext());
String patternString = "{(geo-entity: $x, entity-location: $y) isa is-located-in;}";
Conjunction<VarPatternAdmin> pattern = conjunction(patternString, graph);
List<Answer> answers = new ArrayList<>();
answers.add(new QueryAnswer(ImmutableMap.of(var("x"), getConceptByResourceValue(graph, "Warsaw"), var("y"), getConceptByResourceValue(graph, "Poland"))));
ReasonerAtomicQuery atomicQuery = ReasonerQueries.atomic(pattern, graph);
assertNotExists(qb.parse(explicitQuery));
answers.forEach(atomicQuery::materialise);
assertExists(qb.parse(explicitQuery));
}
use of ai.grakn.graql.internal.query.QueryAnswer in project grakn by graknlabs.
the class AtomicQueryTest method testWhenMaterialisingEntity_MaterialisedInformationIsCorrectlyFlaggedAsInferred.
@Test
public void testWhenMaterialisingEntity_MaterialisedInformationIsCorrectlyFlaggedAsInferred() {
EmbeddedGraknTx<?> graph = materialisationTestSet.tx();
ReasonerAtomicQuery entityQuery = ReasonerQueries.atomic(conjunction("$x isa newEntity", graph), graph);
assertEquals(entityQuery.materialise(new QueryAnswer()).findFirst().orElse(null).get("x").asEntity().isInferred(), true);
}
use of ai.grakn.graql.internal.query.QueryAnswer in project grakn by graknlabs.
the class GetQueryPropertyTest method joinAnswer.
private Optional<Answer> joinAnswer(Answer answerA, Answer answerB) {
Map<Var, Concept> answer = Maps.newHashMap(answerA.map());
answer.putAll(answerB.map());
for (Var var : Sets.intersection(answerA.vars(), answerB.vars())) {
if (!answerA.get(var).equals(answerB.get(var))) {
return Optional.empty();
}
}
return Optional.of(new QueryAnswer(answer));
}
Aggregations