【发布时间】:2014-02-13 12:14:18
【问题描述】:
我正在尝试使用 Titan Graph api 在 Cassandra 数据库中创建一个具有节点和边且具有某些权重的图形。那么如何检索该图以便我可以将其可视化。
rexster 或 gremlin 是它的解决方案.. ??如果是这样..请告诉我过程。
【问题讨论】:
标签: cassandra gremlin titan rexster
我正在尝试使用 Titan Graph api 在 Cassandra 数据库中创建一个具有节点和边且具有某些权重的图形。那么如何检索该图以便我可以将其可视化。
rexster 或 gremlin 是它的解决方案.. ??如果是这样..请告诉我过程。
【问题讨论】:
标签: cassandra gremlin titan rexster
我有一个 4 集群 cassandra 设置。我在它上面运行 Titan。我制作了这个程序,它创建两个节点,然后在它们之间创建一条边,最后查询并打印它。
public static void main(String args[])
{
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "cassandra");
baseConfiguration.setProperty("storage.hostname", "192.168.1.10");
TitanGraph titanGraph = TitanFactory.open(baseConfiguration);
Vertex rash = titanGraph.addVertex(null);
rash.setProperty("userId", 1);
rash.setProperty("username", "rash");
rash.setProperty("firstName", "Rahul");
rash.setProperty("lastName", "Chaudhary");
rash.setProperty("birthday", 101);
Vertex honey = titanGraph.addVertex(null);
honey.setProperty("userId", 2);
honey.setProperty("username", "honey");
honey.setProperty("firstName", "Honey");
honey.setProperty("lastName", "Anant");
honey.setProperty("birthday", 201);
Edge frnd = titanGraph.addEdge(null, rash, honey, "FRIEND");
frnd.setProperty("since", 2011);
titanGraph.commit();
Iterable<Vertex> results = rash.query().labels("FRIEND").has("since", 2011).vertices();
for(Vertex result : results)
{
System.out.println("Id: " + result.getProperty("userId"));
System.out.println("Username: " + result.getProperty("username"));
System.out.println("Name: " + result.getProperty("firstName") + " " + result.getProperty("lastName"));
}
}
我的 pom.xml,我只有这个依赖:
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-cassandra</artifactId>
<version>0.5.4</version>
</dependency>
我正在运行 Cassandra 2.1.2。
我对 gremlin 了解不多,但我相信 Gremlin 是您可以用来从命令行查询数据库的 shell。 Rexter 是一种 API,您可以在任何其他使用蓝图的 API(如 Titan)之上使用它,以使其他人可以通过 REST API 访问您的查询/代码。由于您想将嵌入式 Java 与 titan 一起使用,因此您不需要 gremlin。有了我所说的依赖关系,蓝图 API 随之而来并使用该 API(就像我在我的代码中所做的那样),你可以用你的图表做任何事情。
您可能会发现此备忘单很有用。 http://www.fromdev.com/2013/09/Gremlin-Example-Query-Snippets-Graph-DB.html
【讨论】:
首先注意TitanGraph 使用Blueprints API,因此Titan API 就是Blueprints API。当您使用蓝图时,您可以使用Gremlin、Rexster 或TinkerPop stack 的任何部分来处理您的图表。
在 Titan 中如何可视化图表取决于您选择的图表可视化工具。如果我假设您正在使用Gephi 或可以使用 GraphML 的类似工具,那么从 Titan 获取数据的最简单方法是打开 Gremlin REPL,获取对图表的引用,然后执行以下操作:
g = TitanFactory.open(...)
g.saveGraphML('/tmp/my-graph.xml')
您可以从那里将my-graph.xml 导入Gephi 并可视化它。
【讨论】: