Skip to content

Commit

Permalink
refact: params improve for personal rank api (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin authored Dec 15, 2021
1 parent a25b6e6 commit 9f50e67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public String get(@Context GraphManager manager,
PathsTraverser traverser = new PathsTraverser(g);
HugeTraverser.PathSet paths = traverser.paths(sourceId, dir, targetId,
dir, edgeLabel, depth,
maxDegree, capacity, limit);
maxDegree, capacity,
limit);
return manager.serializer(g).writePaths("crosspoints", paths, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public class PersonalRankAPI extends API {

private static final Logger LOG = Log.logger(RestServer.class);

private static final double DEFAULT_DIFF = 0.0001;
private static final double DEFAULT_ALPHA = 0.85;
private static final int DEFAULT_DEPTH = 5;

@POST
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
Expand All @@ -68,16 +72,19 @@ public String personalRank(@Context GraphManager manager,
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);
E.checkArgument(request.maxDiff > 0 && request.maxDiff <= 1.0,
"The max diff of rank request must be in range " +
"(0, 1], but got '%s'", request.maxDiff);
E.checkArgument(request.maxDegree > 0L || request.maxDegree == NO_LIMIT,
"The max degree of rank request must be > 0 " +
"or == -1, but got: %s", request.maxDegree);
E.checkArgument(request.limit > 0L || request.limit == NO_LIMIT,
"The limit of rank request must be > 0 or == -1, " +
"but got: %s", request.limit);
E.checkArgument(request.maxDepth > 0L &&
E.checkArgument(request.maxDepth > 1L &&
request.maxDepth <= Long.parseLong(DEFAULT_MAX_DEPTH),
"The max depth of rank request must be " +
"in range (0, %s], but got '%s'",
"in range (1, %s], but got '%s'",
DEFAULT_MAX_DEPTH, request.maxDepth);

LOG.debug("Graph [{}] get personal rank from '{}' with " +
Expand Down Expand Up @@ -105,13 +112,16 @@ private static class RankRequest {
@JsonProperty("label")
private String label;
@JsonProperty("alpha")
private double alpha;
private double alpha = DEFAULT_ALPHA;
// TODO: used for future enhancement
@JsonProperty("max_diff")
private double maxDiff = DEFAULT_DIFF;
@JsonProperty("max_degree")
private long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
@JsonProperty("limit")
private long limit = Long.parseLong(DEFAULT_LIMIT);
@JsonProperty("max_depth")
private int maxDepth;
private int maxDepth = DEFAULT_DEPTH;
@JsonProperty("with_label")
private PersonalRankTraverser.WithLabel withLabel =
PersonalRankTraverser.WithLabel.BOTH_LABEL;
Expand All @@ -121,11 +131,11 @@ private static class RankRequest {
@Override
public String toString() {
return String.format("RankRequest{source=%s,label=%s,alpha=%s," +
"maxDegree=%s,limit=%s,maxDepth=%s," +
"withLabel=%s,sorted=%s}",
"maxDiff=%s,maxDegree=%s,limit=%s," +
"maxDepth=%s,withLabel=%s,sorted=%s}",
this.source, this.label, this.alpha,
this.maxDegree, this.limit, this.maxDepth,
this.withLabel, this.sorted);
this.maxDiff, this.maxDegree, this.limit,
this.maxDepth, this.withLabel, this.sorted);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.apache.commons.collections.CollectionUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
Expand Down Expand Up @@ -60,13 +61,16 @@
import com.baidu.hugegraph.util.CollectionUtil;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.InsertionOrderUtil;
import com.baidu.hugegraph.util.Log;
import com.baidu.hugegraph.util.collection.CollectionFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

public class HugeTraverser {

protected static final Logger LOG = Log.logger(HugeTraverser.class);

private HugeGraph graph;

private static CollectionFactory collectionFactory;
Expand Down Expand Up @@ -618,7 +622,7 @@ public int hashCode() {
*/
@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof Path)) {
if (!(other instanceof Path)) {
return false;
}
return this.vertices.equals(((Path) other).vertices);
Expand Down

0 comments on commit 9f50e67

Please sign in to comment.