Search in sources :

Example 76 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class GraknTxJanusTest method whenDeletingAConcept_TheConceptIsDeleted.

@Test
public void whenDeletingAConcept_TheConceptIsDeleted() {
    Concept sacrifice = graknTx.putEntityType("sacrifice");
    assertFalse(sacrifice.isDeleted());
    sacrifice.delete();
    assertTrue(sacrifice.isDeleted());
}
Also used : Concept(ai.grakn.concept.Concept) Test(org.junit.Test)

Example 77 with Concept

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

Example 78 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class BenchmarkTests method testTransitiveMatrix.

/**
 * single-rule transitivity test with initial data arranged in a N x N square grid.
 * The rule is given as:
 *
 * (Q-from: $x, Q-to: $z) isa Q;
 * (Q-from: $z, Q-to: $y) isa Q;
 * ->
 * (Q-from: $x, Q-to: $y) isa Q;
 *
 * Each pair of neighbouring grid points is related in the following fashion:
 *
 *  a_{i  , j} -  Q  - a_{i, j + 1}
 *       |                    |
 *       Q                    Q
 *       |                    |
 *  a_{i+1, j} -  Q  - a_{i+1, j+1}
 *
 *  i e [0, N)
 *  j e [0, N)
 */
@Test
public void testTransitiveMatrix() {
    LOG.debug(new Object() {
    }.getClass().getEnclosingMethod().getName());
    final int N = 10;
    int limit = 100;
    // DJ       IC     FO
    // results @N = 15 14400     ?
    // results @N = 20 44100     ?       ?     12s     4 s
    // results @N = 25 105625    ?       ?     50s    11 s
    // results @N = 30 216225    ?       ?      ?     30 s
    // results @N = 35 396900   ?        ?      ?     76 s
    SampleKBContext kb = TransitivityMatrixKB.context(N, N);
    QueryBuilder iqb = kb.tx().graql().infer(true).materialise(false);
    // full result
    String queryString = "match (Q-from: $x, Q-to: $y) isa Q; get;";
    GetQuery query = iqb.parse(queryString);
    // with specific resource
    String queryString2 = "match (Q-from: $x, Q-to: $y) isa Q;$x has index 'a'; get;";
    GetQuery query2 = iqb.parse(queryString2);
    // with substitution
    Concept id = iqb.<GetQuery>parse("match $x has index 'a'; get;").execute().iterator().next().get("x");
    String queryString3 = "match (Q-from: $x, Q-to: $y) isa Q;$x id '" + id.getId().getValue() + "'; get;";
    GetQuery query3 = iqb.parse(queryString3);
    executeQuery(query, "full");
    executeQuery(query2, "With specific resource");
    executeQuery(query3, "Single argument bound");
    executeQuery(query.match().limit(limit).get(), "limit " + limit);
}
Also used : Concept(ai.grakn.concept.Concept) SampleKBContext(ai.grakn.test.rule.SampleKBContext) GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 79 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class MatchTest method whenQueryingForResourcesWithEqualValues_ResultsAreCorrect.

@Test
public void whenQueryingForResourcesWithEqualValues_ResultsAreCorrect() {
    Match query = qb.match(x.val(y));
    assertThat(query, iterableWithSize(greaterThan(10)));
    query.forEach(result -> {
        Concept cx = result.get(x);
        Concept cy = result.get(y);
        assertEquals(cx.asAttribute().getValue(), cy.asAttribute().getValue());
    });
}
Also used : Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 80 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class MatchTest method whenQueryingForTitlesWithEqualValues_ResultsAreCorrect.

@Test
public void whenQueryingForTitlesWithEqualValues_ResultsAreCorrect() {
    // This is an edge-case which fooled the resource-index optimiser
    Match query = qb.match(x.isa("title").val(y));
    assertThat(query, iterableWithSize(greaterThan(3)));
    query.forEach(result -> {
        Concept cx = result.get(x);
        Concept cy = result.get(y);
        assertEquals(cx.asAttribute().getValue(), cy.asAttribute().getValue());
    });
}
Also used : Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

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