I'm trying to extract entity dictionary contains person name etc. from dbpedia using sparql.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:name ?name . FILTER(lang(?name) = "en")
}
The query above did succeed, but when I change the language name to fr, there is nothing to fetch.
How can I fetch names in other languages?
Moreover, why can't I filter language using query below?
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:language "English"
?person dbpprop:name ?name .
}
// this query returns nothing
I tried to fetch all languages using
SELECT DISTINCT ?lanName
WHERE {
?person a owl:Person .
?person dbpprop:language ?lanName .
}
and the result set contains English.
You need to filter based on the language of the value of the property. Not every property will have values in different languages, but some properties will. It seems, from your example, that dbpprop:name doesn't have values in every language. You may find more values in other languages if you look on the other language specific DBpediae.
However, for something like a name, you'll probably get multi-language results if you use the rdfs:label property. For instance, to get the names of Barack Obama, Daniel Webster, and Johnny Cash in Russian, you could do:
select ?label {
values ?person { dbpedia:Johnny_Cash dbpedia:Barack_Obama dbpedia:Daniel_Webster }
?person rdfs:label ?label .
filter langMatches(lang(?label),"ru")
}
SPARQL results
As an aside, note the use of langMatches rather than equality for matching language tags. This is usually a better approach, because it will correctly handle the different language tags within a language For example (from the SPARQL specification), you can find both of the French literals:
"Cette Série des Années Soixante-dix"#fr .
"Cette Série des Années Septante"#fr-BE .
with langMatches(lang(?title),"fr"), but only the first one with lang(?title) = "fr".
You are looking for rdfs:label for a name, of course all the names are English, you are looking at the English dbpedia.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
FILTER(lang(?name) = "fr")
}
Again, for the second one, if you replace the name with the rdfs: label you can have:
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
?person dbpprop:language <http://dbpedia.org/resource/English_language>.
}
Related
I'm learning semantic web and using dbpedia to learn sparql. Below is an example to get all the schools in IL, USA. If you look at the filters, I'm filtering 2 fields (name and city) for the English language only.
Question - instead of 2 filter expressions or 'n' number of filter expressions per field, is it possible to set a global filter condition that can be applied to set of fields?
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?link ?name ?city ?website where {
SERVICE <https://dbpedia.org/sparql> {
?link rdf:type dbo:School .
?link rdfs:label ?name .
?link dbo:country dbr:United_States .
?link dbo:state dbr:Illinois .
?link dbo:city ?city_link .
?city_link rdfs:label ?city .
OPTIONAL {
?link dbp:website ?website .
}
}
FILTER (lang(?name)="en") .
FILTER (lang(?city)="en") .
}
new to SPARQL. Trying to figure out why I get different results on these two queries. It's based on this other question, where I'm trying to match properties to a name of a person. For example, I'm curious to know the birthday of J.K. Rowling, without knowing her URI directly. Here's the code from the link above:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "Car"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
compared to the query I'd like with J.K.:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "J.K. Rowling"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
The first one works fine, however, when I replace "Car" with "J.K. Rowling" as in the second, nothing is returned (her URI is return if I remove the dbo:abstract line and the filter line for it). J.K. Rowling does have a dbo:abstract in English. I'm not sure why it works for one and not the other. The only thing I can see that that 'Car' is a 'Thing', while J.K. is a 'person'
I have the following code to retrieve all people that was born in Barcelona
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?person ?birthPlace
WHERE {
?person rdfs:label ?label.
?person rdf:type dbo:Person.
?person <http://dbpedia.org/property/birthPlace>
<http://dbpedia.org/resource/Barcelona>.
}
However, I do not know how to get the birthPlace. I want a variable that says next to each name that Barcelona is the place of birth. Any ideas?
How about this:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?person ?birthPlace
WHERE {
?person rdfs:label ?label.
?person rdf:type dbo:Person.
?person <http://dbpedia.org/property/birthPlace> ?birthPlace.
FILTER (?birthPlace = <http://dbpedia.org/resource/Barcelona>)
}
Note that your query has a pattern to match labels, but the labels are not returned. That leads to duplicate results because some people have multiple labels (in different languages). Remove the pattern, or add ?label to the SELECT clause.
You can abbreviate <http://dbpedia.org/property/birthPlace> to dbp:birthPlace.
I tried doing some sparql requests on http://dbpedia.org/sparql.
My sparql-request is this:
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Name ?Todestag ?person
WHERE {
?person dbo:deathPlace :Hamburg .
?person foaf:name ?Name .
?person dbo:deathDate ?Todestag .
FILTER ( ?Todestag > "2016-01-01"^^xsd:date ) .
} ORDER BY ?Todestag
The problem:
Somehow this FILTER doesn’t work. The SPARQL request gives me all people who died on every day since the start of time in DBpedia. However, I just want people who died after 2016. Can anyone spot the mistake in the query or the syntax?
Here is the correct solution to the query, note the casting applied to the FILTER CLAUSE ( i.e. xsd:date(?Todestag ) :
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Name ?Todestag ?person
WHERE {
?person dbo:deathPlace :Hamburg .
?person foaf:name ?Name .
?person dbo:deathDate ?Todestag .
FILTER ( xsd:date(?Todestag) > "2016-01-01"^^xsd:date ) .
} ORDER BY ?Todestag
Live Query Solution Page (format HTML Table).
Query Definition Page
Okay, I figured it out myself. The problem is definitely the filter. I have now changed the filter and the desired result appears. The filter must be: FILTER (str(?Todestag) >= "2016") .
Completely, it would look like this:
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Name ?Todestag ?person
WHERE {
?person dbo:deathPlace :Hamburg .
?person foaf:name ?Name .
?person dbo:deathDate ?Todestag .
FILTER (str(?Todestag) >= "2016") .
} ORDER BY ?Todestag
I am working from this example, and I want to archieve the same, however with a different topic - Climate change
All i need to output is the abstract from this page: http://dbpedia.org/page/Climate_change
PREFIX dbp-res: <http://dbpedia.org/resource/>
PREFIX dbp-ont: <http://dbpedia.org/ontology/>
PREFIX dbp-prop: <http://dbpedia.org/property/>
SELECT *
WHERE
{
?Resource a dbp-ont:Agent .
?Resource dbp-ont:abstract ?Description .
?Resource rdfs:label ?Label .
FILTER( STR(?Label) = 'Climate_change' )
FILTER (langMatches(lang(?Description),'en'))
FILTER (langMatches(lang(?Label),'en'))
}
The problem seems to be the Agent, but I have no clue, as to what to replace it with.
My query