Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: params improve for personal rank api #1695

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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