use of ai.grakn.concept.AttributeType 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.AttributeType in project grakn by graknlabs.
the class ConceptBuilder method putSchemaConcept.
private SchemaConcept putSchemaConcept() {
SchemaConcept superConcept = use(SUPER_CONCEPT);
Label label = use(LABEL);
SchemaConcept concept;
if (superConcept.isEntityType()) {
concept = executor.tx().putEntityType(label);
} else if (superConcept.isRelationshipType()) {
concept = executor.tx().putRelationshipType(label);
} else if (superConcept.isRole()) {
concept = executor.tx().putRole(label);
} else if (superConcept.isAttributeType()) {
AttributeType attributeType = superConcept.asAttributeType();
AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.getDataType());
concept = executor.tx().putAttributeType(label, dataType);
} else if (superConcept.isRule()) {
concept = executor.tx().putRule(label, use(WHEN), use(THEN));
} else {
throw GraqlQueryException.insertMetaType(label, superConcept);
}
setSuper(concept, superConcept);
return concept;
}
use of ai.grakn.concept.AttributeType 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))));
}
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class AttributeTest method whenCreatingResourceWithAnInvalidDataType_Throw.
// this is deliberately an incorrect type for the test
@SuppressWarnings("unchecked")
@Test
public void whenCreatingResourceWithAnInvalidDataType_Throw() {
String invalidThing = "Invalid Thing";
AttributeType longAttributeType = tx.putAttributeType("long", AttributeType.DataType.LONG);
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.invalidResourceValue(invalidThing, AttributeType.DataType.LONG).getMessage());
longAttributeType.putAttribute(invalidThing);
}
use of ai.grakn.concept.AttributeType in project grakn by graknlabs.
the class TxObserver method putAttributeType.
private void putAttributeType(PutAttributeType putAttributeType) {
Label label = GrpcUtil.convert(putAttributeType.getLabel());
AttributeType.DataType<?> dataType = GrpcUtil.convert(putAttributeType.getDataType());
AttributeType<?> attributeType = tx().putAttributeType(label, dataType);
responseObserver.onNext(GrpcUtil.conceptResponse(attributeType));
}
Aggregations