这周才接触到图数据库或者图数据可视化领域。我想使用 JanusGraph 进行图形分析和可视化。我希望在c#中导入并处理图数据,然后在c#WebUI中点击一个按钮,分析后的图数据会自动传输到Gephi中,成为一张漂亮的图。
为了达到这个目的,我先搭建一个简单的环境。我使用的是janusgraph-full-1.0.0-rc2,运行
gremlin-server.bat
,按理说我使用的数据后端应该是inmemory
,并没有使用索引后端。我首先尝试将顶点添加到 JanusGraph 实例,在 VSCode 中运行以下代码:
private static void Main()
{
Console.WriteLine("Hello, World!");
var client = new GremlinClient(new GremlinServer("localhost", 8182));
var g = Traversal().WithRemote(new DriverRemoteConnection(client));
var vertex = g.AddV("person").Property("name", "Alice").Property("age", 25).Next();
var vertices = g.V().ToList();
if (vertices.Count == 0)
{
Console.WriteLine("no");
}
else
{
foreach (var vertex2 in vertices)
{
Console.WriteLine(vertex2.Id);
}
}
client.Dispose();
Console.WriteLine("Bye-Bye, World!");
}
它产生这样的输出:
PS D:\\Programming\\GremlinExample> dotnet run
Hello, World!
4208
Bye-Bye, World!
看来我已经成功将 ID 为 4208 的顶点添加到 JanusGraph 实例中,我可以通过在 Gremlin 控制台中运行以下命令来检查此操作的正确性:
gremlin> :remote connect tinkerpop.server conf/remote-objects.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - \[localhost/127.0.0.1:8182\] - type ':remote console' to return to local mode
gremlin> graph = g.V().hasLabel('person')
==>v[4208]
接下来,我需要将我添加的顶点发送到 Gephi。但是我发现自己只知道如何在Gremlin控制台向Gephi发送“临时图数据”,也就是下面的代码:
gremlin> :remote connect tinkerpop.server conf/remote-objects.yaml
gremlin> :remote console
gremlin> :plugin use tinkerpop.gephi
gremlin> :remote connect tinkerpop.gephi
gremlin> graph = TinkerFactory.createModern()
gremlin> :> graph
我开始迷惑了,我如何通过Http之类的方式将我刚刚添加的4208顶点发送到c#环境中的Gephi?