如何形成dbPedia iSPARQL查询(用于Wikipedia内容) [英] How to form dbPedia iSPARQL query (for wikipedia content)

查看:196
本文介绍了如何形成dbPedia iSPARQL查询(用于Wikipedia内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我需要从维基百科获取有关所有山脉的内容。我的目标是显示初始段落以及相应文章的图片(例如蒙特罗莎和< a href = http://en.wikipedia.org/wiki/Vincent_Pyramid rel = nofollow>文森特金字塔。

Say I need to fetch content from wikipedia about all mountains. My target is to show initial paragraph, and an image from respective article (eg. Monte Rosa and Vincent Pyramid.

我认识

我有2个问题:

1-我发现如何制定查询条件很困难。我无法解决 iSPARQL 。我尝试了以下查询,但引发错误,提示说xml无效。

1 - I am finding it difficult how could I formulate my queries. I can't play around iSPARQL. I tried following query but it throws error saying invalid xml.

SELECT DISTINCT ?Mountain FROM <http://dbpedia.org> WHERE {
  [] rdf:type ?Mountain 
}

2-我的要求是只显示至少有1张图片的山脉(我也需要展示此图片)现在我上面列出的山脉都有图片,但是我怎么可能当然?另外,通过查看这两个示例,我发现Wiki文章中的许多字段有所不同-因此,为了将来扩展,可能很难提取它们。

2 - My requirement is to show only mountains that have at least 1 image (I need to show this image too). Now the ones I listed above have images, but how could I be sure? Also, looking at both examples I see many fields differ in wiki articles - so for future extension it maybe quite difficult to fetch them.

我只想拒绝那些没有足够数据或描述的内容。

I just want to reject those which do not have sufficient data or description.

如何过滤掉

更新:

我的更正查询,其中解决了我的第一个问题:

My corrected query, which solves my first problem:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?name ?description
WHERE {
?name rdf:type <http://dbpedia.org/ontology/Mountain>;
dbpedia-owl:abstract ?description .
}


推荐答案

您还可以使用以下命令查询dbpedia其 SPARQL端点(比iSPARQL花哨的少)。要了解有关编写哪些查询的更多信息,请查看 DBpedia的数据集页面。那里的示例显示了如何根据Wikipedia类别选择页面。要在 Wikipedia山脉类别中选择资源,可以使用以下查询:

You can also query dbpedia using its SPARQL endpoint (less fancy than iSPARQL). To find out more about what queries to write, take a look at the DBpedia's datasets page. The examples there show how one can select pages based on Wikipedia categories. To select resources in the Wikipedia Mountains category, you can use the following query:

select ?mountain where {
  ?mountain a dbpedia-owl:Mountain .
}

SPARQL结果

一旦您拥有其中的某些链接,您可以在网络浏览器中查看它们并查看与它们相关的数据。例如,珠穆朗玛峰的页面显示了很多属性。为了将结果限制在那些有图像的页面上,您可能对 dbpedia-owl:thumbnail 属性感兴趣,或者对 foaf:depiction可能更感兴趣。对于介绍性段落,您可能想要类似 dbpedia-owl:abstract 的内容。使用这些,我们可以增强以前的查询。以下查询在类别Stratovolcanoes中查找具有摘要和描述的内容。由于StackOverflow是英语网站,因此我仅将摘要限于英语。

Once you have some of these links in hand, you can look at them in a web browser and see the data associated with them. For instance the page for Mount Everest shows lots of properties. For restricting results to those pages that have an image, you might be interested in the dbpedia-owl:thumbnail property, or perhaps better yet foaf:depiction. For the introductory paragraph, you probably want something like the dbpedia-owl:abstract. Using those, we can enhance the query from before. The following query finds things in the category Stratovolcanoes with an abstract and an depiction. Since StackOverflow is an English language site, I've restricted the abstracts to those in English.

select * where {
  ?mountain a dbpedia-owl:Mountain ;
            dbpedia-owl:abstract ?abstract ;
            foaf:depiction ?depiction .
  FILTER(langMatches(lang(?abstract),"EN"))
}
LIMIT 10

SPARQL结果

这篇关于如何形成dbPedia iSPARQL查询(用于Wikipedia内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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