Search in sources :

Example 1 with AttributeType

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());
}
Also used : Attribute(ai.grakn.concept.Attribute) AttributeType(ai.grakn.concept.AttributeType) Relationship(ai.grakn.concept.Relationship) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 2 with AttributeType

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;
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 3 with AttributeType

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))));
    }
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) Attribute(ai.grakn.concept.Attribute) AttributeType(ai.grakn.concept.AttributeType) Var(ai.grakn.graql.Var)

Example 4 with AttributeType

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);
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Test(org.junit.Test)

Example 5 with AttributeType

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));
}
Also used : AttributeType(ai.grakn.concept.AttributeType) PutAttributeType(ai.grakn.rpc.generated.GrpcGrakn.PutAttributeType) Label(ai.grakn.concept.Label)

Aggregations

AttributeType (ai.grakn.concept.AttributeType)27 Test (org.junit.Test)13 EntityType (ai.grakn.concept.EntityType)7 Label (ai.grakn.concept.Label)7 RelationshipType (ai.grakn.concept.RelationshipType)7 GraknTx (ai.grakn.GraknTx)6 Role (ai.grakn.concept.Role)6 Attribute (ai.grakn.concept.Attribute)5 Property (com.pholser.junit.quickcheck.Property)5 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)4 GraknSession (ai.grakn.GraknSession)3 SchemaConcept (ai.grakn.concept.SchemaConcept)3 GraknTxType (ai.grakn.GraknTxType)2 Keyspace (ai.grakn.Keyspace)2 Concept (ai.grakn.concept.Concept)2 ConceptId (ai.grakn.concept.ConceptId)2 Entity (ai.grakn.concept.Entity)2 EmbeddedGraknSession (ai.grakn.factory.EmbeddedGraknSession)2 EngineContext (ai.grakn.test.rule.EngineContext)2 Collection (java.util.Collection)2