如何使用 SPARQL 获取数据类型属性值

发布于 2024-09-04 21:03:48 字数 579 浏览 7 评论 0原文

我在 protege 中创建了一些样本本体。根据我的本体,有一个名为 person 的类,它的子类名为 Student。有一些学生个体(约翰,保罗,玛丽,...)。 我定义了一些名为“电子邮件”的数据属性并分配了他们的电子邮件地址。

以下查询导致本体中的所有个人。但我想获取每个人及其电子邮件地址。

String queryStr =
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  "+
    "select   ?ind "+
    "where { "+
    "?ind  rdf:type <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#Student> ;"+

"}\n ";

上面的查询在 eclipse IDE 中的 jena 上进行了测试。

任何想法..?

预先感谢!

I have created some sample ontology in protege.According to my ontology there is a class called person and which has sub class called Student.There are some student individuals(john,paul,marry,...).
I have defined some data property called "email" and assigned their email addresses.

Following query which is resulting all the individuals in ontology.But I want to get each individual and their email address.

String queryStr =
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  "+
    "select   ?ind "+
    "where { "+
    "?ind  rdf:type <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#Student> ;"+

"}\n ";

Above query was tested on jena in eclipse IDE.

any idea..?

Thank in advance!

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

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

发布评论

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

评论(2

一笑百媚生 2024-09-11 21:03:48

要获取电子邮件地址,您需要 1) 将它们的变量添加到 SELECT 行,2) 在 WHERE 模式中绑定该变量。您可能想为自己的本体添加前缀,因为您现在需要引用它两次。像这样的东西:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX my: <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#>

SELECT ?ind ?email
WHERE {
  ?ind rdf:type my:Student .
  ?ind my:Email ?email
}

To get the email addresses you need to 1) add a variable for them to the SELECT line, and 2) bind that variable in the WHERE pattern. And you'll probably want to add a prefix for your own ontology, since you'll now need to refer to it twice. Something like:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX my: <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#>

SELECT ?ind ?email
WHERE {
  ?ind rdf:type my:Student .
  ?ind my:Email ?email
}
神经暖 2024-09-11 21:03:48

更紧凑的方式如下:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX my: <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#>

SELECT ?ind ?email 
WHERE { 
       ?ind rdf:type my:Student ;
            my:Email ?email .
     }

A more compact way would be the following:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX my: <http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#>

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