use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class TxObserver method getAttributesByValue.
private void getAttributesByValue(AttributeValue attributeValue) {
Collection<Attribute<Object>> attributes = tx().getAttributesByValue(GrpcUtil.convert(attributeValue));
Iterator<TxResponse> iterator = attributes.stream().map(GrpcUtil::conceptResponse).iterator();
IteratorId iteratorId = grpcIterators.add(iterator);
responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class MatchTest method testMatchAllResourcesUsingResourceName.
@Test
public void testMatchAllResourcesUsingResourceName() {
Match match = qb.match(var().has("title", "Godfather").has(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue(), x));
Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
Set<Attribute<?>> expected = godfather.attributes().collect(toSet());
Set<Attribute<?>> results = match.get(x).map(Concept::asAttribute).collect(toSet());
assertEquals(expected, results);
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class AttributeTypeTest method whenGettingTheResourceFromAResourceType_ReturnTheResource.
@Test
public void whenGettingTheResourceFromAResourceType_ReturnTheResource() {
AttributeType<String> t1 = tx.putAttributeType("t1", AttributeType.DataType.STRING);
AttributeType<String> t2 = tx.putAttributeType("t2", AttributeType.DataType.STRING);
Attribute c1 = t1.putAttribute("1");
Attribute c2 = t2.putAttribute("2");
assertEquals(c1, t1.getAttribute("1"));
assertNull(t1.getAttribute("2"));
assertEquals(c2, t2.getAttribute("2"));
assertNull(t2.getAttribute("1"));
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class SchemaMutationTest method whenAddingResourceToSubTypeOfEntityType_EnsureNoValidationErrorsOccur.
@Test
public void whenAddingResourceToSubTypeOfEntityType_EnsureNoValidationErrorsOccur() {
// Create initial Schema
AttributeType<String> name = tx.putAttributeType("name", AttributeType.DataType.STRING);
EntityType person = tx.putEntityType("perspn").attribute(name);
EntityType animal = tx.putEntityType("animal").sup(person);
Attribute bob = name.putAttribute("Bob");
person.addEntity().attribute(bob);
tx.commit();
// Now make animal have the same resource type
tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
animal.attribute(name);
tx.commit();
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class EntityTest method checkKeyCreatesCorrectResourceStructure.
@Test
public void checkKeyCreatesCorrectResourceStructure() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.key(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
entity.attribute(attribute);
Relationship relationship = entity.relationships().iterator().next();
checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.KEY, Schema.ImplicitType.KEY_OWNER, Schema.ImplicitType.KEY_VALUE);
}
Aggregations