Search in sources :

Example 6 with VertexElement

use of ai.grakn.kb.internal.structure.VertexElement in project grakn by graknlabs.

the class EmbeddedGraknTx method addTypeVertex.

/**
 * Adds a new type vertex which occupies a grakn id. This result in the grakn id count on the meta concept to be
 * incremented.
 *
 * @param label    The label of the new type vertex
 * @param baseType The base type of the new type
 * @return The new type vertex
 */
private VertexElement addTypeVertex(LabelId id, Label label, Schema.BaseType baseType) {
    VertexElement vertexElement = addVertexElement(baseType);
    vertexElement.property(Schema.VertexProperty.SCHEMA_LABEL, label.getValue());
    vertexElement.property(Schema.VertexProperty.LABEL_ID, id.getValue());
    return vertexElement;
}
Also used : VertexElement(ai.grakn.kb.internal.structure.VertexElement)

Example 7 with VertexElement

use of ai.grakn.kb.internal.structure.VertexElement in project grakn by graknlabs.

the class EmbeddedGraknTx method initialiseMetaConcepts.

@SuppressWarnings("unchecked")
private boolean initialiseMetaConcepts() {
    boolean schemaInitialised = false;
    if (isMetaSchemaNotInitialised()) {
        VertexElement type = addTypeVertex(Schema.MetaSchema.THING.getId(), Schema.MetaSchema.THING.getLabel(), Schema.BaseType.TYPE);
        VertexElement entityType = addTypeVertex(Schema.MetaSchema.ENTITY.getId(), Schema.MetaSchema.ENTITY.getLabel(), Schema.BaseType.ENTITY_TYPE);
        VertexElement relationType = addTypeVertex(Schema.MetaSchema.RELATIONSHIP.getId(), Schema.MetaSchema.RELATIONSHIP.getLabel(), Schema.BaseType.RELATIONSHIP_TYPE);
        VertexElement resourceType = addTypeVertex(Schema.MetaSchema.ATTRIBUTE.getId(), Schema.MetaSchema.ATTRIBUTE.getLabel(), Schema.BaseType.ATTRIBUTE_TYPE);
        addTypeVertex(Schema.MetaSchema.ROLE.getId(), Schema.MetaSchema.ROLE.getLabel(), Schema.BaseType.ROLE);
        addTypeVertex(Schema.MetaSchema.RULE.getId(), Schema.MetaSchema.RULE.getLabel(), Schema.BaseType.RULE);
        relationType.property(Schema.VertexProperty.IS_ABSTRACT, true);
        resourceType.property(Schema.VertexProperty.IS_ABSTRACT, true);
        entityType.property(Schema.VertexProperty.IS_ABSTRACT, true);
        relationType.addEdge(type, Schema.EdgeLabel.SUB);
        resourceType.addEdge(type, Schema.EdgeLabel.SUB);
        entityType.addEdge(type, Schema.EdgeLabel.SUB);
        schemaInitialised = true;
    }
    // Copy entire schema to the graph cache. This may be a bad idea as it will slow down graph initialisation
    copyToCache(getMetaConcept());
    // Role and rule have to be copied separately due to not being connected to meta schema
    copyToCache(getMetaRole());
    copyToCache(getMetaRule());
    return schemaInitialised;
}
Also used : VertexElement(ai.grakn.kb.internal.structure.VertexElement)

Example 8 with VertexElement

use of ai.grakn.kb.internal.structure.VertexElement in project grakn by graknlabs.

the class PostProcessingTest method createFakeResource.

private AttributeImpl<String> createFakeResource(AttributeTypeImpl<String> type, String value) {
    String index = Schema.generateAttributeIndex(type.getLabel(), value);
    Vertex resourceVertex = tx.getTinkerPopGraph().addVertex(Schema.BaseType.ATTRIBUTE.name());
    resourceVertex.addEdge(Schema.EdgeLabel.ISA.getLabel(), type.currentShard().vertex().element());
    resourceVertex.property(Schema.VertexProperty.INDEX.name(), index);
    resourceVertex.property(Schema.VertexProperty.VALUE_STRING.name(), value);
    resourceVertex.property(Schema.VertexProperty.ID.name(), Schema.PREFIX_VERTEX + resourceVertex.id().toString());
    return AttributeImpl.get(new VertexElement(tx, resourceVertex));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexElement(ai.grakn.kb.internal.structure.VertexElement)

Aggregations

VertexElement (ai.grakn.kb.internal.structure.VertexElement)8 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 SchemaConceptImpl (ai.grakn.kb.internal.concept.SchemaConceptImpl)1 Shard (ai.grakn.kb.internal.structure.Shard)1 REST (ai.grakn.util.REST)1