use of com.baidu.hugegraph.traversal.algorithm.JaccardSimilarTraverser 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);
}
use of com.baidu.hugegraph.traversal.algorithm.JaccardSimilarTraverser in project incubator-hugegraph by apache.
the class JaccardSimilarityAPI method get.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("vertex") String vertex, @QueryParam("other") String other, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree) {
LOG.debug("Graph [{}] get jaccard similarity between '{}' and '{}' " + "with direction {}, edge label {} and max degree '{}'", graph, vertex, other, direction, edgeLabel, maxDegree);
Id sourceId = VertexAPI.checkAndParseVertexId(vertex);
Id targetId = VertexAPI.checkAndParseVertexId(other);
Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
HugeGraph g = graph(manager, graph);
double similarity;
try (JaccardSimilarTraverser traverser = new JaccardSimilarTraverser(g)) {
similarity = traverser.jaccardSimilarity(sourceId, targetId, dir, edgeLabel, maxDegree);
}
return JsonUtil.toJson(ImmutableMap.of("jaccard_similarity", similarity));
}
Aggregations