3

我正在从事一个涉及在 Java 中使用知识表示的项目,我的印象是某种语义网络是实现它的方法。

Gremlin/Tinkerpop 似乎有很好的图形生成和遍历语法,但我只能让它在独立的 shell 中工作。它是一种 JVM 语言,所以大概它有某种 Java API?我尝试将源文件夹添加到 Eclipse 项目中,但它只是充满了错误并拒绝工作。

有没有更好的方法来做到这一点?也许是一个编译库,类似于我用来处理用户输入的斯坦福 CoreNLP 库?

4

2 回答 2

3

Tinkerpop 3 提供了一个 API(就像 JDBC 为 RDBMS 所做的那样)和(特定于供应商的)实现。内存中的参考实现也是可用的。所以首先你需要决定你需要的实现。出于学习目的,我建议首先使用参考实现(TinkerGraph)。

最简单的方法是使用 maven。为此,添加以下依赖项:

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

如果不使用 maven,您需要将以下 jar 文件添加到您的类路径(我不知道 TinkerGraph 的 uber-jar):

+- 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

现在您可以在您的 Java(或其他 JVM 基础)语言中使用该 API。

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

注意:Tinkerpop3 需要 Java 8(它提供了基于 Java 8 流和 lambda 的非常好的 API!)。

于 2015-11-02T17:33:49.140 回答
0

I know this isn't directly answering your question, but I was where you are now, and this info might come in handy.

We're currently using tinkerpop 3.0.1-incubating with titan 1.0.0 for a project at work. I highly recommend going over the tinkerpop documentation extensively.

I'm currently trying out a design pattern where i have a basic graph utilities class in groovy (gremlin groovy is very similar to the independent shell that you mentioned). The point of the utils class is to wrap all the traversal, access, and retrieval functionalities (from node/s x, go through edges y and get prop z, and so on). This is important due to the fact that tinkerpop tends to have some changes from version to version, and this serves as a single point of change. Then i use regular java with this utils class to implement my own ORM kinda thing.

here's some groovy sources i found helpful (about 4 mins each video):

https://www.youtube.com/watch?v=1Trx7cKwMOQ

https://www.youtube.com/watch?v=u7NWMOL5aUo

PS: here's some useful groovy snippet that'll save u time down the line:

note the .fill(result) as a method of obtaining the info you'd get from the shell

def result = []
g.V().values().fill(result)
return result.first()
于 2016-03-28T11:56:25.297 回答