Search in sources :

Example 1 with PredictionTraverser

use of com.baidu.hugegraph.traversal.algorithm.PredictionTraverser in project incubator-hugegraph by apache.

the class ResourceAllocationAPI method create.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String create(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("vertex") String current, @QueryParam("other") String other, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("limit") @DefaultValue(DEFAULT_ELEMENTS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get resource allocation between '{}' and '{}' " + "with direction {}, edge label {}, max degree '{}' and " + "limit '{}'", graph, current, other, direction, edgeLabel, maxDegree, limit);
    Id sourceId = VertexAPI.checkAndParseVertexId(current);
    Id targetId = VertexAPI.checkAndParseVertexId(other);
    E.checkArgument(!current.equals(other), "The source and target vertex id can't be same");
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    PredictionTraverser traverser = new PredictionTraverser(g);
    double score = traverser.resourceAllocation(sourceId, targetId, dir, edgeLabel, maxDegree, limit);
    return JsonUtil.toJson(ImmutableMap.of("resource_allocation", score));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) PredictionTraverser(com.baidu.hugegraph.traversal.algorithm.PredictionTraverser) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 2 with PredictionTraverser

use of com.baidu.hugegraph.traversal.algorithm.PredictionTraverser in project incubator-hugegraph by apache.

the class AdamicAdarAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("vertex") String current, @QueryParam("other") String other, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("limit") @DefaultValue(DEFAULT_ELEMENTS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get adamic adar between '{}' and '{}' with " + "direction {}, edge label {}, max degree '{}' and limit '{}'", graph, current, other, direction, edgeLabel, maxDegree, limit);
    Id sourceId = VertexAPI.checkAndParseVertexId(current);
    Id targetId = VertexAPI.checkAndParseVertexId(other);
    E.checkArgument(!current.equals(other), "The source and target vertex id can't be same");
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    PredictionTraverser traverser = new PredictionTraverser(g);
    double score = traverser.adamicAdar(sourceId, targetId, dir, edgeLabel, maxDegree, limit);
    return JsonUtil.toJson(ImmutableMap.of("adamic_adar", score));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) PredictionTraverser(com.baidu.hugegraph.traversal.algorithm.PredictionTraverser) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Aggregations

HugeGraph (com.baidu.hugegraph.HugeGraph)2 Id (com.baidu.hugegraph.backend.id.Id)2 PredictionTraverser (com.baidu.hugegraph.traversal.algorithm.PredictionTraverser)2 Directions (com.baidu.hugegraph.type.define.Directions)2 Timed (com.codahale.metrics.annotation.Timed)2 GET (jakarta.ws.rs.GET)2 Produces (jakarta.ws.rs.Produces)2