use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class MigratorTestUtils method getResources.
public static Stream<Attribute> getResources(GraknTx graph, Thing thing, Label label) {
Role roleOwner = graph.getSchemaConcept(Schema.ImplicitType.HAS_OWNER.getLabel(label));
Role roleOther = graph.getSchemaConcept(Schema.ImplicitType.HAS_VALUE.getLabel(label));
Stream<Relationship> relations = thing.relationships(roleOwner);
return relations.flatMap(r -> r.rolePlayers(roleOther)).map(Concept::asAttribute);
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class EntityTest method whenAddingMultipleResourcesToEntity_EnsureDifferentRelationsAreBuilt.
@Test
public void whenAddingMultipleResourcesToEntity_EnsureDifferentRelationsAreBuilt() throws InvalidKBException {
String resourceTypeId = "A Attribute Thing";
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceTypeId, AttributeType.DataType.STRING);
entityType.attribute(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute1 = attributeType.putAttribute("A resource thing");
Attribute attribute2 = attributeType.putAttribute("Another resource thing");
assertEquals(0, entity.relationships().count());
entity.attribute(attribute1);
assertEquals(1, entity.relationships().count());
entity.attribute(attribute2);
assertEquals(2, entity.relationships().count());
tx.commit();
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class EntityTest method whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated.
@Test
public void whenAddingResourceToAnEntity_EnsureTheImplicitStructureIsCreated() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.attribute(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.HAS, Schema.ImplicitType.HAS_OWNER, Schema.ImplicitType.HAS_VALUE);
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class RelationshipTest method whenAttributeLinkedToRelationshipIsInferred_EnsureItIsMarkedAsInferred.
@Test
public void whenAttributeLinkedToRelationshipIsInferred_EnsureItIsMarkedAsInferred() {
AttributeType attributeType = tx.putAttributeType("Another thing of sorts", AttributeType.DataType.STRING);
RelationshipType relationshipType = tx.putRelationshipType("A thing of sorts").attribute(attributeType);
Attribute attribute = attributeType.putAttribute("Things");
Relationship relationship = relationshipType.addRelationship();
RelationshipImpl.from(relationship).attributeInferred(attribute);
assertTrue(relationship.relationships().findAny().get().isInferred());
}
use of ai.grakn.concept.Attribute in project grakn by graknlabs.
the class ResourceAtom method materialise.
@Override
public Stream<Answer> materialise() {
Answer substitution = getParentQuery().getSubstitution();
AttributeType type = getSchemaConcept().asAttributeType();
Concept owner = substitution.get(getVarName());
Var resourceVariable = getPredicateVariable();
// if the attribute already exists, only attach a new link to the owner, otherwise create a new attribute
if (substitution.containsVar(resourceVariable)) {
Attribute attribute = substitution.get(resourceVariable).asAttribute();
attachAttribute(owner, attribute);
return Stream.of(substitution);
} else {
Attribute attribute = AttributeTypeImpl.from(type).putAttributeInferred(Iterables.getOnlyElement(getMultiPredicate()).getPredicate().equalsValue().get());
attachAttribute(owner, attribute);
return Stream.of(substitution.merge(new QueryAnswer(ImmutableMap.of(resourceVariable, attribute))));
}
}
Aggregations