Introduction to PuppyGraph's Command Line Interface
PuppyGraph includes a CLI featuring prompts and auto-completion, catering to those who prefer using the command line.
In this introduction, the examples presume the existence of a Docker container called puppy, already equipped with example graph data from Explore the Example Graph.
Start a PuppyGraph CLI
In terminal, run the command to get into PuppyGraph CLI.
You can access the PuppyGraph Gremlin Console through the console command.
[PuppyGraph]> console
____ ____ _
| _ \ _ _ _ __ _ __ _ _ / ___| _ __ __ _ _ __ | |__
| |_) | | | | | | '_ \ | '_ \ | | | | | | _ | '__| / _` | | '_ \ | '_ \
| __/ | |_| | | |_) | | |_) | | |_| | | |_| | | | | (_| | | |_) | | | | |
|_| \__,_| | .__/ | .__/ \__, | \____| |_| \__,_| | .__/ |_| |_|
|_| |_| |___/ |_|
Welcome to PuppyGraph!
version: 0.10
To Learn more about the graph schema:
- Use graph.show() to list all the vertex and edge labels.
- Use graph.show('$FOO') to list all the vertex and edge labels related to $FOO.
- Use graph.describe('$BAR') to list all the attributes of the label $BAR.
See https://tinkerpop.apache.org/gremlin.html to learn more about the Gremlin query language.
Here are some example queries for exploring the graph:
- Use g.V() to list all the vertices.
- Use g.E() to list all the edges.
- Use g.V().count() to get the total number of vertices.
- Use g.E().count() to get the total number of edges.
- Use g.V('$ID').out() to find out vertices that are reachable in 1-hop from the vertex $ID. For example, g.V('person:::v1').out() will find out 1-hop reachable vertices from 'person:::v1'.
- Use g.V('$ID').out().out() similarly to find out 2-hop reachable vertices from the vertex $ID.
puppy-gremlin>
Feel free to write queries as desired. To navigate back to the top level CLI, use :x or :exit.
g Default graph traversal source
:help (:h) Display help message
:exit (:x) Exit PuppyGraph console (Ctrl-D)
:quit (:q) Alias to: :exit
:edit (:e) Edit the current buffer
:save (:s) Save the current buffer to a file
Cypher Console
You can access the Cypher Console through the cypher-console command.
[PuppyGraph]> cypher-console
puppy-cypher>
Make sure to initiate Cypher queries using the prefix :>.
puppy-cypher> :> MATCH (v) RETURN count(*)
==>[count(*):6]
puppy-cypher> :> MATCH (v) RETURN v
==>[v:[_type:node,name:peter,_id:person:::v6,_label:person,age:35]]
==>[v:[_type:node,name:marko,_id:person:::v1,_label:person,age:29]]
==>[v:[_type:node,name:josh,_id:person:::v4,_label:person,age:32]]
==>[v:[_type:node,name:vadas,_id:person:::v2,_label:person,age:27]]
==>[v:[_type:node,name:ripple,_id:software:::v5,lang:java,_label:software]]
==>[v:[_type:node,name:lop,_id:software:::v3,lang:java,_label:software]]
Groovy Console
Gremlin integrates effortlessly with Groovy within the Groovy Console, allowing for the direct execution of Groovy scripts. This integration offers enhanced flexibility.
You can access the PuppyGraph Groovy Console through the groovy command.
[PuppyGraph]> groovy
puppy-gremlin>
As a demonstration, we'll execute the example script provided below in the console.
marko_knows = g.V().has('name', 'marko').out('knows').toList()outputs = []for (int i =0; i < marko_knows.size(); i++){ outputs << g.V(marko_knows[i]).values('name').next()}'marko knows:'+ outputs