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());
}
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);
}
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);
}
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());
});
}
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());
});
}
Aggregations