So my question is simple: from this URI --
http://dbpedia.org/snorql/?describe=http%3A%2F%2Fdbpedia.org%2Fresource%2FRed_Dragon_%28spacecraft%29
-- I want to extract specific things like --
rdfs:comment
rdfs:label
how to do that ?
Currently your query gets all properties, including rdfs:label and rdfs:comment. To get just those properties, substitute them for ?property, e.g.:
{ <http://dbpedia.org/resource/Red_Dragon_(spacecraft)> rdfs:label ?label .
<http://dbpedia.org/resource/Red_Dragon_(spacecraft)> rdfs:comment ?comment .
}
Also, you may want to filter for language tags, e.g., FILTER (lang(?label) = "en).
Related
I'm trying to get the Deathplace for a unique language. My query is this but I have errors...
SELECT ?place ?placeLabel
WHERE {
<https://dbpedia.org/page/Alfonso_XII> rdfs:label ?person
?place dbo:deathPlace ?person;
rdfs:label ?placeLabel.
FILTER (LANG(?placeLabel) = "en")
}
You have a few issues with this query.
You are using the URL of the resource, not the URI
A place of death links a person to a place, not the other way round.
The right URI prefix for deathPlace is dbp:
Places should be resources indeed but in DBpedia that's a strong assumption
Since you don't ask for the person level, it seems you don't need it in the query
SELECT ?place ?placeLabel
WHERE {
dbr:Alfonso_XII dbp:deathPlace ?place .
OPTIONAL {?place rdfs:label ?placeLabel .
FILTER (LANG(?placeLabel) = "en") }
}
How can I list properties with their values for any given DBpedia class? I'm new to this and have looked at several other questions on this but I haven't found exactly what I'm looking for.
What I'm trying to do is providing some relevant additional information to topics of conversation I have got from text mining.
Say for example the topic of conversation in a certain community is iPhones. I would like to use this word to query the DBpedia page for this word, IPhone, to get an output such as:
Type: Smartphone
Operating System: IOS
Manufacturer: Foxconn
EDIT:
Using the query from AKSW I can print the p (property?) and o (object?), although I'm still not getting the output I want. Instead of getting something like:
weight: 133.0
I get
http://dbpedia.org/property/weight:133.0
Is there a way to just get the name of the property instead of the DBpedia link?
My Code
Classes do not "have" properties with values. Instances (resp. resources or individuals) do have a relationship via a property to some value which can be an individual itself or a literal (or some anonymous instance aka blank node). And instances belong to a class. e.g. Berlin belongs to the class City
What you want is to get all outgoing values of a given resource in DBpedia:
SELECT * WHERE { <http://dbpedia.org/resource/IPhone> ?p ?o }
Alternatively, you can use SPARQL DESCRIBE, which return the data in forms of an RDF graph resp. a set of RDF triples:
DESCRIBE <http://dbpedia.org/resource/IPhone>
This might also return incoming information because it's not really specified in the W3C recommendation what has to be returned.
As stated by AKSW properties often link to other classes rather than values. If you want all properties and their values, including other classes the the below gives you the label and filters by language (put the language code you need where have put "en").
SELECT DISTINCT ?label ?o
WHERE {
<http://dbpedia.org/resource/IPhone> ?p ?o.
?p <http://www.w3.org/2000/01/rdf-schema#label> ?label .
FILTER(LANG(?label) = "" || LANGMATCHES(LANG(?label), "en"))
}
If you don't want any properties that link to other classes, then you only want datatype properties so this code could help:
SELECT DISTINCT ?label ?o
WHERE {
<http://dbpedia.org/resource/IPhone> ?p ?o.
?p <http://www.w3.org/2000/01/rdf-schema#label> ?label .
?p a owl:DatatypeProperty .
FILTER(LANG(?label) = "" || LANGMATCHES(LANG(?label), "en"))
}
Obviously this gives you far less information and functionality, but it might just be what you're after?
Edit: In reply to your comment, it is also possible to get the labels for the values, using the same technique:
SELECT DISTINCT ?label ?oLabel
WHERE {
<http://dbpedia.org/resource/IPhone> ?p ?o.
?p <http://www.w3.org/2000/01/rdf-schema#label> ?label .
?o <http://www.w3.org/2000/01/rdf-schema#label> ?oLabel
FILTER(LANG(?label) = "" || LANGMATCHES(LANG(?label), "en"))
}
Note that http://www.w3.org/2000/01/rdf-schema#label is often shortened to rdfs:label by defining prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
So you could also do:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?label ?oLabel
WHERE {
<http://dbpedia.org/resource/IPhone> ?p ?o.
?p rdfs:label ?label .
?o rdfs:label ?oLabel
FILTER(LANG(?label) = "" || LANGMATCHES(LANG(?label), "en"))
}
and get exactly the same result but possibly easier to read.
I'm trying to develop a tool in JS for tagging pictures, so I need a set of possible "things" from dbpedia. I already tryed to retrieve this way:
select ?s ?l {
?s a owl:Class .
?s rdf:type ?l
FILTER regex(str(?s), "House", "i").
}
http://dbpedia.org/snorql/?query=select+%3Fs+%3Fl+%7B%0D%0A+++%3Fs+a+owl%3AClass+.%0D%0A+++%3Fs+rdf%3Atype+%3Fl%0D%0A+++FILTER+regex%28str%28%3Fs%29%2C+%22House%22%2C+%22i%22%29.%0D%0A%7D
And also this way:
select ?label
WHERE {
?concept a skos:Concept.
?concept skos:prefLabel ?label.
FILTER regex(str(?label), "^House", "i").
}
http://dbpedia.org/snorql/?query=select+%3Flabel+%0D%0AWHERE+%7B%0D%0A++%3Fconcept+a+skos%3AConcept.%0D%0A++%3Fconcept+skos%3AprefLabel+%3Flabel.%0D%0A++FILTER+regex%28str%28%3Flabel%29%2C+%22%5EHouse%22%2C+%22i%22%29.%0D%0A%7D
In the first case, I just have "instances" of the house "thing", but not the "House" class itself. In the second one, I never retrieve the "house" and the similar thing is "houses". Any alternative for retrieving a better vocabulary based in dbpedia dataset?
If you don't bother to restrict yourself to owl:Thing or to skos:Concept, you can just get things that have a label that contains "house". Rather than using regex, I chose to use contains and lcase, since a string containment could be less expensive than invoking a full regular expression processor.
select ?thing ?label where {
?thing rdfs:label ?label .
filter contains(lcase(?label), "house")
}
SPARQL results (limited to 200)
I have the following SPARQL query:
SELECT ?nationalityLabel WHERE {
dbpedia:Henrik_Ibsen dbpedia-owl:nationality ?nationality .
?nationality rdfs:label ?nationalityLabel .
}
I have checked that Henrik Ibsen exists and that he has the nationality ontology/property on him:
http://dbpedia.org/page/Henrik_Ibsen
And this is an ontology:
http://dbpedia.org/ontology/nationality
A very similar query to this listed here works:
https://stackoverflow.com/a/10248653/1680130
The problem I have is that the query doesn't return any result.
If I could get help solving this it would be great.
Summarized solution:
Both answers were great so upvote to both but landed on Joshua's in the end because informing about dbpedia-owl being cleaner. Optimal solution in my opinion:
First check with dbpedia-owl for birth-place:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
If found then get the demonym:
select ?label {
dbpedia:Norway dbpedia-owl:demonym ?label
filter langMatches(lang(?label),"en")
}
If above fails then do the "dirty" query:
SELECT
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
filter langMatches(lang(?nationality),"en")
}
Of course is "dirty" means data being correct but not so often present the order might be better other way around because people can be born in a country but from a different.
Kristian's answer is right that the property is dbpprop:nationality that Henrik Ibsen has. You're right that there is a dbpedia-owl:nationality property, too, but Henrik Ibsen doesn't have a value for it, unfortunately. The value of dbpprop:nationality that Henrik Ibsen has, though, is a string, which is a literal, and literals cannot be the subjects of triples in RDF, so ?nationality rdfs:label ?nationalityLabel in your query will never match.
The DBpedia ontology data (dbpedia-owl) tends to be cleaner than the dbpprop data, so you might prefer a solution using dbpedia-owl properties that Henrik Ibsen does have. In this case, you might look to the dbpedia-owl:birthPlace. Then you could get the name the country of the birth places:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
}
SPARQL results
You might want to narrow the permissible languages:
select ?label {
dbpedia:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
filter langMatches(lang(?label),"en")
}
SPARQL results
Those queries will produce the name of the country, but it wanted the corresponding demonym, you can get the dbpedia-owl:demonym value of the country, if it's available. It's probably best to make the demonym optional, since a cursory investigation suggests that lots of countries in DBpedia don't have a value for it, so the name of the country may be the only option. E.g.,
select ?name ?demonym {
dbpedia:Henrik_Ibsen dbpedia-owl:birthPlace ?country .
?country a dbpedia-owl:Country ; rdfs:label ?name .
optional { ?country dbpedia-owl:demonym ?demonym }
filter langMatches(lang(?name),"en")
filter langMatches(lang(?demonym),"en")
}
SPARQL results
Two things are wrong with the query:
It's dbpprop:nationality
The label doesn't appear to exist, and unless you make that variable optional, it will eliminate the row altogether. EDIT: *Joshua Taylor's answer reminded me that the label doesn't exist because the dbprop:nationality value is a literal, which cannot be used as a subject resource, therefore, there will never be a label for dbpprop:nationality. Instead, where the data exists, you would use dbpedia-owl:nationality, which you did originally. it just so happens that Henrik_Ibsen has no dbpedia-owl:nationality value associated with him*
Updated query (updated).
SELECT
#### ?label #### See Edit
?nationality
WHERE {
dbpedia:Henrik_Ibsen dbpprop:nationality ?nationality .
#### OPTIONAL { ?nationality rdfs:label ?label . } #### See Edit.
}
Basically I have a query (shown below) which works efficiently. However, I want my search to be more precise where the label is the actual string 'yago' rather than containing the string 'yago'. I want to try to do it without filters if possible as I think using FILTER makes querying DBpedia take longer.
SELECT ?uri ?label
WHERE {
?uri rdfs:label ?label.
?label bif:contains "'yago'" .
}
You can try doing the following if you want to do it without filters:
SELECT ?uri ?label
WHERE {
?uri rdfs:label "Yago"#en .
?uri rdfs:label ?label
}
I not sure though it if it is much faster than the corresponding query with filters:
SELECT ?uri ?label
WHERE {
?uri rdfs:label ?label .
filter(?label="Yago"#en)
}
A key correction to the original response. If you have an exact match, with the language label, then the following will work:
SELECT ?uri ?label
WHERE {
?uri rdfs:label "Yago"#en .
}
If, however, the exact match may not be using what you want, SPARQL supports a standard regex:
SELECT ?uri ?label
WHERE {
?uri rdfs:label ?label .
FILTER regex(str(?label), "yago", "i")
}
...which will match the string regardless of character case, and you can play the usual regex games to get the required string match. (Of course, other string functions, such as STRSTARTS and STRENDS will be more efficient if those meet the desired matching criteria.)