在JUNG图中表示RDF数据

时间:2011-04-20 16:58:21

标签: graph rdf ontology jung

我正在将RDF数据加载到JUNG图中以进行一些分析。 所以我创建了一个新的图表:

DirectedGraph g = new DirectedSparseGraph<String,GraphLink>();

我创建了一个支持类来指定链接:

public class GraphLink {
  String uri;
  Float weight;
}

然后我填充它:

for each rdf triple <s,p,o>{
  g.addVertex( s )
  g.addVertex( o )

  GraphLink link = new GraphLink()
  link.uri = pred
  link.weight = some weight;
  g.addEdge( link, s, o )
}

这是一种有效的方式还是有更好的方法? 边缘的表示非常违反直觉,但如果我这样做:

g.addEdge( p, s, o )

我得到了重复边缘的例外。

任何提示?

更新:此代码似乎运行良好:

DirectedGraph<RDFNode,Statement> g = new DirectedSparseGraph<RDFNode,Statement>()
// list all statements
// TODO: pagination for very large graphs.
assert m.size() < 10000000,"graph is too large."
m.listStatements().each{ stm->
    RDFNode sub = stm.getSubject()
    RDFNode obj = stm.getObject()
    g.addVertex( sub )
    if ( includeLiterals || !obj.isLiteral() ){
        g.addVertex( obj )
        g.addEdge( stm, sub, obj, EdgeType.DIRECTED )
    }
}

Mulone

1 个答案:

答案 0 :(得分:4)

这可能不是你想要的,但你可以尝试JenaJung,它将jena模型呈现为Jung图。

来自README文件:

Model model = FileManager.get().loadModel("http://example.com/data.rdf");
Graph<RDFNode, Statement> g = new JenaJungGraph(model);

Layout<RDFNode, Statement> layout = new FRLayout(g);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<RDFNode, Statement> viz =
    new BasicVisualizationServer<RDFNode, Statement>(layout);