gpt4 book ai didi

parsing - 如何将 Apache Any23 RDF 语句添加到 Apache Jena?

转载 作者:行者123 更新时间:2023-12-04 05:08:53 29 4
gpt4 key购买 nike

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

这是我正在使用的代码:

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(绕过 Jena)中提取 RDF 语句的主题?
由于我在编程方面缺乏经验,因此非常感谢任何帮助!

最佳答案

你在打电话

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

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

在 try-catch 块之后移动它。

关于parsing - 如何将 Apache Any23 RDF 语句添加到 Apache Jena?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15140531/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com