use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeApiTest method testCreateWithoutSourceOrTargetLabel.
@Test
public void testCreateWithoutSourceOrTargetLabel() {
Object outVId = getVertexId("person", "name", "peter");
Object inVId = getVertexId("software", "name", "lop");
Edge edge = new Edge("created");
edge.sourceId(outVId);
edge.targetId(inVId);
edge.property("date", "2017-03-24");
edge.property("city", "Hongkong");
edge = edgeAPI.create(edge);
Assert.assertEquals("created", edge.label());
Assert.assertEquals("person", edge.sourceLabel());
Assert.assertEquals("software", edge.targetLabel());
Assert.assertEquals(outVId, edge.sourceId());
Assert.assertEquals(inVId, edge.targetId());
String date = Utils.formatDate("2017-03-24");
Map<String, Object> props = ImmutableMap.of("date", date, "city", "Hongkong");
Assert.assertEquals(props, edge.properties());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class GraphManager method addEdge.
public Edge addEdge(Object sourceId, String label, Object targetId, Map<String, Object> properties) {
Edge edge = new Edge(label);
edge.sourceId(sourceId);
edge.targetId(targetId);
this.attachProperties(edge, properties);
return this.addEdge(edge);
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class GraphManager method getEdge.
public Edge getEdge(String edgeId) {
Edge edge = this.edgeAPI.get(edgeId);
this.attachManager(edge);
return edge;
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class BatchExample method main.
public static void main(String[] args) {
// If connect failed will throw a exception.
HugeClient hugeClient = HugeClient.builder("http://localhost:8080", "hugegraph").build();
SchemaManager schema = hugeClient.schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("lang").asText().ifNotExist().create();
schema.propertyKey("date").asDate().ifNotExist().create();
schema.propertyKey("price").asInt().ifNotExist().create();
schema.vertexLabel("person").properties("name", "age").primaryKeys("name").ifNotExist().create();
schema.vertexLabel("person").properties("price").nullableKeys("price").append();
schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create();
schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create();
schema.edgeLabel("knows").link("person", "person").properties("date").ifNotExist().create();
schema.edgeLabel("created").link("person", "software").properties("date").ifNotExist().create();
schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create();
// get schema object by name
System.out.println(schema.getPropertyKey("name"));
System.out.println(schema.getVertexLabel("person"));
System.out.println(schema.getEdgeLabel("knows"));
System.out.println(schema.getIndexLabel("createdByDate"));
// list all schema objects
System.out.println(schema.getPropertyKeys());
System.out.println(schema.getVertexLabels());
System.out.println(schema.getEdgeLabels());
System.out.println(schema.getIndexLabels());
GraphManager graph = hugeClient.graph();
Vertex marko = new Vertex("person").property("name", "marko").property("age", 29);
Vertex vadas = new Vertex("person").property("name", "vadas").property("age", 27);
Vertex lop = new Vertex("software").property("name", "lop").property("lang", "java").property("price", 328);
Vertex josh = new Vertex("person").property("name", "josh").property("age", 32);
Vertex ripple = new Vertex("software").property("name", "ripple").property("lang", "java").property("price", 199);
Vertex peter = new Vertex("person").property("name", "peter").property("age", 35);
Edge markoKnowsVadas = new Edge("knows").source(marko).target(vadas).property("date", "2016-01-10");
Edge markoKnowsJosh = new Edge("knows").source(marko).target(josh).property("date", "2013-02-20");
Edge markoCreateLop = new Edge("created").source(marko).target(lop).property("date", "2017-12-10");
Edge joshCreateRipple = new Edge("created").source(josh).target(ripple).property("date", "2017-12-10");
Edge joshCreateLop = new Edge("created").source(josh).target(lop).property("date", "2009-11-11");
Edge peterCreateLop = new Edge("created").source(peter).target(lop).property("date", "2017-03-24");
List<Vertex> vertices = new ArrayList<>();
vertices.add(marko);
vertices.add(vadas);
vertices.add(lop);
vertices.add(josh);
vertices.add(ripple);
vertices.add(peter);
List<Edge> edges = new ArrayList<>();
edges.add(markoKnowsVadas);
edges.add(markoKnowsJosh);
edges.add(markoCreateLop);
edges.add(joshCreateRipple);
edges.add(joshCreateLop);
edges.add(peterCreateLop);
vertices = graph.addVertices(vertices);
vertices.forEach(vertex -> System.out.println(vertex));
edges = graph.addEdges(edges, false);
edges.forEach(edge -> System.out.println(edge));
hugeClient.close();
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testAutoCreateSchema.
/**
* NOTE: Unsupport auto create schema
*/
// @Test
public void testAutoCreateSchema() {
String[] args = new String[] { "-f", "example/struct.json", "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2" };
HugeGraphLoader.main(args);
List<PropertyKey> propertyKeys = CLIENT.schema().getPropertyKeys();
propertyKeys.forEach(pkey -> {
Assert.assertEquals(DataType.TEXT, pkey.dataType());
});
List<Vertex> vertices = CLIENT.graph().listVertices();
List<Edge> edges = CLIENT.graph().listEdges();
Assert.assertEquals(7, vertices.size());
Assert.assertEquals(6, edges.size());
boolean interestedVertex = false;
for (Vertex vertex : vertices) {
Assert.assertEquals(String.class, vertex.id().getClass());
if (((String) vertex.id()).contains("li,nary")) {
interestedVertex = true;
Assert.assertEquals("26", vertex.property("age"));
Assert.assertEquals("Wu,han", vertex.property("city"));
}
}
Assert.assertTrue(interestedVertex);
boolean interestedEdge = false;
for (Edge edge : edges) {
Assert.assertEquals(String.class, edge.sourceId().getClass());
Assert.assertEquals(String.class, edge.targetId().getClass());
if (((String) edge.sourceId()).contains("marko") && ((String) edge.targetId()).contains("vadas")) {
interestedEdge = true;
Assert.assertEquals("20160110", edge.property("date"));
Assert.assertEquals("0.5", edge.property("weight"));
}
}
Assert.assertTrue(interestedEdge);
}
Aggregations