使用 hugegraph-studio 插入电影数据并查询

本文介绍了如何使用hugegraph-studio进行电影数据的插入和图查询操作。通过准备环境,将Gremlin语句在工作室中执行,实现对TomHanks参演电影、合作导演等信息的查询,包括路径查找、合作次数排序和未参演电影的搜索。
摘要由CSDN通过智能技术生成

0. 准备工作

  1. 下载 hugegraph
  2. 启动 HugeGraphServer
  3. 下载 hugegraph-studio
  4. 启动 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",
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值