Search in sources :

Example 1 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class HugeVertex method edges.

@Watched(prefix = "vertex")
@Override
public Iterator<Edge> edges(Direction tinkerpopDir, String... edgeLabels) {
    Directions direction = Directions.convert(tinkerpopDir);
    // NOTE: get edges from memory if load all edges when loading vertex.
    if (this.existsEdges()) {
        return this.getEdges(direction, edgeLabels);
    }
    Id[] edgeLabelIds = this.graph().mapElName2Id(edgeLabels);
    Query query = GraphTransaction.constructEdgesQuery(this.id(), direction, edgeLabelIds);
    return this.graph().edges(query);
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 2 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class RaysAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String sourceV, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_depth") int depth, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity, @QueryParam("limit") @DefaultValue(DEFAULT_PATHS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get rays paths from '{}' with " + "direction '{}', edge label '{}', max depth '{}', " + "max degree '{}', capacity '{}' and limit '{}'", graph, sourceV, direction, edgeLabel, depth, maxDegree, capacity, limit);
    Id source = VertexAPI.checkAndParseVertexId(sourceV);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    SubGraphTraverser traverser = new SubGraphTraverser(g);
    HugeTraverser.PathSet paths = traverser.rays(source, dir, edgeLabel, depth, maxDegree, capacity, limit);
    return manager.serializer(g).writePaths("rays", paths, false);
}
Also used : SubGraphTraverser(com.baidu.hugegraph.traversal.algorithm.SubGraphTraverser) HugeGraph(com.baidu.hugegraph.HugeGraph) Directions(com.baidu.hugegraph.type.define.Directions) HugeTraverser(com.baidu.hugegraph.traversal.algorithm.HugeTraverser) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 3 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class ShortestPathAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String source, @QueryParam("target") String target, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_depth") int depth, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("skip_degree") @DefaultValue("0") long skipDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity) {
    LOG.debug("Graph [{}] get shortest path from '{}', to '{}' with " + "direction {}, edge label {}, max depth '{}', " + "max degree '{}', skipped maxDegree '{}' and capacity '{}'", graph, source, target, direction, edgeLabel, depth, maxDegree, skipDegree, capacity);
    Id sourceId = VertexAPI.checkAndParseVertexId(source);
    Id targetId = VertexAPI.checkAndParseVertexId(target);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    ShortestPathTraverser traverser = new ShortestPathTraverser(g);
    List<String> edgeLabels = edgeLabel == null ? ImmutableList.of() : ImmutableList.of(edgeLabel);
    HugeTraverser.Path path = traverser.shortestPath(sourceId, targetId, dir, edgeLabels, depth, maxDegree, skipDegree, capacity);
    return manager.serializer(g).writeList("path", path.vertices());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ShortestPathTraverser(com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser) Directions(com.baidu.hugegraph.type.define.Directions) HugeTraverser(com.baidu.hugegraph.traversal.algorithm.HugeTraverser) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 4 with Directions

use of com.baidu.hugegraph.type.define.Directions 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 5 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class KneighborAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String sourceV, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_depth") int depth, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("limit") @DefaultValue(DEFAULT_ELEMENTS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get k-neighbor from '{}' with " + "direction '{}', edge label '{}', max depth '{}', " + "max degree '{}' and limit '{}'", graph, sourceV, direction, edgeLabel, depth, maxDegree, limit);
    Id source = VertexAPI.checkAndParseVertexId(sourceV);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    Set<Id> ids;
    try (KneighborTraverser traverser = new KneighborTraverser(g)) {
        ids = traverser.kneighbor(source, dir, edgeLabel, depth, maxDegree, limit);
    }
    return manager.serializer(g).writeList("vertices", ids);
}
Also used : KneighborTraverser(com.baidu.hugegraph.traversal.algorithm.KneighborTraverser) HugeGraph(com.baidu.hugegraph.HugeGraph) 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

Id (com.baidu.hugegraph.backend.id.Id)24 Directions (com.baidu.hugegraph.type.define.Directions)24 HugeGraph (com.baidu.hugegraph.HugeGraph)15 Timed (com.codahale.metrics.annotation.Timed)14 GET (jakarta.ws.rs.GET)14 Produces (jakarta.ws.rs.Produces)14 HugeTraverser (com.baidu.hugegraph.traversal.algorithm.HugeTraverser)6 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 RangeConditions (com.baidu.hugegraph.backend.query.Condition.RangeConditions)2 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)2 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)2 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)2 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)2 PathsTraverser (com.baidu.hugegraph.traversal.algorithm.PathsTraverser)2 PredictionTraverser (com.baidu.hugegraph.traversal.algorithm.PredictionTraverser)2 ShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser)2 SingleSourceShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser)2