use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class CorenessTest method testImplicitTypeShouldBeIncluded.
@Test
public void testImplicitTypeShouldBeIncluded() {
addSchemaAndEntities();
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
String aResourceTypeLabel = "aResourceTypeLabel";
AttributeType<String> attributeType = graph.putAttributeType(aResourceTypeLabel, AttributeType.DataType.STRING);
graph.getEntityType(thing).attribute(attributeType);
graph.getEntityType(anotherThing).attribute(attributeType);
Attribute Attribute1 = attributeType.putAttribute("blah");
graph.getConcept(entityId1).asEntity().attribute(Attribute1);
graph.getConcept(entityId2).asEntity().attribute(Attribute1);
graph.getConcept(entityId3).asEntity().attribute(Attribute1);
graph.getConcept(entityId4).asEntity().attribute(Attribute1);
Attribute Attribute2 = attributeType.putAttribute("bah");
graph.getConcept(entityId1).asEntity().attribute(Attribute2);
graph.getConcept(entityId2).asEntity().attribute(Attribute2);
graph.getConcept(entityId3).asEntity().attribute(Attribute2);
graph.commit();
}
Map<Long, Set<String>> result;
try (GraknTx graph = session.open(GraknTxType.READ)) {
result = graph.graql().compute().centrality().usingKCore().execute();
System.out.println("result = " + result);
assertEquals(2, result.size());
assertEquals(5, result.get(4L).size());
assertEquals(1, result.get(3L).size());
result = graph.graql().compute().centrality().usingKCore().minK(4L).execute();
assertEquals(1, result.size());
assertEquals(5, result.get(4L).size());
}
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class KCoreTest method testImplicitTypeShouldBeExcluded.
@Test
public void testImplicitTypeShouldBeExcluded() {
addSchemaAndEntities();
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
String aResourceTypeLabel = "aResourceTypeLabel";
AttributeType<String> attributeType = graph.putAttributeType(aResourceTypeLabel, AttributeType.DataType.STRING);
graph.getEntityType(thing).attribute(attributeType);
Attribute aAttribute = attributeType.putAttribute("blah");
graph.getConcept(entityId1).asEntity().attribute(aAttribute);
graph.getConcept(entityId2).asEntity().attribute(aAttribute);
graph.commit();
}
Map<String, Set<String>> result;
try (GraknTx graph = session.open(GraknTxType.READ)) {
result = graph.graql().compute().cluster().usingKCore().includeAttribute().kValue(2L).execute();
assertEquals(1, result.size());
assertEquals(5, result.values().iterator().next().size());
result = graph.graql().compute().cluster().usingKCore().kValue(3L).execute();
assertEquals(1, result.size());
assertEquals(4, result.values().iterator().next().size());
}
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class JsonMigratorMainTest method runAndAssertDataCorrect.
private void runAndAssertDataCorrect(String... args) {
run(args);
try (GraknTx graph = session.open(GraknTxType.READ)) {
EntityType personType = graph.getEntityType("person");
assertEquals(1, personType.instances().count());
Entity person = personType.instances().iterator().next();
Entity address = getProperty(graph, person, "has-address").asEntity();
Entity streetAddress = getProperty(graph, address, "address-has-street").asEntity();
Attribute number = getResource(graph, streetAddress, Label.of("number"));
assertEquals(21L, number.getValue());
Collection<Thing> phoneNumbers = getProperties(graph, person, "has-phone");
assertEquals(2, phoneNumbers.size());
}
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class AttributeTest method whenCreatingResource_EnsureTheResourcesDataTypeIsTheSameAsItsType.
@Test
public void whenCreatingResource_EnsureTheResourcesDataTypeIsTheSameAsItsType() throws Exception {
AttributeType<String> attributeType = tx.putAttributeType("attributeType", AttributeType.DataType.STRING);
Attribute attribute = attributeType.putAttribute("resource");
assertEquals(AttributeType.DataType.STRING, attribute.dataType());
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect.
@Test
public void whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("title")).get();
Attribute<?> remoteConcept = query.stream().findAny().get().get("x").asAttribute();
Attribute<?> localConcept = localTx.getConcept(remoteConcept.getId()).asAttribute();
assertEquals(localConcept.dataType(), remoteConcept.dataType());
assertEquals(localConcept.getValue(), remoteConcept.getValue());
assertEquals(localConcept.owner().getId(), remoteConcept.owner().getId());
assertEqualConcepts(localConcept, remoteConcept, Attribute::ownerInstances);
}
}
Aggregations