Java n-triple RDF解析 [英] Java n-triple RDF parsing

查看:623
本文介绍了Java n-triple RDF解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析一个n-triple形式的RDF文件。

I want to parse an RDF file which is in n-triple form.

我可以编写自己的解析器但是我宁愿使用库,而Jena似乎对于这个目的来说是非常复杂的(或者至少我看不到他们的文档解释如何以合理的方式阅读n-triples)。

I can write my own parser but I would rather use a library, and Jena seems unecessarily complicated for this purpose (or at least I can't see their docs explaining how to read n-triples in a sensible way).

你能不能指出我对于任何有用的图书馆,或者你知道芝麻或耶拿,你可能知道如何解决这个问题。

Could you please either point me to any useful libraries or if you know either Sesame or Jena well, you might know something about how they can solve this.

推荐答案

如果你只想解析NTriples而不需要做除基本处理和查询之外的任何事情,那么你可以尝试 NxParser 。这是一个非常简单的Java代码,它将传递任何NTriples格式(如NQuads等),它为您提供了文件中语句的迭代器。如果您只想要NTriples,则可以轻松忽略少于/超过3项的语句。

If you just want to parse the NTriples and don't need to do anything other than basic processing and querying then you could try the NxParser. It is a very simple bit of Java code that'll pass any NTriples like format (so NQuads etc) which gives you an iterator over the statements in the file. If you only want NTriples you can easily ignore statements with less/more than 3 items.

在链接页面上调整示例将提供以下简单代码:

Adapting the example on the linked page would give the following simple code:

NxParser nxp = new NxParser(new FileInputStream("filetoparse.nq"),false);

while (nxp.hasNext()) 
{
  Node[] ns = nxp.next();
  if (ns.length == 3)
  {
    //Only Process Triples  
    //Replace the print statements with whatever you want
    for (Node n: ns) 
    {
      System.out.print(n.toN3());
      System.out.print(" ");
    }
    System.out.println(".");
  }
}

这篇关于Java n-triple RDF解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆