public ConnectedComponentVertexProgram(ConceptId sourceId) { this.persistentProperties.put(SOURCE, sourceId.getValue()); }
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null || this.getClass() != o.getClass()) return false; ConceptId that = (ConceptId) o; return (this.value.equals(that.getValue())); }
@Override public boolean canOperateOnEdges() { return id().getValue().startsWith(Schema.PREFIX_EDGE); } }
/** * @param id an ID of a concept * @return * The id of the concept correctly escaped in graql. * If the ID doesn't begin with a number and is only comprised of alphanumeric characters, underscores and dashes, * then it will be returned as-is, otherwise it will be quoted and escaped. */ public static String idToString(ConceptId id) { return escapeLabelOrId(id.getValue()); }
@Nullable public static String nullableIdToString(@Nullable ConceptId id) { return id != null ? escapeLabelOrId(id.getValue()) : null; }
@Override public String getPredicateValue() { return getPredicate().getValue();} }
private GraphTraversal<Edge, Edge> edgeTraversal() { return __.hasId(id().getValue().substring(1)); }
@Override public <T extends Concept> T getConcept(ConceptId id) { return operateOnOpenGraph(() -> { if (txCache().isConceptCached(id)) { return txCache().getCachedConcept(id); } else { if (id.getValue().startsWith(Schema.PREFIX_EDGE)) { Optional<T> concept = getConceptEdge(id); if (concept.isPresent()) return concept.get(); } return this.<T>getConcept(Schema.VertexProperty.ID, id.getValue()).orElse(null); } }); }
private GraphTraversal<Vertex, Vertex> vertexTraversal(GraphTraversal<Vertex, ? extends Element> traversal) { // A vertex should always be looked up by vertex property, not the actual vertex ID which may be incorrect. // This is because a vertex may represent a reified relation, which will use the original edge ID as an ID. // We know only vertices have this property, so the cast is safe //noinspection unchecked return (GraphTraversal<Vertex, Vertex>) traversal.has(Schema.VertexProperty.ID.name(), id().getValue()); }
private static GrpcConcept.ConceptId convert(ConceptId id) { return GrpcConcept.ConceptId.newBuilder().setValue(id.getValue()).build(); }
private <T extends Concept> Optional<T> getConceptEdge(ConceptId id) { String edgeId = id.getValue().substring(1); GraphTraversal<Edge, Edge> traversal = getTinkerTraversal().E(edgeId); if (traversal.hasNext()) { return Optional.of(factory().buildConcept(factory().buildEdgeElement(traversal.next()))); } return Optional.empty(); }
private String summaryFormat(Object object) { if (object instanceof SchemaConcept) { return ((SchemaConcept) object).label().getValue().replaceAll("-", "_"); } else if (object instanceof Thing) { Thing thing = (Thing) object; return summaryFormat(thing.type()) + thing.id().getValue(); } else if (object instanceof Label) { return valueToString(((Label) object).getValue()); } else { return object.toString(); } }
public static SessionProto.Transaction.Req getConcept(ConceptId id) { return SessionProto.Transaction.Req.newBuilder() .setGetConceptReq(SessionProto.Transaction.GetConcept.Req.newBuilder().setId(id.getValue())) .build(); }
public static ConceptProto.Concept concept(ai.grakn.concept.Concept concept) { return ConceptProto.Concept.newBuilder() .setId(concept.id().getValue()) .setBaseType(getBaseType(concept)) .build(); }
private Stream<Relationship> reifiedRelations(Role... roles){ GraphTraversal<Vertex, Vertex> traversal = vertex().tx().getTinkerTraversal().V(). has(Schema.VertexProperty.ID.name(), id().getValue()); if(roles.length == 0){ traversal.in(Schema.EdgeLabel.ROLE_PLAYER.getLabel()); } else { Set<Integer> roleTypesIds = Arrays.stream(roles).map(r -> r.labelId().getValue()).collect(toSet()); traversal.inE(Schema.EdgeLabel.ROLE_PLAYER.getLabel()). has(Schema.EdgeProperty.ROLE_LABEL_ID.name(), P.within(roleTypesIds)).outV(); } return traversal.toStream().map(vertex -> vertex().tx().<Relationship>buildConcept(vertex)); }
/** * Given an thing, return a var with the type. * @param thing thing to map * @return var patterns representing given thing */ private static VarPattern base(Thing thing){ VarPattern var = var(thing.id().getValue()).isa(Graql.label(thing.type().label())); return hasResources(var, thing); }
public static GrpcConcept.Concept convert(Concept concept) { return GrpcConcept.Concept.newBuilder() .setId(GrpcConcept.ConceptId.newBuilder().setValue(concept.getId().getValue()).build()) .setBaseType(getBaseType(concept)) .build(); }
public SessionProto.Transaction.Res runConceptMethod(ConceptId id, ConceptProto.Method.Req method) { SessionProto.Transaction.ConceptMethod.Req conceptMethod = SessionProto.Transaction.ConceptMethod.Req.newBuilder() .setId(id.getValue()).setMethod(method).build(); SessionProto.Transaction.Req request = SessionProto.Transaction.Req.newBuilder().setConceptMethodReq(conceptMethod).build(); transceiver.send(request); return responseOrThrow(); }