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

feat: support edgeexistence api #539

Closed
wants to merge 4 commits into from
Closed
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 @@ -28,6 +28,7 @@ GIT_DIR=hugegraph
# download code and compile
git clone --depth 100 ${HUGEGRAPH_GIT_URL} $GIT_DIR
cd "${GIT_DIR}"
git log
git checkout "${COMMIT_ID}"
mvn package -DskipTests -Dmaven.javadoc.skip=true -ntp

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.traverser;


import org.apache.hugegraph.api.graph.GraphAPI;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.rest.RestResult;
import org.apache.hugegraph.structure.graph.Edge;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class EdgeExistenceAPI extends TraversersAPI {

public EdgeExistenceAPI(RestClient client, String graph) {
super(client, graph);
}

@Override
protected String type() {
return "edgeexistence";
}

public List<Edge> get(Object sourceId, Object targetId, String edgeLabel,
String sortValues, long limit) {
String source = GraphAPI.formatVertexId(sourceId, false);
String target = GraphAPI.formatVertexId(targetId, false);

checkLimit((int) limit);

Map<String, Object> params = new LinkedHashMap<>();
params.put("source", source);
params.put("target", target);
params.put("label", edgeLabel);
params.put("sortValues", sortValues);
params.put("limit", limit);
RestResult result = this.client.get(this.path(), params);
return result.readList(this.type(), Edge.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.hugegraph.api.traverser.TemplatePathsAPI;
import org.apache.hugegraph.api.traverser.VerticesAPI;
import org.apache.hugegraph.api.traverser.WeightedShortestPathAPI;
import org.apache.hugegraph.api.traverser.EdgeExistenceAPI;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Edges;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class TraverserManager {
private PersonalRankAPI personalRankAPI;
private VerticesAPI verticesAPI;
private EdgesAPI edgesAPI;
private EdgeExistenceAPI edgeExistenceAPI;

public TraverserManager(RestClient client, GraphManager graphManager) {
this.graphManager = graphManager;
Expand All @@ -124,6 +126,7 @@ public TraverserManager(RestClient client, GraphManager graphManager) {
this.personalRankAPI = new PersonalRankAPI(client, graph);
this.verticesAPI = new VerticesAPI(client, graph);
this.edgesAPI = new EdgesAPI(client, graph);
this.edgeExistenceAPI = new EdgeExistenceAPI(client, graph);
}

public double jaccardSimilarity(Object vertexId, Object otherId) {
Expand Down Expand Up @@ -538,4 +541,10 @@ public Iterator<Edge> iteratorEdges(Shard shard, int sizePerPage) {
return this.edges(shard, page, sizePerPage);
});
}

public List<Edge> edgeExistence(Object sourceId, Object targetId, String edgeLabel,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add this 2 versions:

edgeExistence(Object sourceId, Object targetId)
edgeExistence(Object sourceId, Object targetId, String edgeLabel)

String sortValues, long limit){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect int limit

return this.edgeExistenceAPI.get(sourceId, targetId, edgeLabel,
sortValues, limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems one line is ok

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.hugegraph.api.traverser.SingleSourceShortestPathApiTest;
import org.apache.hugegraph.api.traverser.TemplatePathsApiTest;
import org.apache.hugegraph.api.traverser.WeightedShortestPathApiTest;
import org.apache.hugegraph.api.traverser.EdgeExistenceAPITest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand Down Expand Up @@ -84,6 +85,7 @@
FusiformSimilarityApiTest.class,
NeighborRankApiTest.class,
PersonalRankApiTest.class,
EdgeExistenceAPITest.class,

TargetApiTest.class,
GroupApiTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hugegraph.api.schema.SchemaAPI;
import org.apache.hugegraph.api.schema.VertexLabelAPI;
import org.apache.hugegraph.api.task.TaskAPI;
import org.apache.hugegraph.api.traverser.EdgeExistenceAPI;
import org.apache.hugegraph.api.variables.VariablesAPI;
import org.apache.hugegraph.api.version.VersionAPI;
import org.apache.hugegraph.client.RestClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.traverser;


import org.apache.hugegraph.api.BaseApiTest;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.testutil.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

public class EdgeExistenceAPITest extends TraverserApiTest{

@BeforeClass
public static void prepareSchemaAndGraph() {
BaseApiTest.initPropertyKey();
BaseApiTest.initVertexLabel();
BaseApiTest.initEdgeLabel();
BaseApiTest.initIndexLabel();
BaseApiTest.initVertex();
BaseApiTest.initEdge();
}

@Test
public void testEdgeExistenceGet() {
Object markoId = getVertexId("person", "name", "marko");
Object vadasId = getVertexId("person", "name", "vadas");

List<Edge> edges = edgeExistenceAPI.get(markoId, vadasId,
"knows", "", 100);

Assert.assertEquals(1, edges.size());
String id = edges.get(0).id();

Assert.assertTrue(id.contains("marko"));
Assert.assertTrue(id.contains("vadas"));

Object lopId = getVertexId("software", "name", "lop");

edges = edgeExistenceAPI.get(lopId, vadasId,
"knows", "", 100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems one line is ok

Assert.assertEquals(0, edges.size());

Object joshId = getVertexId("person", "name", "josh");
Object rippleId = getVertexId("person", "name", "ripple");

edges = edgeExistenceAPI.get(joshId, rippleId,
"created", "", 100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems one line is ok

Assert.assertEquals(1, edges.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TraverserApiTest extends BaseApiTest {

protected static VerticesAPI verticesAPI;
protected static EdgesAPI edgesAPI;
protected static EdgeExistenceAPI edgeExistenceAPI;

@BeforeClass
public static void init() {
Expand Down Expand Up @@ -82,5 +83,7 @@ public static void init() {

verticesAPI = new VerticesAPI(client, GRAPH);
edgesAPI = new EdgesAPI(client, GRAPH);

edgeExistenceAPI = new EdgeExistenceAPI(client, GRAPH);
}
}
Loading