org.apache.hugegraph.api.traversers.NeighborRankAPI Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.apache.hugegraph.api.traversers;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEPTH;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Singleton;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import org.apache.hugegraph.core.GraphManager;
import org.slf4j.Logger;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.api.API;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.traversal.algorithm.NeighborRankTraverser;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
@Path("graphs/{graph}/traversers/neighborrank")
@Singleton
@Tag(name = "NeighborRankAPI")
public class NeighborRankAPI extends API {
private static final Logger LOG = Log.logger(NeighborRankAPI.class);
@POST
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String neighborRank(@Context GraphManager manager,
@PathParam("graph") String graph,
RankRequest request) {
E.checkArgumentNotNull(request, "The rank request body can't be null");
E.checkArgumentNotNull(request.source,
"The source of rank request can't be null");
E.checkArgument(request.steps != null && !request.steps.isEmpty(),
"The steps of rank request can't be empty");
E.checkArgument(request.steps.size() <= DEFAULT_MAX_DEPTH,
"The steps length of rank request can't exceed %s",
DEFAULT_MAX_DEPTH);
E.checkArgument(request.alpha > 0 && request.alpha <= 1.0,
"The alpha of rank request must be in range (0, 1], " +
"but got '%s'", request.alpha);
LOG.debug("Graph [{}] get neighbor rank from '{}' with steps '{}', " +
"alpha '{}' and capacity '{}'", graph, request.source,
request.steps, request.alpha, request.capacity);
Id sourceId = HugeVertex.getIdValue(request.source);
HugeGraph g = graph(manager, graph);
List steps = steps(g, request);
NeighborRankTraverser traverser;
traverser = new NeighborRankTraverser(g, request.alpha,
request.capacity);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy