从lastfm.rdfize.com 添加RDF 模型

发布于 2024-10-01 19:10:45 字数 670 浏览 6 评论 0原文

我正在用 Java 编程,尝试使用 Jena 库和 lastfm.rdfize.com 网站创建一个简单的 RDF 存储。

我遇到了以下问题: lastfm.rdfize.com 生成一个 rdf,例如在 Turtle 中,请求如下: “http://lastfm.rdfize.com/?username=&eventID=&artistName="+artistName+"&venueID=&output=turtle”

我发出请求并获取结果网页的内容。 如果我打印它们 - 对我来说它们似乎是一个不错的 RDF。

但是,我无法将它们添加到模型中。

我尝试创建一个文件,将字符串(即 HTML 内容)写入该文件(看起来也不错)并将其读取到模型中:

InputStream lastf = FileManager.get().open("lastfm.txt");
Model temp=null;
temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
temp.read(lastf,null,"Turtle");

但是,此时我收到以下错误消息:

(ErrorHandlerLib.java :49) - [行: 22, 列: 2 ] 未知字符:

I am programming in Java, trying to make a simple RDF Store using Jena library and lastfm.rdfize.com website.

I'm getting into the following problem:
the lastfm.rdfize.com produces an rdf, for example in Turtle on the request like:
"http://lastfm.rdfize.com/?username=&eventID=&artistName="+artistName+"&venueID=&output=turtle"

I make a request and take the contents of the resulting web page.
If I print them - they seem like a decent RDF to me.

However, I can't add them to the model.

I tried creating a file, writing the String(which is the HTML content) to this file(which also seems okay) and reading it to the model like that:

InputStream lastf = FileManager.get().open("lastfm.txt");
Model temp=null;
temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
temp.read(lastf,null,"Turtle");

However, at this point I get the following error message:

(ErrorHandlerLib.java:49) - [line: 22, col: 2 ] Unknown char:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神仙妹妹 2024-10-08 19:10:45

您的代码确实适合我使用像这样的简单的 RDF/Turtle ...

@base <http://example.org/ns/> .                                                                                                                     
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<s1> <p1> <o1>;
<p2> "some typed literal"^^xsd:string;
<p2> "some non-typed literal";
<p4> 10 .
<o1> <label> "some label" .

因此,您的数据文件 lastfm.txt 中似乎存在某种格式或字符集错误。
我建议使用 RDF 验证器验证您的文件,尝试使用 http://www.rdfabout.com/demo /验证器/
使用此验证器,您可以测试 RDF/XML 和 RDF/Turtle,确保您为正在使用的 RDF 序列化类型选择正确的格式。

验证数据的另一个选项可能是来自 http://librdf.orgraptor 工具
但这有点复杂,您需要在本地安装它。

如果验证器提示字符集错误,那么您可以更改用于读取数据的字符集。像这样的东西应该可以工作..

package t1;                        
import java.io.*;
import com.hp.hpl.jena.util.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import java.nio.charset.*;

class test {
 public static void main (String[] args) { 
       InputStreamReader lastf = new 
          InputStreamReader(FileManager.get().open("lastfm.txt"),
                            Charset.forName("ISO-8859-1"));

       Model temp=null;
       temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
       temp.read(lastf,null,"Turtle");
       System.out.println(temp.size());
       temp.write(System.out);
    }
}

所有这些都应该为您提供发现错误的指南(我希望),但如果您没有发现它,则发布数据以便我们可以查看它。

Your code does work for me with a trivial RDF/Turtle like ...

@base <http://example.org/ns/> .                                                                                                                     
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<s1> <p1> <o1>;
<p2> "some typed literal"^^xsd:string;
<p2> "some non-typed literal";
<p4> 10 .
<o1> <label> "some label" .

It seems therefore that you have some format or charset error in your data file lastfm.txt.
I suggest to validate your file with an RDF validator, try with http://www.rdfabout.com/demo/validator/
With this validator you can test both RDF/XML and RDF/Turtle make sure you select the correct format for the type of RDF serialization you are working with.

Another option to validate your data could be the raptor tool from http://librdf.org
but this one is a bit more sophisticated and you need to install it locally.

If the validators shouts with a charset error then you could change the charset you are using to read your data. Something like this should work ..

package t1;                        
import java.io.*;
import com.hp.hpl.jena.util.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import java.nio.charset.*;

class test {
 public static void main (String[] args) { 
       InputStreamReader lastf = new 
          InputStreamReader(FileManager.get().open("lastfm.txt"),
                            Charset.forName("ISO-8859-1"));

       Model temp=null;
       temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
       temp.read(lastf,null,"Turtle");
       System.out.println(temp.size());
       temp.write(System.out);
    }
}

All this should give you a guideline to spot the error (I hope) but If you don't spot it then post the data so that we can have a look at it.

硬不硬你别怂 2024-10-08 19:10:45

听起来像是字符集问题。该文件是 utf-8 还是其他格式?

Sounds like charset trouble. Is the file in uTF-8 or something else?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文