Skip to content

Commit

Permalink
Mainly fixed some English issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
SDIPro committed Mar 31, 2015
1 parent a3b0f17 commit 5f757a3
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions Gremlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To know more about [Gremlin](http://gremlindocs.com) and [TinkerPop](http://www.

# Get Started

Launch the **gremlin.sh** (or gremlin.bat on Windows OS) console script located in **bin** directory:
Launch the **gremlin.sh** (or gremlin.bat on Windows OS) console script located in the **bin** directory:
```java
> gremlin.bat

Expand All @@ -21,16 +21,16 @@ Launch the **gremlin.sh** (or gremlin.bat on Windows OS) console script located

# Open the graph database

Before to play with [Gremlin](http://gremlindocs.com) you need a valid **[OrientGraph](Graph-Database-Tinkerpop.md#work_with_graphdb)** instance that points to a OrientDB database. To know all the database types look at [Storage types](Concepts.md#storage).
Before playing with [Gremlin](http://gremlindocs.com) you need a valid **[OrientGraph](Graph-Database-Tinkerpop.md#work_with_graphdb)** instance that points to an OrientDB database. To know all the database types look at [Storage types](Concepts.md#storage).

When you're working with a local or memory database if the database not exists it's created automatically. Using the remote connection you need to create the database on the target server before to use it. This is due to security restrictions.
When you're working with a local or an in-memory database, if the database does not exist it's created for you automatically. Using the remote connection you need to create the database on the target server before using it. This is due to security restrictions.

Once created the **[OrientGraph](Graph-Database-Tinkerpop.md#work_with_graphdb)** instance with a proper URL is necessary to assign it to a variable. [Gremlin](http://gremlindocs.com) is written in Groovy, so it supports all the Groovy syntax and both can be mixed to create very powerful scripts!
Once created the **[OrientGraph](Graph-Database-Tinkerpop.md#work_with_graphdb)** instance with a proper URL is necessary to assign it to a variable. [Gremlin](http://gremlindocs.com) is written in Groovy, so it supports all the Groovy syntax, and both can be mixed to create very powerful scripts!

Example with a local database (see below for more information about it):
```java
gremlin> g = new OrientGraph("local:/home/gremlin/db/demo");
==>orientgraph[local:/home/gremlin/db/demo]
gremlin> g = new OrientGraph("plocal:/home/gremlin/db/demo");
==>orientgraph[plocal:/home/gremlin/db/demo]
```

Some useful links:
Expand All @@ -39,31 +39,31 @@ Some useful links:

## Working with local database

This is the most used mode. The console opens and locks the database for exclusive use. Doesn't require to start a OrientDB Server.
This is the most often used mode. The console opens and locks the database for exclusive use. This doesn't require starting an OrientDB server.
```java
gremlin> g = new OrientGraph("local:/home/gremlin/db/demo");
==>orientgraph[local:/home/gremlin/db/demo]
gremlin> g = new OrientGraph("plocal:/home/gremlin/db/demo");
==>orientgraph[plocal:/home/gremlin/db/demo]
```

## Working with remote database
## Working with a remote database

Open a database on a remote server. Assure the server is up and running. To start the server just launch **server.sh** (or server.bat on Windows OS) script. For more information look at [OrientDB Server](DB-Server.md)
To open a database on a remote server be sure the server is up and running first. To start the server just launch **server.sh** (or server.bat on Windows OS) script. For more information look at [OrientDB Server](DB-Server.md)
```java
gremlin> g = new OrientGraph("remote:localhost/demo");
==>orientgraph[remote:localhost/demo]
```

## Working with in-memory database

In this mode the database is volatile and all the changes will be not persistent. Use this in cluster configuration (the database life is assured by the cluster itself) or just for test.
In this mode the database is volatile and all the changes will be not persistent. Use this in a clustered configuration (the database life is assured by the cluster itself) or just for test.
```java
gremlin> g = new OrientGraph("memory:demo");
==>orientgraph[memory:demo]
```

## Use the security
## Use security

OrientDB supports the security by creating multiple users and roles to associate privileges. To know more look at [Security](Security.md). To open the graph database with a different user than default pass user and password as additional parameters:
OrientDB supports security by creating multiple users and roles associated with certain privileges. To know more look at [Security](Security.md). To open the graph database with a different user than the default, pass the user and password as additional parameters:

```java
gremlin> g = new OrientGraph("memory:demo", "reader", "reader");
Expand All @@ -72,17 +72,17 @@ gremlin> g = new OrientGraph("memory:demo", "reader", "reader");

# Create a new Vertex

To create a new vertex use the **addVertex()** method. The vertex will be created and the unique id will be displayed as return value.
To create a new vertex, use the **addVertex()** method. The vertex will be created and a unique id will be displayed as the return value.
```java
g.addVertex();
==>v[#5:0]
```

# Create an edge =

To create a new edge between two vertices use the **addEdge(v1, v2, label)** method. The edge will be created with the label specified.
To create a new edge between two vertices, use the **addEdge(v1, v2, label)** method. The edge will be created with the label specified.

In the example below 2 vertices are created and assigned to a variable (Gremlin is based on Groovy), then an edge is created between them.
In the example below two vertices are created and assigned to a variable (Gremlin is based on Groovy), then an edge is created between them.
```java
gremlin> v1 = g.addVertex();
==>v[#5:0]
Expand All @@ -95,14 +95,14 @@ gremlin> e = g.addEdge(v1, v2, 'friend');
```

# Save changes
OrientDB assigns a temporary identifier to each vertex and edge that is created. For saving them to the database stopTransaction(SUCCESS) should be called
OrientDB assigns a temporary identifier to each vertex and edge that is created. To save them to the database stopTransaction(SUCCESS) should be called
```groovy
gremlin> g.stopTransaction(SUCCESS)
```

# Retrieve a vertex

To retrieve a vertex by its ID, use the **v(id)** method passing the [RecordId](Concepts.md#recordid) as argument (with or without the prefix '#'). This example retrieves the first vertex created in the upon example.
To retrieve a vertex by its ID, use the **v(id)** method passing the [RecordId](Concepts.md#recordid) as an argument (with or without the prefix '#'). This example retrieves the first vertex created in the above example.
```java
gremlin> g.v('5:0')
==>v[#5:0]
Expand All @@ -119,7 +119,7 @@ gremlin> g.V

# Retrieve an edge

Retrieving an edge it's very similar to [use the *e(id)* method passing the [Concepts#RecordId RecordId](Retrieve_a_vertex],.md) as argument (with or without the prefix '#'). This example retrieves the first edge created in the upon example.
Retrieving an edge is very similar to retrieving a vertex. Use the *e(id)* method passing the [RecordId](Concepts.md#recordid) as an argument (with or without the prefix '#'). This example retrieves the first edge created in the previous example.
```java
gremlin> g.e('6:0')
==>e[#6:0][#5:0-friend->#5:1]
Expand All @@ -136,29 +136,29 @@ gremlin> g.E

# Traversal

The power of Gremlin is on traversal. Once you have a graph loaded in your database you can traverse it in many ways.
The power of Gremlin is in traversal. Once you have a graph loaded in your database you can traverse it in many different ways.

## Basic Traversal

To display all the outgoing edges of the first vertex just created postpone the **.outE** at the vertex. Example:
To display all the outgoing edges of the first vertex just created append the **.outE** at the vertex. Example:
```java
gremlin> v1.outE
==>e[#6:0][#5:0-friend->#5:1]
```

And to display all the incoming edges of the second vertex created in the previous examples postpone the **.inE** at the vertex. Example:
To display all the incoming edges of the second vertex created in the previous examples append the **.inE** at the vertex. Example:
```java
gremlin> v2.inE
==>e[#6:0][#5:0-friend->#5:1]
```

In this case the edge is the same because it's the outgoing of 5:0 and the goes up to 5:1 where is the incoming edge.
In this case the edge is the same because it's the outgoing edge of 5:0 and the incoming edge of 5:1.

For more information look at the [Basic Traversal with Gremlin](https://github.com/tinkerpop/gremlin/wiki/Basic-Graph-Traversals).

## Filter results

This examples returns all the outgoing edges of all the vertices with label equals to 'friend'.
This example returns all the outgoing edges of all the vertices with label equal to 'friend'.
```java
gremlin> g.V.outE('friend')
==>e[#6:0][#5:0-friend->#5:1]
Expand All @@ -175,12 +175,12 @@ This is not strictly necessary because OrientDB always closes the database when

# Create complex paths

[Gremlin](http://gremlindocs.com) allows to concatenate expressions to create more complex traversal in a single line:
[Gremlin](http://gremlindocs.com) allows you to concatenate expressions to create more complex traversals in a single line:
```java
v1.outE.inV
```

Of course this could be much more complex. Below an examples with the graph taken from the official documentation:
Of course this could be much more complex. Below is an example with the graph taken from the official documentation:
```java
g = new OrientGraph('memory:test')

Expand Down Expand Up @@ -227,10 +227,7 @@ For more information: [Using Gremlin through Java](https://github.com/tinkerpop/

# Declaring output

In the simplest case, the output of the last step (https://github.com/tinkerpop/gremlin/wiki/Gremlin-Steps) in the Gremlin pipeline
corresponds to the output of the overall Gremlin expression. However,
it is possible to instruct the Gremlin engine to consider any of the
input variables as output. This can be declared as:
In the simplest case, the output of the last step (https://github.com/tinkerpop/gremlin/wiki/Gremlin-Steps) in the Gremlin pipeline corresponds to the output of the overall Gremlin expression. However, it is possible to instruct the Gremlin engine to consider any of the input variables as output. This can be declared as:

```java
Map<String, Object> params = new HashMap<String, Object>();
Expand All @@ -241,10 +238,8 @@ db.command(new OCommandSQL("select gremlin('
current.as('id').outE.label.groupCount(map1).optional('id').sideEffect{map2=it.map();map2+=map1;}
')")).execute(params);
```
There are more possibilities to define the output in [Gremlin](http://gremlindocs.com) pipelines
so this mechanism is expected to be extended in the future. Please,
contact OrientDB mailing list to discuss customized outputs.
There are more possibilities to define the output in the [Gremlin](http://gremlindocs.com) pipelines. So this mechanism is expected to be extended in the future. Please, contact OrientDB mailing list to discuss customized outputs.

# Conclusions

Now you learned how to use [Gremlin](http://gremlindocs.com) on top of OrientDB the best place to go in deep with this powerful language is the [Gremlin WiKi](https://github.com/tinkerpop/gremlin/wiki).
Now you've learned how to use [Gremlin](http://gremlindocs.com) on top of OrientDB. The best place to go in depth with this powerful language is the [Gremlin WiKi](https://github.com/tinkerpop/gremlin/wiki).

0 comments on commit 5f757a3

Please sign in to comment.