use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class InferenceRule method rewriteVariables.
private InferenceRule rewriteVariables(Atom parentAtom) {
if (parentAtom.isUserDefined() || parentAtom.requiresRoleExpansion()) {
ReasonerAtomicQuery rewrittenHead = ReasonerQueries.atomic(head.getAtom().rewriteToUserDefined(parentAtom));
List<Atom> bodyRewrites = new ArrayList<>();
body.getAtoms(Atom.class).map(at -> {
if (at.isRelation() && !at.isUserDefined() && Objects.equals(at.getSchemaConcept(), head.getAtom().getSchemaConcept())) {
return at.rewriteToUserDefined(parentAtom);
} else {
return at;
}
}).forEach(bodyRewrites::add);
ReasonerQueryImpl rewrittenBody = ReasonerQueries.create(bodyRewrites, tx);
return new InferenceRule(rewrittenHead, rewrittenBody, ruleId, tx);
}
return this;
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence_reifiedRelation.
// Bug #11150 Relations with resources as single VarPatternAdmin
// tests whether directly and indirectly reified relations are equivalent
@Test
public void testAlphaEquivalence_reifiedRelation() {
EmbeddedGraknTx<?> graph = genealogySchema.tx();
String patternString = "{$rel (happening: $b, protagonist: $p) isa event-protagonist has event-role 'parent';}";
String patternString2 = "{$rel (happening: $c, protagonist: $r) isa event-protagonist; $rel has event-role 'parent';}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
ReasonerQueryImpl query2 = ReasonerQueries.create(conjunction(patternString2, graph), graph);
queryEquivalence(query, query2, true);
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence_chainTreeAndLoopStructure.
// TODO
@Ignore
@Test
public void testAlphaEquivalence_chainTreeAndLoopStructure() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String chainString = "{" + "($x, $y) isa is-located-in;" + "($y, $z) isa is-located-in;" + "($z, $u) isa is-located-in;" + "}";
String treeString = "{" + "($x, $y) isa is-located-in;" + "($y, $z) isa is-located-in;" + "($y, $u) isa is-located-in;" + "}";
String loopString = "{" + "($x, $y) isa is-located-in;" + "($y, $z) isa is-located-in;" + "($z, $x) isa is-located-in;" + "}";
ReasonerQueryImpl chainQuery = ReasonerQueries.create(conjunction(chainString, graph), graph);
ReasonerQueryImpl treeQuery = ReasonerQueries.create(conjunction(treeString, graph), graph);
ReasonerQueryImpl loopQuery = ReasonerQueries.create(conjunction(loopString, graph), graph);
queryEquivalence(chainQuery, treeQuery, false);
queryEquivalence(chainQuery, loopQuery, false);
queryEquivalence(treeQuery, loopQuery, false);
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testQueryReiterationCondition_CyclicalRuleGraph.
@Test
public void testQueryReiterationCondition_CyclicalRuleGraph() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String patternString = "{($x, $y) isa is-located-in;}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
assertTrue(query.requiresReiteration());
}
use of ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl in project grakn by graknlabs.
the class QueryTest method testAlphaEquivalence_QueryCopyIsAlphaEquivalent.
// simple equality tests between original and a copy of a query
@Test
public void testAlphaEquivalence_QueryCopyIsAlphaEquivalent() {
EmbeddedGraknTx<?> graph = geoKB.tx();
String patternString = "{$x isa city;$y isa country;($x, $y) isa is-located-in;}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(patternString, graph), graph);
queryEquivalence(query, (ReasonerQueryImpl) query.copy(), true);
}
Aggregations