How do I query DBPedia to obtain all owl:sameAs links? - sparql

I have a direct link to a DBPedia page (e.g. Argentina) and I'd like to retrieve some or all links with the owl:sameAs label (e.g. wikidata, freebase, etc.)
All the tutorials that I've read focus on retrieving group of object with particular features (e.g., French films).
I've also read this but it just returns one result instead of the entire list of owl:sameAs.
How do I do this?

The following query returns what you're looking for:
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT ?obj WHERE {
dbpedia:Argentina (owl:sameAs|^owl:sameAs) ?obj
}
Note that the URI of the resource is actually http://dbpedia.org/resource/Argentina, not page/Argentina. When you put the first URI into a web browser, though, you get redirected to the latter. Be sure to use the former in your query (or just use the prefix dbpedia:).

Related

Get every places names in geonames with SPARQL DBPEDIA

I'm quite new to sparql.
I founded this query to get all country in the UN
select distinct ?s
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> }
So I tried to adapt it to Geonames with:
select distinct ?s
where { ?s a <http://dbpedia.org/page/GeoNames> }
But it doesn't work. How can I get every place's name in geonames?
I hope someone can help me with that!
Every publisher uses its own namespace and method to generate URIs of the published entities. The nice thing about Linked Open Data is that it allows such independence while URIs can still be linked using agreed open standards. When different URI represent the same thing, this is declared by linking them with owl:sameAs.
Your query attempt assumes that DPpedia and Geonames use the same URIs, if I understood correctly the intention (I'm not sure qhat you mean by "to adapt"). What you need to do is use two separate variables, and then specify that from the owl:sameAs mappings, you want only those from Geonames.
select distinct *
where { ?cuntryDBpedia a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ;
owl:sameAs ?countryGeonames .
FILTER REGEX (?countryGeonames,"geonames.org")
}

dbpedia sparql movie query sql

Hi I'm trying to learn how to query DBpedia using SPARQL. I can't find any website/source that shows me how do this and I'm finding it difficult to learn how to use all the properties (like the ones available at http://mappings.dbpedia.org/index.php?title=Special%3AAllPages&from=&to=&namespace=202 ). Any good source I can learn from?
So for example if I want to check if the wikipedia page http://en.wikipedia.org/wiki/Inception is a movie (property film) or not, how do I do that?
The wikipedia URL http://en.wikipedia.org/wiki/Inception maps to the dbpedia URI http://dbpedia.org/resource/Inception. Dbpedia has a SPARQL endpoint at: http://dbpedia.org/sparql, which you may use to run queries either programmatically or via the html interface.
To check if http://dbpedia.org/page/Inception is a "movie", you have many options. To give you an idea:
If you know the URI of "movie" in dbpedia (it is http://schema.org/Movie), then run an ASK query to check against that type. ASK will return true/false based on whether the pattern in the where clause is valid against the data:
ASK where {
<http://dbpedia.org/resource/Inception> a <http://schema.org/Movie>
}
If you don't know the URI of "movie" then you have a number of options. For example:
Execute an ASK query with a filter on whether the resource has a type that contains the word "movie" somewhere in its uri (or its associated rdfs:label, or both). You would use a regular expression for this:
ASK where {
<http://dbpedia.org/resource/Inception> a ?type .
FILTER regex(str(?type), "^.*movie", "i")
}
Same idea, but return all matches and post-process the results (programmatically I pressume) to see if they match your request:
select distinct ?type where {
<http://dbpedia.org/resource/Inception> a ?type .
FILTER regex(str(?type), "^.*movie", "i")
}
Return all the types of the resource without applying a filter and post-process to see if they match your request:
select distinct ?type where {
<http://dbpedia.org/resource/Inception> a ?type
}
Many options. The SPARQL spec is you number one resource.
First I suggest you start reading up on what exactly SPARQL is. There are tons of really good tutorials such as: this.
If you want to write SPARQL queries on dbpedia, there are various endpoints that you can use. They don't always accept all features that are supported by SPARQL, but if you don't want to go through the trouble of installing one locally, they can be a relatively reliable test environment. The queries that I am going to write below, have been tested on Virtuoso endpoint.
Let's say you want to find all the movies in dbpedia. You first need to know what is the URI for a movie type in dbpedia. If you open Inception in dbpedia, you can see that the type dbpedia-owl:Film is associated to it. So if you want to get the first 100 movies, you just need to call:
select distinct *
where {
?s ?o dbpedia-owl:Film
} LIMIT 100
If you want o know more about each of these movies, you just need to expand your queries by expanding the triples.
select distinct *
where {
?s ?p dbpedia-owl:Film.
?s ?x ?y.
} LIMIT 100

SPARQL query: How to use wikiPageDisambiguates for redirect

I'm trying to retrieve thumbnail links for a given entity name. My current query looks like the following and works for most of the cases.
select ?value {
<http://dbpedia.org/resource/Angela_Merkel> dbpedia-owl:thumbnail ?value
}
However, for some cases e.g "CDU" it fails, because the entity is ambiguous. See this Example in the SPARQL Explorer.
In these cases I would like to return the thumbnail of the first wikiPageDisambiguates entry. So, for "CDU" it would be the thumbnail of this page. Can somebody tell me how to do this in SPARQL?
In these cases I would like to return the thumbnail of the first wikiPageDisambiguates entry. So, for "CDU" it would be the thumbnail of this page. Can somebody tell me how to do this in SPARQL?
There's no order on these. Any representation necessarily has to put them in some order, but they're not actually ordered in the underlying RDF. You can retrieve an arbitrary one, but not "the first". For instance, look at the results from select * where { dbpedia:CDU ?p ?o }. There are a bunch of disambiguation links. Now, you can follow those links, if they are there, to get thumbnails:
select ?thumbnail where {
dbpedia:CDU dbpedia-owl:wikiPageDisambiguates?/dbpedia-owl:thumbnail ?thumbnail
}
SPARQL results
The property path dbpedia-owl:wikiPageDisambiguates?/dbpedia-owl:thumbnail uses a question mark after the wiki page disambiguation property. That means that there can be either zero or one occurrences of the the property. Then it has to be followed by a dbpedia-owl:thumbnail link. That means that if dbpedia:CDU has a thumbnail property, you'll get it, or if it has a a disambiguation that has a thumbnail, you'll get that.
If you do want to impose some ordering, you can do that, but you'll have to determine what it should be. You can use order by to specify the ordering, and limit to specify that you want just the first one. E.g., you could do:
select ?thumbnail where {
dbpedia:CDU dbpedia-owl:wikiPageDisambiguates? ?cdu .
?cdu dbpedia-owl:thumbnail ?thumbnail ;
rdfs:label ?label
}
order by ?label
limit 1
SPARQL results

How I can retrieve a DBPedia page that start with "http://fr.dbpedia.org"

I have a DBPedia resource as
http://dbpedia.org/page/London
.
I would like to get French page of http://dbpedia.org/page/London using SPARQL. I have noticed that I can retrieve this information through owl:sameAs.
I am trying to write this query on http://dbpedia.org/sparql endpoint to retrieve http://fr.dbpedia.org/page/Londres page:
prefix owl: <http://www.w3.org/2002/07/owl#>
select ?resource where {
?resource owl:sameAs "http://dbpedia.org/page/London"
FILTER strStarts (?resource, "http://fr.dbpedia.org")
In particular, I thought to use "strStarts" property, because I have read this document: http://www.w3.org/TR/sparql11-query/#func-strstarts.
This document says that "The STRSTARTS function corresponds to the XPath fn:starts-with function" and I thought to use this function to retrieve the triples that start with "http://fr.dbpedia.org".
But, from my query I don't get any result. Why?
What am I doing wrong here?
There are a few problems in your query. First, URIs are not strings, so you'd need to use <http://dbpedia.org/page/London> rather than "http://dbpedia.org/page/London". Second, that's the wrong URI for London. The resource is <http://dbpedia.org/resource/London>. (Yes, when you put that in a web browser, you get redirected to the …/page/London; that's not the URI of the resource, though.) The URI can be abbreviated as dbpedia:London on the public endpoint. Third, because URIs are not strings, you need to filter strstarts( str(?resource), … ), explicitly getting the string form of the URI. Thus:
select ?resource where {
?resource owl:sameAs dbpedia:London
filter strstarts(str(?resource), "http://fr.dbpedia.org")
}
SPARQL results

How to form dbPedia iSPARQL query (for wikipedia content)

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.
I came to know about dbpedia, and with some research got to find that it provides live queries into wiki database directly.
I have 2 questions:
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 - 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.
How can I filter out mountains based on pictures present?
UPDATE:
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 .
}
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 Results
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 Results