本文整理匯總了Java中org.apache.tinkerpop.gremlin.structure.Vertex.addEdge方法的典型用法代碼示例。如果您正苦於以下問題:Java Vertex.addEdge方法的具體用法?Java Vertex.addEdge怎麽用?Java Vertex.addEdge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.tinkerpop.gremlin.structure.Vertex
的用法示例。
在下文中一共展示了Vertex.addEdge方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldLoseTypesWithGraphSONNoTypesForEdgeIds
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
/**
* Asserts the approximateGraphsChecks function fails when expected. Edge ids.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeIds() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final TinkerGraph sampleGraph1 = TinkerGraph.open();
TinkerFactory.generateModern(sampleGraph1);
final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101L);
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized edge Id.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:21,代碼來源:TinkerGraphGraphSONSerializerV2d0Test.java
示例2: shouldLoseTypesWithGraphSONNoTypesForEdgeProps
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
/**
* Asserts the approximateGraphsChecks function fails when expected. Edge props.
*/
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
final GraphWriter writer = getWriter(noTypesMapperV2d0);
final GraphReader reader = getReader(noTypesMapperV2d0);
final Graph sampleGraph1 = TinkerFactory.createModern();
final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
"uuid", UUID.randomUUID());
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, sampleGraph1);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
// Should fail on deserialized edge prop.
assertFalse(approximateGraphsCheck(sampleGraph1, read));
}
}
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:22,代碼來源:TinkerGraphGraphSONSerializerV2d0Test.java
示例3: deserializersTestsTinkerGraph
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test
public void deserializersTestsTinkerGraph() {
final TinkerGraph tg = TinkerGraph.open();
final Vertex v = tg.addVertex("vertexTest");
final Vertex v2 = tg.addVertex("vertexTest");
v.addEdge("knows", v2);
final GraphWriter writer = getWriter(defaultMapperV2d0);
final GraphReader reader = getReader(defaultMapperV2d0);
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeObject(out, tg);
final String json = out.toString();
final Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
assertTrue(approximateGraphsCheck(tg, gRead));
} catch (IOException e) {
e.printStackTrace();
fail("Should not have thrown exception: " + e.getMessage());
}
}
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:24,代碼來源:TinkerGraphGraphSONSerializerV2d0Test.java
示例4: shouldUpdateEdgeIndicesInNewGraph
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test
public void shouldUpdateEdgeIndicesInNewGraph() {
final TinkerGraph g = TinkerGraph.open();
g.createIndex("oid", Edge.class);
final Vertex v = g.addVertex();
v.addEdge("friend", v, "oid", "1", "weight", 0.5f);
v.addEdge("friend", v, "oid", "2", "weight", 0.6f);
// a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has()
// to get into the Pipeline and evaluate what's going through it. in this case, we know that at index
// is used because only oid 1 should pass through the pipeline due to the inclusion of the
// key index lookup on "oid". If there's an weight of something other than 0.5f in the pipeline being
// evaluated then something is wrong.
assertEquals(new Long(1), g.traversal().E().has("weight", P.test((t, u) -> {
assertEquals(0.5f, t);
return true;
}, 0.5)).has("oid", "1").count().next());
}
示例5: shouldRemoveEdgeFromAnIndex
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test
public void shouldRemoveEdgeFromAnIndex() {
final TinkerGraph g = TinkerGraph.open();
g.createIndex("oid", Edge.class);
final Vertex v = g.addVertex();
v.addEdge("friend", v, "oid", "1", "weight", 0.5f);
final Edge e = v.addEdge("friend", v, "oid", "1", "weight", 0.5f);
v.addEdge("friend", v, "oid", "2", "weight", 0.6f);
// a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has()
// to get into the Pipeline and evaluate what's going through it. in this case, we know that at index
// is used because only oid 1 should pass through the pipeline due to the inclusion of the
// key index lookup on "oid". If there's an weight of something other than 0.5f in the pipeline being
// evaluated then something is wrong.
assertEquals(new Long(2), g.traversal().E().has("weight", P.test((t, u) -> {
assertEquals(0.5f, t);
return true;
}, 0.5)).has("oid", "1").count().next());
e.remove();
assertEquals(new Long(1), g.traversal().E().has("weight", P.test((t, u) -> {
assertEquals(0.5f, t);
return true;
}, 0.5)).has("oid", "1").count().next());
}
示例6: write
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Override
public void write(final Kryo kryo, final Output output, final Color color) {
final TinkerGraph graph = TinkerGraph.open();
final Vertex v = graph.addVertex(T.id, 1, T.label, "color", "name", color.toString());
final Vertex vRed = graph.addVertex(T.id, 2, T.label, "primary", "name", "red");
final Vertex vGreen = graph.addVertex(T.id, 3, T.label, "primary", "name", "green");
final Vertex vBlue = graph.addVertex(T.id, 4, T.label, "primary", "name", "blue");
v.addEdge("hasComponent", vRed, "amount", color.getRed());
v.addEdge("hasComponent", vGreen, "amount", color.getGreen());
v.addEdge("hasComponent", vBlue, "amount", color.getBlue());
// make some junk so the graph is kinda big
generate(graph);
try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
GryoWriter.build().mapper(() -> kryo).create().writeGraph(stream, graph);
final byte[] bytes = stream.toByteArray();
output.writeInt(bytes.length);
output.write(bytes);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例7: generate
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
private static void generate(final Graph graph) {
final int size = 100;
final List<Object> ids = new ArrayList<>();
final Vertex v = graph.addVertex("sin", 0.0f, "cos", 1.0f, "ii", 0f);
ids.add(v.id());
final GraphTraversalSource g = graph.traversal();
final Random rand = new Random();
for (int ii = 1; ii < size; ii++) {
final Vertex t = graph.addVertex("ii", ii, "sin", Math.sin(ii / 5.0f), "cos", Math.cos(ii / 5.0f));
final Vertex u = g.V(ids.get(rand.nextInt(ids.size()))).next();
t.addEdge("linked", u);
ids.add(u.id());
ids.add(v.id());
}
}
示例8: generateClassic
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
public static void generateClassic(final TinkerGraph g) {
final Vertex marko = g.addVertex(T.id, 1, "name", "marko", "age", 29);
final Vertex vadas = g.addVertex(T.id, 2, "name", "vadas", "age", 27);
final Vertex lop = g.addVertex(T.id, 3, "name", "lop", "lang", "java");
final Vertex josh = g.addVertex(T.id, 4, "name", "josh", "age", 32);
final Vertex ripple = g.addVertex(T.id, 5, "name", "ripple", "lang", "java");
final Vertex peter = g.addVertex(T.id, 6, "name", "peter", "age", 35);
marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5f);
marko.addEdge("knows", josh, T.id, 8, "weight", 1.0f);
marko.addEdge("created", lop, T.id, 9, "weight", 0.4f);
josh.addEdge("created", ripple, T.id, 10, "weight", 1.0f);
josh.addEdge("created", lop, T.id, 11, "weight", 0.4f);
peter.addEdge("created", lop, T.id, 12, "weight", 0.2f);
}
示例9: generateModern
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
public static void generateModern(final TinkerGraph g) {
final Vertex marko = g.addVertex(T.id, 1, T.label, "person", "name", "marko", "age", 29);
final Vertex vadas = g.addVertex(T.id, 2, T.label, "person", "name", "vadas", "age", 27);
final Vertex lop = g.addVertex(T.id, 3, T.label, "software", "name", "lop", "lang", "java");
final Vertex josh = g.addVertex(T.id, 4, T.label, "person", "name", "josh", "age", 32);
final Vertex ripple = g.addVertex(T.id, 5, T.label, "software", "name", "ripple", "lang", "java");
final Vertex peter = g.addVertex(T.id, 6, T.label, "person", "name", "peter", "age", 35);
marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5d);
marko.addEdge("knows", josh, T.id, 8, "weight", 1.0d);
marko.addEdge("created", lop, T.id, 9, "weight", 0.4d);
josh.addEdge("created", ripple, T.id, 10, "weight", 1.0d);
josh.addEdge("created", lop, T.id, 11, "weight", 0.4d);
peter.addEdge("created", lop, T.id, 12, "weight", 0.2d);
}
示例10: addStatementInternal
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
Statement addStatementInternal(final Vertex outV, final Vertex inV, final String label, final String context) {
Edge edge = outV.addEdge(label, inV);
registerStatementAdded();
if (null != context) {
edge.property(Schema.EdgeProperties.CONTEXT, context);
}
return toStatement(edge);
}
示例11: shouldNotAllowMixingWithGenericEdge
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowMixingWithGenericEdge() throws IOException {
TinkerGraph graph = newGratefulDeadGraphWithSpecializedElements();
GraphTraversalSource g = graph.traversal();
List<Vertex> vertices = g.V().limit(2).toList();
Vertex v1 = vertices.get(0);
Vertex v2 = vertices.get(1);
v1.addEdge("something_else", v2);
}
示例12: importGraph
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
private static void importGraph(HDT hdt, Graph graph) {
Dictionary d = hdt.getDictionary();
long [] sharedMap = new long[(int)d.getNshared()];
long [] subjectMap = new long[(int)(d.getNsubjects()-d.getNshared())];
// long [] predicateMap = new long[(int)d.getNpredicates()];
long [] objectMap = new long[(int)(d.getNobjects()-d.getNshared())];
// load(predicateMap, d.getPredicates().getSortedEntries(), to);
loadSection(sharedMap, d.getShared().getSortedEntries(), graph, DictionarySectionRole.SHARED);
loadSection(subjectMap, d.getSubjects().getSortedEntries(), graph, DictionarySectionRole.SUBJECT);
loadSection(objectMap, d.getObjects().getSortedEntries(), graph, DictionarySectionRole.OBJECT);
IteratorTripleID it = hdt.getTriples().searchAll();
int count=0;
while(it.hasNext()) {
TripleID triple = it.next();
long s = getIDShared(sharedMap, subjectMap, triple.getSubject());
// long p = predicateMap[triple.getPredicate()-1];
long o = getIDShared(sharedMap, objectMap, triple.getObject());
Vertex subj = graph.vertices(s).next();
Vertex obj = graph.vertices(o).next();
subj.addEdge(d.idToString(triple.getPredicate(), TripleComponentRole.PREDICATE).toString(), obj);
if((count%10000)==0) {
System.out.println("Edges: "+(count/1000)+"K");
}
count++;
}
}
示例13: shouldCloneTinkergraph
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test
public void shouldCloneTinkergraph() {
final TinkerGraph original = TinkerGraph.open();
final TinkerGraph clone = TinkerGraph.open();
final Vertex marko = original.addVertex("name", "marko", "age", 29);
final Vertex stephen = original.addVertex("name", "stephen", "age", 35);
marko.addEdge("knows", stephen);
GraphHelper.cloneElements(original, clone);
final Vertex michael = clone.addVertex("name", "michael");
michael.addEdge("likes", marko);
michael.addEdge("likes", stephen);
clone.traversal().V().property("newProperty", "someValue").toList();
clone.traversal().E().property("newProperty", "someValue").toList();
assertEquals("original graph should be unchanged", new Long(2), original.traversal().V().count().next());
assertEquals("original graph should be unchanged", new Long(1), original.traversal().E().count().next());
assertEquals("original graph should be unchanged", new Long(0), original.traversal().V().has("newProperty").count().next());
assertEquals("cloned graph should contain new elements", new Long(3), clone.traversal().V().count().next());
assertEquals("cloned graph should contain new elements", new Long(3), clone.traversal().E().count().next());
assertEquals("cloned graph should contain new property", new Long(3), clone.traversal().V().has("newProperty").count().next());
assertEquals("cloned graph should contain new property", new Long(3), clone.traversal().E().has("newProperty").count().next());
assertNotSame("cloned elements should reference to different objects",
original.traversal().V().has("name", "stephen").next(),
clone.traversal().V().has("name", "stephen").next());
}
示例14: shouldUseLongIdManagerToCoerceTypes
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
@Test
public void shouldUseLongIdManagerToCoerceTypes() {
final Graph graph = TinkerGraph.open(longIdManagerConfig);
final Vertex v = graph.addVertex(T.id, vertexIdValue);
final VertexProperty vp = v.property(VertexProperty.Cardinality.single, "test", "value", T.id, vertexPropertyIdValue);
final Edge e = v.addEdge("self", v, T.id, edgeIdValue);
assertEquals(100l, v.id());
assertEquals(200l, e.id());
assertEquals(300l, vp.id());
}
示例15: generateFollows
import org.apache.tinkerpop.gremlin.structure.Vertex; //導入方法依賴的package包/類
private Vertex[] generateFollows(Vertex forUser, Vertex[] users, int count){
Vertex[] followedUsers = new Vertex[count];
for(int i = 0; i < count; i++) {
followedUsers[i] = users[faker.number().numberBetween(0, users.length - 1)];
Edge follows = forUser.addEdge(Schema.FOLLOWS, followedUsers[i], Schema.CREATED_AT, getTimestamp());
}
return followedUsers;
}