use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class JsonMigratorTest method whenMigratorExecutedOverJsonDirectory_AllDataIsPersistedInGraph.
@Test
public void whenMigratorExecutedOverJsonDirectory_AllDataIsPersistedInGraph() {
load(factory, getFile("json", "string-or-object/schema.gql"));
String template = "\n" + "insert $thing isa the-thing\n" + " has a-string if (<the-thing.a-string> != null) do {<the-thing.a-string>}\n" + " else {<the-thing>} ;";
declareAndLoad(template, "string-or-object/data");
try (GraknTx graph = factory.open(GraknTxType.READ)) {
EntityType theThing = graph.getEntityType("the-thing");
assertEquals(2, theThing.instances().count());
Stream<Entity> things = theThing.instances();
boolean thingsCorrect = things.allMatch(thing -> {
Object string = getResource(graph, thing, Label.of("a-string")).getValue();
return string.equals("hello") || string.equals("goodbye");
});
assertTrue(thingsCorrect);
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAnEntity_TheInformationOnTheEntityIsCorrect.
@Test
public void whenGettingAnEntity_TheInformationOnTheEntityIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("movie")).get();
Entity remoteConcept = query.stream().findAny().get().get("x").asEntity();
Entity localConcept = localTx.getConcept(remoteConcept.getId()).asEntity();
// There actually aren't any new methods on Entity, but we should still check we can get them
assertEquals(localConcept.getId(), remoteConcept.getId());
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class ShortestPathTest method testMultiplePathsSharing1Instance.
@Test
public void testMultiplePathsSharing1Instance() throws InvalidKBException {
ConceptId startId;
ConceptId endId;
Set<List<ConceptId>> correctPaths = new HashSet<>();
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
EntityType entityType = graph.putEntityType(thing);
Role role1 = graph.putRole("role1");
Role role2 = graph.putRole("role2");
entityType.plays(role1).plays(role2);
RelationshipType relationshipType1 = graph.putRelationshipType(related).relates(role1).relates(role2);
Role role3 = graph.putRole("role3");
Role role4 = graph.putRole("role4");
entityType.plays(role3).plays(role4);
RelationshipType relationshipType2 = graph.putRelationshipType(veryRelated).relates(role3).relates(role4);
Entity start = entityType.addEntity();
Entity end = entityType.addEntity();
Entity middle = entityType.addEntity();
startId = start.getId();
endId = end.getId();
ConceptId middleId = middle.getId();
ConceptId assertion11 = relationshipType1.addRelationship().addRolePlayer(role1, start).addRolePlayer(role2, middle).getId();
ConceptId assertion12 = relationshipType1.addRelationship().addRolePlayer(role1, middle).addRolePlayer(role2, end).getId();
ConceptId assertion21 = relationshipType2.addRelationship().addRolePlayer(role3, start).addRolePlayer(role4, middle).getId();
ConceptId assertion22 = relationshipType2.addRelationship().addRolePlayer(role3, middle).addRolePlayer(role4, end).getId();
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion22, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion22, endId));
graph.commit();
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
List<List<Concept>> allPaths = graph.graql().compute().paths().from(startId).to(endId).execute();
assertEquals(correctPaths.size(), allPaths.size());
Set<List<ConceptId>> computedPaths = allPaths.stream().map(path -> path.stream().map(Concept::getId).collect(Collectors.toList())).collect(Collectors.toSet());
assertEquals(correctPaths, computedPaths);
}
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class InsertQueryTest method whenAddingAnAttributeRelationshipWithProvenance_TheAttributeAndProvenanceAreAdded.
@Test
public void whenAddingAnAttributeRelationshipWithProvenance_TheAttributeAndProvenanceAreAdded() {
InsertQuery query = qb.insert(y.has("provenance", z.val("Someone told me")), w.isa("movie").has(title, x.val("My Movie"), y));
Answer answer = Iterables.getOnlyElement(query.execute());
Entity movie = answer.get(w).asEntity();
Attribute<String> theTitle = answer.get(x).asAttribute();
Relationship hasTitle = answer.get(y).asRelationship();
Attribute<String> provenance = answer.get(z).asAttribute();
assertThat(hasTitle.rolePlayers().toArray(), arrayContainingInAnyOrder(movie, theTitle));
assertThat(hasTitle.attributes().toArray(), arrayContaining(provenance));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class MatchTest method whenExecutingGraqlTraversalFromGraph_ReturnExpectedResults.
@Test
public void whenExecutingGraqlTraversalFromGraph_ReturnExpectedResults() {
EntityType type = movieKB.tx().putEntityType("Concept Type");
Entity entity = type.addEntity();
Collection<Concept> results = movieKB.tx().graql().match(x.isa(type.getLabel().getValue())).stream().findAny().get().concepts();
assertThat(results, containsInAnyOrder(entity));
}
Aggregations