0. 准备工作
- 下载 hugegraph
- 启动 HugeGraphServer
- 下载 hugegraph-studio
- 启动 HugeGraphStudio
详细步骤可参考:准备执行Gremlin的图形化环境
1. 插入数据
把以下语句拷贝到 hugegraph-studio 的 gremlin 输入框,然后点击右上角的三角图标执行。
schema = graph.schema();
schema.propertyKey("name").asText().create();
schema.propertyKey("born").asInt().create();
schema.propertyKey("title").asText().create();
schema.propertyKey("released").asInt().create();
schema.propertyKey("score").asInt().create();
schema.propertyKey("roles").asText().create();
schema.vertexLabel("person").properties("name", "born").primaryKeys("name").create();
schema.vertexLabel("movie").properties("title", "released").primaryKeys("title").create();
schema.edgeLabel("ACTED_IN").multiTimes().properties("roles").sourceLabel("person").targetLabel("movie").sortKeys("roles").create();
schema.edgeLabel("DIRECTED").properties("score").sourceLabel("person").targetLabel("movie").create();
schema.edgeLabel("PRODUCED").properties("score").sourceLabel("person").targetLabel("movie").create();
schema.edgeLabel("WROTE").properties("score").sourceLabel("person").targetLabel("movie").create();
schema.indexLabel("personByBorn").onV("person").by("born").range().create();
theMatrix = graph.addVertex(T.label, "movie", "title", "The Matrix", "released", 1999);
keanu = graph.addVertex(T.label, "person", "name", "keanu Reeves", "born", 1964);
carrie = graph.addVertex(T.label, "person", "name", "carrie-anne Moss", "born", 1967);
laurence = graph.addVertex(T.label, "person", "name", "laurence Fishburne", "born", 1961);
hugo = graph.addVertex(T.label, "person", "name", "hugo Weaving", "born", 1960);
lillyW = graph.addVertex(T.label, "person", "name", "Lilly Wachowski", "born", 1967);
lanaW = graph.addVertex(T.label, "person", "name", "Lana Wachowski", "born", 1965);
joelS = graph.addVertex(T.label, "person", "name", "Joel Silver", "born", 1952);
keanu.addEdge("ACTED_IN", theMatrix, "roles", "Neo");
carrie.addEdge("ACTED_IN", theMatrix, "roles", "Trinity");
laurence.addEdge("ACTED_IN", theMatrix, "roles", "Morpheus");
hugo.addEdge("ACTED_IN", theMatrix, "roles", "agent Smith");
lillyW.addEdge("DIRECTED", theMatrix, "score", 10);
lanaW.addEdge("DIRECTED", theMatrix, "score", 10);
joelS.addEdge("PRODUCED", theMatrix, "score", 10);
emil = graph.addVertex(T.label, "person", "name", "emil Eifrem", "born", 1978);
emil.addEdge("ACTED_IN", theMatrix, "roles", "emil");
theMatrixReloaded = graph.addVertex(T.label, "movie", "title", "The Matrix Reloaded", "released", 2003);
keanu.addEdge("ACTED_IN", theMatrixReloaded, "roles", "Neo");
carrie.addEdge("ACTED_IN", theMatrixReloaded, "roles", "Trinity");
laurence.addEdge("ACTED_IN", theMatrixReloaded, "roles", "Morpheus");
hugo.addEdge("ACTED_IN", theMatrixReloaded, "roles", "agent Smith");
lillyW.addEdge("DIRECTED", theMatrixReloaded, "score", 10);
lanaW.addEdge("DIRECTED", theMatrix, "score", 10);
joelS.addEdge("PRODUCED", theMatrixReloaded, "score", 10);
theMatrixRevolutions = graph.addVertex(T.label, "movie", "title", "The Matrix Revolutions", "released", 2003);
keanu.addEdge("ACTED_IN", theMatrixRevolutions, "roles", "Neo");
carrie.addEdge("ACTED_IN", theMatrixRevolutions, "roles", "Trinity");
laurence.addEdge("ACTED_IN", theMatrixRevolutions, "roles", "Morpheus");
hugo.addEdge("ACTED_IN", theMatrixRevolutions, "roles", "agent Smith");
lillyW.addEdge("DIRECTED", theMatrixRevolutions, "score", 10);
lanaW.addEdge("DIRECTED", theMatrixRevolutions, "score", 10);
joelS.addEdge("PRODUCED", theMatrixRevolutions, "score", 10);
theDevilsadvocate = graph.addVertex(T.label, "movie", "title", "The Devil's advocate", "released", 1997);
charlize = graph.addVertex(T.label, "person", "name", "charlize Theron", "born", 1975);
al = graph.addVertex(T.label, "person", "name", "al Pacino", "born", 1940);
taylor = graph.addVertex(T.label, "person", "name", "taylor Hackford", "born", 1944);
keanu.addEdge("ACTED_IN", theDevilsadvocate, "roles", "Kevin Lomax");
charlize.addEdge("ACTED_IN", theDevilsadvocate, "roles", "Mary ann Lomax");
al.addEdge("ACTED_IN", theDevilsadvocate, "roles", "John Milton");
taylor.addEdge("DIRECTED", theDevilsadvocate, "score", 10);
aFewGoodMen = graph.addVertex(T.label, "movie", "title", "a Few Good Men", "released", 1992);
tomC = graph.addVertex(T.label, "person", "name", "Tom Cruise", "born", 1962);
jackN = graph.addVertex(T.label, "person", "name", "Jack Nicholson", "born", 1937);
demiM = graph.addVertex(T.label, "person", "name", "Demi Moore", "born", 1962);
kevinB = graph.addVertex(T.label, "person", "name", "Kevin Bacon", "born", 1958);
kieferS = graph.addVertex(T.label, "person", "name", "Kiefer Sutherland", "born", 1966);
noahW = graph.addVertex(T.label, "person", "name", "Noah Wyle", "born", 1971);
cubaG = graph.addVertex(T.label, "person", "name", "Cuba Gooding Jr.", "born", 1968);
kevinP = graph.addVertex(T.label, "person", "name", "Kevin Pollak", "born", 1957);
jtw = graph.addVertex(T.label, "person", "name", "J.T. Walsh", "born", 1943);
jamesM = graph.addVertex(T.label, "person", "name", "James Marshall", "born", 1967);
christopherG = graph.addVertex(T.label, "person", "name", "Christopher Guest", "born", 1948);
robR = graph.addVertex(T.label, "person", "name", "Rob Reiner", "born", 1947);
aaronS = graph.addVertex(T.label, "person", "name", "aaron Sorkin", "born", 1961);
tomC.addEdge("ACTED_IN", aFewGoodMen, "roles", "Lt. Daniel Kaffee");
jackN.addEdge("ACTED_IN", aFewGoodMen, "roles", "Col. nathan R. Jessup");
demiM.addEdge("ACTED_IN", aFewGoodMen, "roles", "Lt. Cdr. Joanne Galloway");
kevinB.addEdge("ACTED_IN", aFewGoodMen, "roles", "Capt. Jack Ross");
kieferS.addEdge("ACTED_IN", aFewGoodMen, "roles", "Lt. Jonathan Kendrick");
noahW.addEdge("ACTED_IN", aFewGoodMen, "roles", "Cpl. Jeffrey Barnes");
cubaG.addEdge("ACTED_IN", aFewGoodMen, "roles", "Cpl. Carl Hammaker");
kevinP.addEdge("ACTED_IN", aFewGoodMen, "roles", "Lt. Sam Weinberg");
jtw.addEdge("ACTED_IN", aFewGoodMen, "roles", "Lt. Col. Matthew andrew Markinson");
jamesM.addEdge("ACTED_IN", aFewGoodMen, "roles", "Pfc. Louden Downey");
christopherG.addEdge("ACTED_IN", aFewGoodMen, "roles", "Dr. Stone");
aaronS.addEdge("ACTED_IN", aFewGoodMen, "roles", "Man in Bar");
robR.addEdge("DIRECTED", aFewGoodMen, "score", 10);
aaronS.addEdge("WROTE", aFewGoodMen, "score", 10);
topGun = graph.addVertex(T.label, "movie", "title", "Top Gun", "released", 1986);
kellyM = graph.addVertex(T.label, "person", "name", "Kelly McGillis", "born", 1957);
valK = graph.addVertex(T.label, "person", "name", "Val Kilmer", "born", 1959);
anthonyE = graph.addVertex(T.label, "person",