【问题标题】:How to add Apache Any23 RDF Statements to Apache Jena?如何将 Apache Any23 RDF 语句添加到 Apache Jena?
【发布时间】:2013-02-14 22:31:56
【问题描述】:

基本上,我使用 Any23 蒸馏器从嵌入 RDFa 的文件中提取 RDF 语句(DBpedia Spotlight 使用 xhtml+xml 输出选项创建的实际文件)。通过使用 Any23 RDFa 蒸馏器,我可以提取 RDF 语句(我也尝试使用 Java-RDFa,但我只能提取前缀!)。但是,当我尝试将语句传递给 Jena 模型并将结果打印到控制台时,什么也没有发生!

这是我正在使用的代码:

File myFile = new File("T1");
Any23 runner= new Any23();

DocumentSource source = new FileDocumentSource(myFile); 
ByteArrayOutputStream outA = new ByteArrayOutputStream();
InputStream decodedInput=new ByteArrayInputStream(outA.toByteArray()); //convert the output stream to input so i can pass it to jena model
TripleHandler writer = new NTriplesWriter(outA);

try {
    runner.extract(source, writer);
} finally {
    writer.close();
}

String ttl = outA.toString("UTF-8");
System.out.println(ttl);
System.out.println();
System.out.println();

Model model = ModelFactory.createDefaultModel();
model.read(decodedInput, null, "N-TRIPLE");

model.write(System.out, "TURTLE"); // prints nothing!  

谁能告诉我我做错了什么?可能有很多东西!
有什么简单的方法可以直接从 any23 中提取 RDF 语句的主题(绕过耶拿)? 由于我在编程方面非常缺乏经验,因此我们将不胜感激!

【问题讨论】:

    标签: parsing rdf jena rdfa any23


    【解决方案1】:

    你在打电话

    InputStream decodedInput=new ByteArrayInputStream(outA.toByteArray()) ;
    

    在调用 any23 插入三元组之前。在调用点,它是空的。

    将其移到 try-catch 块之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多