use of com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep in project incubator-hugegraph by apache.
the class HugeTraverser method edgesOfVertex.
private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep, boolean mustAllSK) {
Id[] edgeLabels = edgeStep.edgeLabels();
Query query = GraphTransaction.constructEdgesQuery(source, edgeStep.direction(), edgeLabels);
ConditionQuery filter = null;
if (mustAllSK) {
this.fillFilterBySortKeys(query, edgeLabels, edgeStep.properties());
} else {
filter = (ConditionQuery) query.copy();
this.fillFilterByProperties(filter, edgeStep.properties());
}
query.capacity(Query.NO_CAPACITY);
if (edgeStep.limit() != NO_LIMIT) {
query.limit(edgeStep.limit());
}
Iterator<Edge> edges = this.graph().edges(query);
if (filter != null) {
ConditionQuery finalFilter = filter;
edges = new FilterIterator<>(edges, (e) -> {
return finalFilter.test((HugeEdge) e);
});
}
return edgeStep.skipSuperNodeIfNeeded(edges);
}
use of com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep in project incubator-hugegraph by apache.
the class KneighborTraverser method customizedKneighbor.
public KneighborRecords customizedKneighbor(Id source, EdgeStep step, int maxDepth, long limit) {
E.checkNotNull(source, "source vertex id");
this.checkVertexExist(source, "source vertex");
checkPositive(maxDepth, "k-neighbor max_depth");
checkLimit(limit);
boolean concurrent = maxDepth >= this.concurrentDepth();
KneighborRecords records = new KneighborRecords(concurrent, source, true);
Consumer<Id> consumer = v -> {
if (this.reachLimit(limit, records.size())) {
return;
}
Iterator<Edge> edges = edgesOfVertex(v, step);
while (!this.reachLimit(limit, records.size()) && edges.hasNext()) {
Id target = ((HugeEdge) edges.next()).id().otherVertexId();
records.addPath(v, target);
}
};
while (maxDepth-- > 0) {
records.startOneLayer(true);
traverseIds(records.keys(), consumer, concurrent);
records.finishOneLayer();
}
return records;
}
use of com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep in project incubator-hugegraph by apache.
the class PredictionTraverser method resourceAllocation.
public double resourceAllocation(Id source, Id target, Directions dir, String label, long degree, long limit) {
Set<Id> neighbors = checkAndGetCommonNeighbors(source, target, dir, label, degree, limit);
EdgeStep step = label == null ? new EdgeStep(graph(), dir) : new EdgeStep(graph(), dir, ImmutableList.of(label));
double sum = 0.0;
for (Id vid : neighbors) {
long currentDegree = this.edgesCount(vid, step);
if (currentDegree > 0) {
sum += 1.0 / currentDegree;
}
}
return sum;
}
use of com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep in project incubator-hugegraph by apache.
the class CountAPI method steps.
private static List<EdgeStep> steps(HugeGraph graph, CountRequest request) {
int stepSize = request.steps.size();
List<EdgeStep> steps = new ArrayList<>(stepSize);
for (Step step : request.steps) {
steps.add(step.jsonToStep(graph));
}
return steps;
}
use of com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep in project incubator-hugegraph by apache.
the class JaccardSimilarityAPI method post.
@POST
@Timed
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String post(@Context GraphManager manager, @PathParam("graph") String graph, Request request) {
E.checkArgumentNotNull(request, "The request body can't be null");
E.checkArgumentNotNull(request.vertex, "The source vertex of request can't be null");
E.checkArgument(request.step != null, "The steps of request can't be null");
E.checkArgument(request.top >= 0, "The top must be >= 0, but got: %s", request.top);
LOG.debug("Graph [{}] get jaccard similars from source vertex '{}', " + "with step '{}', top '{}' and capacity '{}'", graph, request.vertex, request.step, request.top, request.capacity);
HugeGraph g = graph(manager, graph);
Id sourceId = HugeVertex.getIdValue(request.vertex);
EdgeStep step = step(g, request.step);
Map<Id, Double> results;
try (JaccardSimilarTraverser traverser = new JaccardSimilarTraverser(g)) {
results = traverser.jaccardSimilars(sourceId, step, request.top, request.capacity);
}
return manager.serializer(g).writeMap(results);
}
Aggregations