use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class JsonMigratorTest method whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped.
@Test
public void whenMigratorExecutedOverMissingData_ErrorIsNotThrownAndMissingObjectsAreSkipped() {
load(factory, getFile("json", "string-or-object/schema.gql"));
String template = "insert $thing isa the-thing has a-string <the-thing.a-string>;";
declareAndLoad(template, "string-or-object/data");
try (GraknTx graph = factory.open(GraknTxType.READ)) {
EntityType theThing = graph.getEntityType("the-thing");
assertEquals(1, theThing.instances().count());
}
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect.
@Test
public void whenGettingAnEntityType_TheInformationOnTheEntityTypeIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").label("person")).get();
EntityType remoteConcept = query.stream().findAny().get().get("x").asEntityType();
EntityType localConcept = localTx.getConcept(remoteConcept.getId()).asEntityType();
// There actually aren't any new methods on EntityType, but we should still check we can get them
assertEquals(localConcept.getId(), remoteConcept.getId());
}
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class DiagonalKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx tx, int n, int m) {
Role relFrom = tx.getRole("rel-from");
Role relTo = tx.getRole("rel-to");
EntityType entity1 = tx.getEntityType("entity1");
RelationshipType horizontal = tx.getRelationshipType("horizontal");
RelationshipType vertical = tx.getRelationshipType("vertical");
ConceptId[][] instanceIds = new ConceptId[n][m];
long inserts = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
instanceIds[i][j] = putEntityWithResource(tx, "a" + i + "," + j, entity1, key).getId();
inserts++;
if (inserts % 100 == 0)
System.out.println("inst inserts: " + inserts);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i < n - 1) {
vertical.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i + 1][j]));
inserts++;
}
if (j < m - 1) {
horizontal.addRelationship().addRolePlayer(relFrom, tx.getConcept(instanceIds[i][j])).addRolePlayer(relTo, tx.getConcept(instanceIds[i][j + 1]));
inserts++;
}
if (inserts % 100 == 0)
System.out.println("rel inserts: " + inserts);
}
}
System.out.println("Extensional DB loaded.");
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class NguyenKB method buildExtensionalDB.
private void buildExtensionalDB(GraknTx graph, int n) {
Role Rfrom = graph.getRole("R-rA");
Role Rto = graph.getRole("R-rB");
Role qfrom = graph.getRole("Q-rA");
Role qto = graph.getRole("Q-rB");
Role Pfrom = graph.getRole("P-rA");
Role Pto = graph.getRole("P-rB");
EntityType entity = graph.getEntityType("entity2");
EntityType aEntity = graph.getEntityType("a-entity");
EntityType bEntity = graph.getEntityType("b-entity");
RelationshipType r = graph.getRelationshipType("R");
RelationshipType p = graph.getRelationshipType("P");
RelationshipType q = graph.getRelationshipType("Q");
ConceptId cId = putEntityWithResource(graph, "c", entity, key).getId();
ConceptId dId = putEntityWithResource(graph, "d", entity, key).getId();
ConceptId eId = putEntityWithResource(graph, "e", entity, key).getId();
ConceptId[] aInstancesIds = new ConceptId[n + 2];
ConceptId[] bInstancesIds = new ConceptId[n + 2];
aInstancesIds[n + 1] = putEntityWithResource(graph, "a" + (n + 1), aEntity, key).getId();
for (int i = 0; i <= n; i++) {
aInstancesIds[i] = putEntityWithResource(graph, "a" + i, aEntity, key).getId();
bInstancesIds[i] = putEntityWithResource(graph, "b" + i, bEntity, key).getId();
}
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(dId));
r.addRelationship().addRolePlayer(Rfrom, graph.getConcept(dId)).addRolePlayer(Rto, graph.getConcept(eId));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(eId)).addRolePlayer(qto, graph.getConcept(aInstancesIds[0]));
for (int i = 0; i <= n; i++) {
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(Pto, graph.getConcept(cId));
p.addRelationship().addRolePlayer(Pfrom, graph.getConcept(cId)).addRolePlayer(Pto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(aInstancesIds[i])).addRolePlayer(qto, graph.getConcept(bInstancesIds[i]));
q.addRelationship().addRolePlayer(qfrom, graph.getConcept(bInstancesIds[i])).addRolePlayer(qto, graph.getConcept(aInstancesIds[i + 1]));
}
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class EntityTypeTest method whenRemovingAttributesFromAType_EnsureTheTypeNoLongerHasThoseAttributes.
@Test
public void whenRemovingAttributesFromAType_EnsureTheTypeNoLongerHasThoseAttributes() {
AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
AttributeType<Integer> age = tx.putAttributeType("age", AttributeType.DataType.INTEGER);
EntityType person = tx.putEntityType("person").attribute(name).attribute(age);
assertThat(person.attributes().collect(toSet()), containsInAnyOrder(name, age));
person.deleteAttribute(name);
assertThat(person.attributes().collect(toSet()), containsInAnyOrder(age));
}
Aggregations