use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class AtomicTest method testRuleApplicability_InstancesMakeRuleInapplicable_NoRoleTypes.
@Test
public void testRuleApplicability_InstancesMakeRuleInapplicable_NoRoleTypes() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
Concept concept = getConcept(graph, "name", "noRoleEntity");
String relationString = "{" + "($x, $y) isa ternary;" + "$x id '" + concept.getId().getValue() + "';" + "}";
Atom relation = ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
assertThat(relation.getApplicableRules().collect(toSet()), empty());
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ResolutionPlanTest method makeSureOptimalOrderPickedWhenResourcesWithSubstitutionsArePresent.
@Test
public void makeSureOptimalOrderPickedWhenResourcesWithSubstitutionsArePresent() {
EmbeddedGraknTx<?> testTx = testContext.tx();
Concept concept = testTx.graql().match(var("x").isa("baseEntity")).get("x").findAny().orElse(null);
String basePatternString = "(role1:$x, role2: $y) isa relation;" + "$x has resource 'this';" + "$y has anotherResource 'that';";
String xPatternString = "{" + "$x id '" + concept.getId() + "';" + basePatternString + "}";
String yPatternString = "{" + "$y id '" + concept.getId() + "';" + basePatternString + "}";
ReasonerQueryImpl queryX = ReasonerQueries.create(conjunction(xPatternString, testTx), testTx);
ReasonerQueryImpl queryY = ReasonerQueries.create(conjunction(yPatternString, testTx), testTx);
assertNotEquals(new ResolutionPlan(queryX).plan().get(0), getAtom(queryX, "anotherResource", testTx));
assertNotEquals(new ResolutionPlan(queryY).plan().get(0), getAtom(queryX, "resource", testTx));
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ExplanationTest method testExplainingQueryContainingContradiction2.
@Test
public void testExplainingQueryContainingContradiction2() {
GraknTx expGraph = explanationKB.tx();
QueryBuilder eiqb = expGraph.graql().infer(true);
Concept a1 = getConcept(expGraph, "name", "a1");
Concept a2 = getConcept(expGraph, "name", "a2");
String queryString = "match " + "(role1: $x, role2: $y) isa relation1;" + "$x id '" + a1.getId() + "';" + "$y id '" + a2.getId() + "'; get;";
GetQuery query = eiqb.parse(queryString);
List<Answer> answers = query.execute();
assertEquals(answers.size(), 0);
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GenealogyTest method checkResource.
private boolean checkResource(List<Answer> answers, String var, String value) {
boolean isOk = true;
Iterator<Answer> it = answers.iterator();
while (it.hasNext() && isOk) {
Concept c = it.next().get(Graql.var(var));
isOk = c.asAttribute().getValue().equals(value);
}
return isOk;
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ConceptPropertyTest method assumeDeletable.
private static void assumeDeletable(GraknTx graph, Concept concept) {
// TODO: A better way to handle these assumptions?
if (concept.isSchemaConcept()) {
SchemaConcept schemaConcept = concept.asSchemaConcept();
assumeThat(schemaConcept.subs().collect(toSet()), contains(schemaConcept));
if (schemaConcept.isType()) {
Type type = schemaConcept.asType();
assumeThat(type.instances().collect(toSet()), empty());
assumeThat(type.getRulesOfHypothesis().collect(toSet()), empty());
assumeThat(type.getRulesOfConclusion().collect(toSet()), empty());
}
if (schemaConcept.isRole()) {
Role role = schemaConcept.asRole();
assumeThat(role.playedByTypes().collect(toSet()), empty());
assumeThat(role.relationshipTypes().collect(toSet()), empty());
Stream<Relationship> allRelations = graph.admin().getMetaRelationType().instances();
Set<Role> allRolesPlayed = allRelations.flatMap(relation -> relation.allRolePlayers().keySet().stream()).collect(toSet());
assumeThat(allRolesPlayed, not(hasItem(role)));
} else if (schemaConcept.isRelationshipType()) {
assumeThat(schemaConcept.asRelationshipType().relates().collect(toSet()), empty());
}
}
}
Aggregations