Search in sources :

Example 41 with Concept

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());
}
Also used : Concept(ai.grakn.concept.Concept) Atom(ai.grakn.graql.internal.reasoner.atom.Atom) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) ResourceAtom(ai.grakn.graql.internal.reasoner.atom.binary.ResourceAtom) Test(org.junit.Test)

Example 42 with Concept

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));
}
Also used : Concept(ai.grakn.concept.Concept) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Example 43 with Concept

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);
}
Also used : Concept(ai.grakn.concept.Concept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 44 with Concept

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;
}
Also used : Concept(ai.grakn.concept.Concept) Answer(ai.grakn.graql.admin.Answer)

Example 45 with Concept

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());
        }
    }
}
Also used : Role(ai.grakn.concept.Role) FromTx(ai.grakn.generator.FromTxGenerator.FromTx) Assume.assumeThat(org.junit.Assume.assumeThat) Matchers.isA(org.hamcrest.Matchers.isA) Methods.mockParamsOf(ai.grakn.generator.Methods.mockParamsOf) Role(ai.grakn.concept.Role) Assume.assumeFalse(org.junit.Assume.assumeFalse) Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) MethodOf(ai.grakn.generator.Methods.MethodOf) RunWith(org.junit.runner.RunWith) Matchers.not(org.hamcrest.Matchers.not) Type(ai.grakn.concept.Type) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Open(ai.grakn.generator.GraknTxs.Open) NonMeta(ai.grakn.generator.AbstractSchemaConceptGenerator.NonMeta) JUnitQuickcheck(com.pholser.junit.quickcheck.runner.JUnitQuickcheck) GraknTx(ai.grakn.GraknTx) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) ExpectedException(org.junit.rules.ExpectedException) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) ErrorMessage(ai.grakn.util.ErrorMessage) Matchers.empty(org.hamcrest.Matchers.empty) Property(com.pholser.junit.quickcheck.Property) Set(java.util.Set) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) InvocationTargetException(java.lang.reflect.InvocationTargetException) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) GraknTxs.allConceptsFrom(ai.grakn.generator.GraknTxs.allConceptsFrom) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) Type(ai.grakn.concept.Type) Relationship(ai.grakn.concept.Relationship) SchemaConcept(ai.grakn.concept.SchemaConcept)

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