本文整理了Java中org.vertexium.Graph.addEdge()
方法的一些代码示例,展示了Graph.addEdge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.addEdge()
方法的具体详情如下:
包路径:org.vertexium.Graph
类名称:Graph
方法名:addEdge
[英]Adds an edge between two vertices.
[中]在两个顶点之间添加边。
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testGraphQueryForEdgesUsingInOrOutVertexId() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.IN_OR_OUT_VERTEX_ID_PROPERTY_NAME, "v1")
.edges();
assertEdgeIdsAnyOrder(edges, "e1", "e2");
}
代码示例来源:origin: visallo/vertexium
@Test
public void testGraphQueryForEdgesUsingInOrOutVertexId() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.IN_OR_OUT_VERTEX_ID_PROPERTY_NAME, "v1")
.edges();
assertEdgeIdsAnyOrder(edges, "e1", "e2");
}
代码示例来源:origin: visallo/vertexium
@Test
public void testFetchHintsEdgeLabels() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_ALL);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.flush();
graph.addEdge("e v1->v2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.addEdge("e v1->v3", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.flush();
v1 = graph.getVertex("v1", FetchHints.EDGE_LABELS, AUTHORIZATIONS_ALL);
List<String> edgeLabels = toList(v1.getEdgesSummary(AUTHORIZATIONS_ALL).getEdgeLabels());
assertEquals(2, edgeLabels.size());
assertTrue(LABEL_LABEL1 + " missing", edgeLabels.contains(LABEL_LABEL1));
assertTrue(LABEL_LABEL2 + " missing", edgeLabels.contains(LABEL_LABEL2));
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testFetchHintsEdgeLabels() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_ALL);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.flush();
graph.addEdge("e v1->v2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.addEdge("e v1->v3", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_ALL);
graph.flush();
v1 = graph.getVertex("v1", FetchHints.EDGE_LABELS, AUTHORIZATIONS_ALL);
List<String> edgeLabels = toList(v1.getEdgesSummary(AUTHORIZATIONS_ALL).getEdgeLabels());
assertEquals(2, edgeLabels.size());
assertTrue(LABEL_LABEL1 + " missing", edgeLabels.contains(LABEL_LABEL1));
assertTrue(LABEL_LABEL2 + " missing", edgeLabels.contains(LABEL_LABEL2));
}
代码示例来源:origin: visallo/vertexium
@Test
public void testGraphQueryForEdgesUsingEdgeLabel() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e3", v3, v1, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL1)
.edges();
assertEdgeIdsAnyOrder(edges, "e1");
edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL2)
.edges();
assertEdgeIdsAnyOrder(edges, "e2", "e3");
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testGraphQueryForEdgesUsingEdgeLabel() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e3", v3, v1, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL1)
.edges();
assertEdgeIdsAnyOrder(edges, "e1");
edges = graph.query(AUTHORIZATIONS_A)
.has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL2)
.edges();
assertEdgeIdsAnyOrder(edges, "e2", "e3");
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testGetEdgesInRange() {
graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("a", "v1", "v2", LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_ALL);
graph.addEdge("aa", "v1", "v2", LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_ALL);
graph.addEdge("az", "v1", "v2", LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_ALL);
graph.addEdge("b", "v1", "v2", LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_ALL);
graph.flush();
List<Edge> edges = toList(graph.getEdgesInRange(new Range(null, "a"), AUTHORIZATIONS_ALL));
assertEdgeIds(edges);
edges = toList(graph.getEdgesInRange(new Range(null, "b"), AUTHORIZATIONS_ALL));
assertEdgeIds(edges, "a", "aa", "az");
edges = toList(graph.getEdgesInRange(new Range(null, "bb"), AUTHORIZATIONS_ALL));
assertEdgeIds(edges, "a", "aa", "az", "b");
edges = toList(graph.getEdgesInRange(new Range(null, null), AUTHORIZATIONS_ALL));
assertEdgeIds(edges, "a", "aa", "az", "b");
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testFindRelatedEdgeSummaryAfterMarkedHidden() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Edge e1 = graph.addEdge("e v1->v2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
List<String> vertexIds = new ArrayList<>();
vertexIds.add("v1");
vertexIds.add("v2");
List<RelatedEdge> relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(1, relatedEdges.size());
org.vertexium.test.util.IterableUtils.assertContains(new RelatedEdgeImpl("e v1->v2", LABEL_LABEL1, v1.getId(), v2.getId()), relatedEdges);
graph.markEdgeHidden(e1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(0, relatedEdges.size());
}
代码示例来源:origin: visallo/vertexium
@Test
public void testFindRelatedEdgeSummaryAfterSoftDelete() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Edge e1 = graph.addEdge("e v1->v2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
List<String> vertexIds = new ArrayList<>();
vertexIds.add("v1");
vertexIds.add("v2");
List<RelatedEdge> relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(1, relatedEdges.size());
org.vertexium.test.util.IterableUtils.assertContains(new RelatedEdgeImpl("e v1->v2", LABEL_LABEL1, v1.getId(), v2.getId()), relatedEdges);
graph.softDeleteEdge(e1, AUTHORIZATIONS_A);
graph.flush();
relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(0, relatedEdges.size());
}
代码示例来源:origin: visallo/vertexium
@Test
public void testFindRelatedEdgeSummaryAfterMarkedHidden() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
Edge e1 = graph.addEdge("e v1->v2", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
List<String> vertexIds = new ArrayList<>();
vertexIds.add("v1");
vertexIds.add("v2");
List<RelatedEdge> relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(1, relatedEdges.size());
org.vertexium.test.util.IterableUtils.assertContains(new RelatedEdgeImpl("e v1->v2", LABEL_LABEL1, v1.getId(), v2.getId()), relatedEdges);
graph.markEdgeHidden(e1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
relatedEdges = toList(graph.findRelatedEdgeSummary(vertexIds, AUTHORIZATIONS_A));
assertEquals(0, relatedEdges.size());
}
代码示例来源:origin: org.vertexium/vertexium-blueprints
@Override
public Edge addEdge(Object id, Vertex outVertex, Vertex inVertex, String label) {
if (label == null) {
throw new IllegalArgumentException("label cannot be null");
}
org.vertexium.Vertex sgOutVertex = VertexiumBlueprintsConvert.toVertexium(outVertex);
org.vertexium.Vertex sgInVertex = VertexiumBlueprintsConvert.toVertexium(inVertex);
Visibility visibility = getVisibilityProvider().getVisibilityForEdge(VertexiumBlueprintsConvert.idToString(id), sgOutVertex, sgInVertex, label);
Authorizations authorizations = getAuthorizationsProvider().getAuthorizations();
return VertexiumBlueprintsEdge.create(this, getGraph().addEdge(VertexiumBlueprintsConvert.idToString(id), sgOutVertex, sgInVertex, label, visibility, authorizations), authorizations);
}
代码示例来源:origin: visallo/vertexium
@Test
public void testGetCounts() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
assertEquals(2, graph.getVertexCount(AUTHORIZATIONS_A));
assertEquals(1, graph.getEdgeCount(AUTHORIZATIONS_A));
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testGetCounts() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
assertEquals(2, graph.getVertexCount(AUTHORIZATIONS_A));
assertEquals(1, graph.getEdgeCount(AUTHORIZATIONS_A));
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testFindPathsWithSoftDeletedEdges() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_EMPTY, AUTHORIZATIONS_A);
Vertex v3 = graph.addVertex("v3", VISIBILITY_EMPTY, AUTHORIZATIONS_A);
graph.addEdge(v1, v2, LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_A); // v1 -> v2
Edge v2ToV3 = graph.addEdge(v2, v3, LABEL_LABEL1, VISIBILITY_EMPTY, AUTHORIZATIONS_A); // v2 -> v3
graph.flush();
List<Path> paths = toList(graph.findPaths(new FindPathOptions("v1", "v3", 2), AUTHORIZATIONS_A));
assertPaths(
paths,
new Path("v1", "v2", "v3")
);
graph.softDeleteEdge(v2ToV3, AUTHORIZATIONS_A);
graph.flush();
assertNull(graph.getEdge(v2ToV3.getId(), AUTHORIZATIONS_A));
paths = toList(graph.findPaths(new FindPathOptions("v1", "v3", 2), AUTHORIZATIONS_A));
assertEquals(0, paths.size());
}
代码示例来源:origin: visallo/vertexium
@Test
public void testAddEdgeWithVisibility() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v2, LABEL_LABEL2, VISIBILITY_B, AUTHORIZATIONS_B);
graph.flush();
Iterable<Edge> aEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_A);
Assert.assertEquals(1, count(aEdges));
assertEquals(LABEL_LABEL1, IterableUtils.single(aEdges).getLabel());
Iterable<Edge> bEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_B);
Assert.assertEquals(1, count(bEdges));
assertEquals(LABEL_LABEL2, IterableUtils.single(bEdges).getLabel());
Iterable<Edge> allEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_A_AND_B);
Assert.assertEquals(2, count(allEdges));
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testAddEdgeWithVisibility() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e2", v1, v2, LABEL_LABEL2, VISIBILITY_B, AUTHORIZATIONS_B);
graph.flush();
Iterable<Edge> aEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_A);
Assert.assertEquals(1, count(aEdges));
assertEquals(LABEL_LABEL1, IterableUtils.single(aEdges).getLabel());
Iterable<Edge> bEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_B);
Assert.assertEquals(1, count(bEdges));
assertEquals(LABEL_LABEL2, IterableUtils.single(bEdges).getLabel());
Iterable<Edge> allEdges = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getEdges(Direction.BOTH, AUTHORIZATIONS_A_AND_B);
Assert.assertEquals(2, count(allEdges));
}
代码示例来源:origin: visallo/vertexium
@Test(expected = VertexiumNotSupportedException.class)
public void testRetrievingVerticesFromElasticsearchEdge() {
graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.edges(FetchHints.NONE);
assertResultsCount(1, 1, edges);
toList(edges).get(0).getVertices(AUTHORIZATIONS_A);
}
代码示例来源:origin: visallo/vertexium
@Test
public void testQueryReturningElasticsearchVertex() {
graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_B);
graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_B)
.vertices(FetchHints.NONE);
assertResultsCount(1, 1, vertices);
Vertex vertex = toList(vertices).get(0);
assertEquals("v2", vertex.getId());
}
代码示例来源:origin: org.vertexium/vertexium-test
@Test
public void testGraphQueryWithQueryStringWithAuthorizations() {
Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL);
v1.setProperty("description", "This is vertex 1 - dog.", VISIBILITY_A, AUTHORIZATIONS_ALL);
Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_ALL);
v2.setProperty("description", "This is vertex 2 - cat.", VISIBILITY_B, AUTHORIZATIONS_ALL);
Edge e1 = graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
e1.setProperty("edgeDescription", "This is edge 1 - dog to cat.", VISIBILITY_A, AUTHORIZATIONS_ALL);
getGraph().flush();
Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices();
assertEquals(1, count(vertices));
if (isIterableWithTotalHitsSupported(vertices)) {
IterableWithTotalHits hits = (IterableWithTotalHits) vertices;
assertEquals(1, hits.getTotalHits());
}
Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A).edges();
assertEquals(1, count(edges));
}
代码示例来源:origin: visallo/vertexium
@Test
public void testQueryReturningElasticsearchEdge() {
graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A);
graph.addEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A);
graph.flush();
QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A)
.edges(FetchHints.NONE);
assertResultsCount(1, 1, edges);
Edge e1 = toList(edges).get(0);
assertEquals(LABEL_LABEL1, e1.getLabel());
assertEquals("v1", e1.getVertexId(Direction.OUT));
assertEquals("v2", e1.getVertexId(Direction.IN));
assertEquals("e1", e1.getId());
}
内容来源于网络,如有侵权,请联系作者删除!