Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Gremlin/Tinkerpop with Java?

I'm working on a project which involves the use of knowledge representation in Java, and I got the impression that some kind of semantic network is the way to go about it.

Gremlin/Tinkerpop seems to have very nice syntax for graph generation and traversal, but I can only get it to work in an independent shell. It's a JVM language, so presumably it has some kind of Java API? I tried adding the source folder to an Eclipse project and it just comes up filled with errors and refuses to work.

Is there some better way of doing this? A compiled library perhaps, akin to the Stanford CoreNLP library that I'm using to process the user input?

like image 485
user5513268 Avatar asked Sep 20 '25 19:09

user5513268


1 Answers

Tinkerpop 3 offers an API (like JDBC does for RDBMS) and (vendor specific) implementations. An in-memory reference implementation is also available. So first you need to decide upon the implementation you need. For learning purposes I recommend using the reference implementation (TinkerGraph) first.

Easiest way to start is to use maven. For this, add the following dependency:

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>tinkergraph-gremlin</artifactId>
    <version>${tinkergraph.version}</version>
</dependency>

If not using maven, you need to add the following jar-files to your class path (I am not aware of an uber-jar for TinkerGraph):

+- org.apache.tinkerpop:tinkergraph-gremlin:jar:3.0.1-incubating:compile
|  \- org.apache.tinkerpop:gremlin-core:jar:3.0.1-incubating:compile
|     +- org.apache.tinkerpop:gremlin-shaded:jar:3.0.1-incubating:compile
|     +- commons-configuration:commons-configuration:jar:1.10:compile
|     |  \- commons-lang:commons-lang:jar:2.6:compile
|     +- org.yaml:snakeyaml:jar:1.15:compile
|     +- org.javatuples:javatuples:jar:1.2:compile
|     +- com.carrotsearch:hppc:jar:0.7.1:compile
|     +- com.fasterxml.jackson.core:jackson-databind:jar:2.5.3:compile
|     |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0:compile
|     |  \- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile
|     +- com.jcabi:jcabi-manifests:jar:1.1:compile
|     |  \- com.jcabi:jcabi-log:jar:0.14:compile
|     +- org.slf4j:slf4j-log4j12:jar:1.7.12:compile
|     |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
|     |  \- log4j:log4j:jar:1.2.17:compile
|     \- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile

Now you can use the API from within your Java (or other JVM base) language.

Graph g = TinkerGraph.open(); // open in-memory Graph

Note: Tinkerpop3 needs Java 8 (it offers a very nice API based on Java 8 streams and lambdas!).

like image 59
rmuller Avatar answered Sep 22 '25 10:09

rmuller