VGalaxies commented on code in PR #268:
URL:
https://github.com/apache/incubator-hugegraph-doc/pull/268#discussion_r1226337719
##########
content/cn/docs/clients/gremlin-console.md:
##########
@@ -4,305 +4,203 @@ linkTitle: "Gremlin Console"
weight: 3
---
-Gremlin-Console是由Tinkerpop自己开发的一个交互式客户端,用户可以使用该客户端对Graph做各种操作,主要有两种使用模式:
+Gremlin-Console 是由 Tinkerpop 自己开发的一个交互式客户端,用户可以使用该客户端对 Graph 做各种操作,主要有两种使用模式:
-- 单机离线调用模式;
-- Client/Server请求模式;
+- 单机离线调用模式
+- Client/Server 请求模式
### 1 单机离线调用模式
-由于lib目录下已经包含了HugeCore的jar包,且HugeGraph已经作为插件注册到Console中,用户可以直接写groovy脚本调用HugeGraph-Core的代码,然后交由Gremlin-Console内的解析引擎执行,就能在不启动Server的情况下操作图。
+由于 lib 目录下已经包含了 HugeCore 的 jar 包,且 HugeGraph 已经作为插件注册到 Console 中,用户可以直接写
groovy 脚本调用 HugeGraph-Core 的代码,然后交由 Gremlin-Console 内的解析引擎执行,就能在不启动 Server
的情况下操作图。
这种模式便于用户快速上手体验,但是不适合大量数据插入和查询的场景。下面给一个示例:
-在script目录下有一个示例脚本:example.groovy
+在 script 目录下有一个示例脚本 `example.groovy`:
```groovy
-import com.baidu.hugegraph.HugeFactory
-import com.baidu.hugegraph.dist.RegisterUtil
+import org.apache.hugegraph.HugeFactory
+import org.apache.hugegraph.backend.id.IdGenerator
+import org.apache.hugegraph.dist.RegisterUtil
+import org.apache.hugegraph.type.define.NodeRole
import org.apache.tinkerpop.gremlin.structure.T
-RegisterUtil.registerCassandra();
-RegisterUtil.registerScyllaDB();
-
-conf = "conf/hugegraph.properties"
-graph = HugeFactory.open(conf);
-schema = graph.schema();
-
-schema.propertyKey("name").asText().ifNotExist().create();
-schema.propertyKey("age").asInt().ifNotExist().create();
-schema.propertyKey("city").asText().ifNotExist().create();
-schema.propertyKey("weight").asDouble().ifNotExist().create();
-schema.propertyKey("lang").asText().ifNotExist().create();
-schema.propertyKey("date").asText().ifNotExist().create();
-schema.propertyKey("price").asInt().ifNotExist().create();
-
-schema.vertexLabel("person").properties("name", "age",
"city").primaryKeys("name").ifNotExist().create();
-schema.vertexLabel("software").properties("name", "lang",
"price").primaryKeys("name").ifNotExist().create();
-schema.indexLabel("personByName").onV("person").by("name").secondary().ifNotExist().create();
-schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create();
-schema.indexLabel("personByAgeAndCity").onV("person").by("age",
"city").secondary().ifNotExist().create();
-schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create();
-schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date",
"weight").ifNotExist().create();
-schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date",
"weight").ifNotExist().create();
-schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create();
-schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create();
-schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create();
-
-marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city",
"Beijing");
-vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city",
"Hongkong");
-lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java",
"price", 328);
-josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city",
"Beijing");
-ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang",
"java", "price", 199);
-peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city",
"Shanghai");
-
-marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5);
-marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0);
-marko.addEdge("created", lop, "date", "20171210", "weight", 0.4);
-josh.addEdge("created", lop, "date", "20091111", "weight", 0.4);
-josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0);
-peter.addEdge("created", lop, "date", "20170324", "weight", 0.2);
-
-graph.tx().commit();
-
-g = graph.traversal();
-
-System.out.println(">>>> query all vertices: size=" + g.V().toList().size());
-System.out.println(">>>> query all edges: size=" + g.E().toList().size());
+RegisterUtil.registerRocksDB()
+
+conf = "conf/graphs/hugegraph.properties"
+graph = HugeFactory.open(conf)
+graph.serverStarted(IdGenerator.of("server-tinkerpop"), NodeRole.MASTER)
+schema = graph.schema()
+
+schema.propertyKey("name").asText().ifNotExist().create()
+schema.propertyKey("age").asInt().ifNotExist().create()
+schema.propertyKey("city").asText().ifNotExist().create()
+schema.propertyKey("weight").asDouble().ifNotExist().create()
+schema.propertyKey("lang").asText().ifNotExist().create()
+schema.propertyKey("date").asText().ifNotExist().create()
+schema.propertyKey("price").asInt().ifNotExist().create()
+
+schema.vertexLabel("person").properties("name", "age",
"city").primaryKeys("name").ifNotExist().create()
+schema.vertexLabel("software").properties("name", "lang",
"price").primaryKeys("name").ifNotExist().create()
+//
schema.indexLabel("personByName").onV("person").by("name").secondary().ifNotExist().create()
Review Comment:
Removed now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]