MetaSchema(String s, int i) { label = Label.of(s); id = LabelId.of(i); }
private Stream<Relationship> edgeRelations(Role... roles){ Set<Role> roleSet = new HashSet<>(Arrays.asList(roles)); Stream<EdgeElement> stream = vertex().getEdgesOfType(Direction.BOTH, Schema.EdgeLabel.ATTRIBUTE); if(!roleSet.isEmpty()){ stream = stream.filter(edge -> { Role roleOwner = vertex().tx().getSchemaConcept(LabelId.of(edge.property(Schema.EdgeProperty.RELATIONSHIP_ROLE_OWNER_LABEL_ID))); return roleSet.contains(roleOwner); }); } return stream.map(edge -> vertex().tx().factory().buildRelation(edge)); }
/** * Run Graql compute count query * * @return a Answer object containing the count value */ private Stream<Value> runComputeCount() { if (!scopeContainsInstance()) { LOG.debug("Count = 0"); return Stream.of(new Value(0)); } Set<LabelId> typeLabelIds = convertLabelsToIds(scopeTypeLabels()); Map<Integer, Long> count; Set<LabelId> rolePlayerLabelIds = getRolePlayerLabelIds(); rolePlayerLabelIds.addAll(typeLabelIds); ComputerResult result = compute( new CountVertexProgram(), new CountMapReduceWithAttribute(), rolePlayerLabelIds, false); count = result.memory().get(CountMapReduceWithAttribute.class.getName()); long finalCount = count.keySet().stream() .filter(id -> typeLabelIds.contains(LabelId.of(id))) .mapToLong(count::get).sum(); if (count.containsKey(GraknMapReduce.RESERVED_TYPE_LABEL_KEY)) { finalCount += count.get(GraknMapReduce.RESERVED_TYPE_LABEL_KEY); } LOG.debug("Count = " + finalCount); return Stream.of(new Value(finalCount)); }
static boolean vertexHasSelectedTypeId(Vertex vertex, Set<LabelId> selectedTypeIds) { return vertex.property(Schema.VertexProperty.THING_TYPE_LABEL_ID.name()).isPresent() && selectedTypeIds.contains(LabelId.of(vertex.value(Schema.VertexProperty.THING_TYPE_LABEL_ID.name()))); }
/** * Gets and increments the current available type id. * * @return the current available Grakn id which can be used for types */ private LabelId getNextId() { TypeImpl<?, ?> metaConcept = (TypeImpl<?, ?>) getMetaConcept(); Integer currentValue = metaConcept.vertex().property(Schema.VertexProperty.CURRENT_LABEL_ID); if (currentValue == null) { currentValue = Schema.MetaSchema.values().length + 1; } else { currentValue = currentValue + 1; } //Vertex is used directly here to bypass meta type mutation check metaConcept.property(Schema.VertexProperty.CURRENT_LABEL_ID, currentValue); return LabelId.of(currentValue); }
/** * The Grakn type property on a given Tinkerpop vertex. * If the vertex is a {@link SchemaConcept}, return invalid {@link Label}. * * @param vertex the Tinkerpop vertex * @return the type */ static LabelId getVertexTypeId(Vertex vertex) { if (vertex.property(Schema.VertexProperty.THING_TYPE_LABEL_ID.name()).isPresent()) { return LabelId.of(vertex.value(Schema.VertexProperty.THING_TYPE_LABEL_ID.name())); } return LabelId.invalid(); }