I hope that this kind of question is allowed here as it is more a Wikidata specific question. Anyways, I try to get all non-classical-music musicians from Wikidata by SPARQL. Right now I have this code:
SELECT ?value ?valueLabel ?born WHERE {
{
SELECT DISTINCT ?value ?born WHERE {
?value wdt:P31 wd:Q5 . # all Humans
?value wdt:P106/wdt:P279* wd:Q639669 . # of occupation or subclass of occupation is musician
?value wdt:P569 ?born . # Birthdate
FILTER(?born >= "1981-01-01T00:00:00Z"^^xsd:dateTime) # filter by Birthyear
}
ORDER BY ASC(?born)
#LIMIT 500
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,ger". }
}
this gets me (theoretically) all People whose occupation is Musician (https://www.wikidata.org/wiki/Q639669) and who were born after 1900. (Theoretically because this query runs way too long and I had to break it into smaller chunks)
What I am after however is to exclude People who are primary classical musicians. Is there any property I am not aware of? Otherwise, how would I change my query to be able to filter by specific properties (like Q21680663, classical composer)?
Thanks!
If you check the Examples tab in the query interface and type music into the search field, you'll find an example that almost hits the spot:
Musicians or singers that have a genre containing 'rock'.
I've used that mostly to just get a list of all musicians with their genres. I finally settled on a MINUS query subtracting any musician who touches western classical music or baroque music, the latter included specifically to get Bach, the old bastard.
SELECT DISTINCT
?human ?humanLabel
(GROUP_CONCAT(DISTINCT ?genreLabel; SEPARATOR = ", ") AS ?genres)
WHERE {
{
?human wdt:P31 wd:Q5;
wdt:P106 wd:Q639669;
wdt:P136 ?genre.
} MINUS {
VALUES ?classics {
wd:Q9730
wd:Q8361
}
?human wdt:P136 ?classics.
}
# This is just boilerplate to get the labels.
# it's slightly faster this way than the label
# service, and the query is close to timing out already
?genre rdfs:label ?genreLabel.
FILTER((LANG(?genreLabel)) = "en")
?human rdfs:label ?humanLabel.
FILTER((LANG(?humanLabel)) = "en")
}
GROUP BY ?humanLabel ?human
In the Query Interface: 25,000 results in 20sec
Here's a taste of what the results look like (from some intermediate version, because I'm not redoing the table now).
artist
genres
Gigi D'Agostino
Latin jazz, Italo dance
Erykah Badu
neo soul, soul music
Yoko Kanno
jazz, blues, pop music, J-pop, film score, New-age music, art rock, ambient music
Michael Franks
pop music, rock music
Harry Nilsson
rock music, pop music, soft rock, baroque pop, psychedelic rock, sunshine pop
Yulia Nachalova
jazz, pop music, soul music, contemporary R&B, blue-eyed soul, estrada
Linda McCartney
pop rock
From the original example, you may want to try also including singers. The following, replacing the existing line with "P106" does that, and results in about twice as many results. But it often times out.
VALUES ?professions {
wd:Q177220
wd:Q639669
}
wdt:P106 ?professions;
Query including singers, 53,000 results but may time out
The example also uses the following to cut down results rather drastically, by including only items with a certain number of statements, assuming those correlate with... something. You may want to experiment with it to focus on the most significant results, or to give you room to avoid the timeout with other changes. Maybe trying lower limits than 50 to find the right balance is a good idea, though.
?human wikibase:statements ?statementcount.
FILTER(?statementcount > 50 )
A query with singers and the statement limit
This is an earlier version. It excludes all the listed genres, but includes any musician linked to any other genre, and there are many of them that would probably qualify as "classics". The filter uses the "NOT IN" construct, which seems cleaner to me than filtering based on labels.
SELECT DISTINCT
?human ?humanLabel
(GROUP_CONCAT(DISTINCT ?genreLabel; SEPARATOR = ", ") AS ?genres)
WHERE {
?human wdt:P31 wd:Q5;
wdt:P106 wd:Q639669;
wdt:P136 ?genre.
# The "MAGIC": Q9730 is "Western Classical Music"
# Q1344 is "opera"
# Then I noticed Amadeus, Wagner, and Bach all slipped through and expanded the list, and it's a really
# ugly way of doing this
FILTER(?genre NOT IN(wd:Q9730, wd:Q1344, wd:Q9734, wd:Q9748, wd:Q189201, wd:Q8361, wd:Q2142754, wd:Q937364, wd:Q1546995, wd:Q1746028, wd:Q207338, wd:Q3328774, wd:Q1065742))
?genre rdfs:label ?genreLabel.
FILTER((LANG(?genreLabel)) = "en")
?human rdfs:label ?humanLabel.
FILTER((LANG(?humanLabel)) = "en")
}
GROUP BY ?humanLabel ?human
This gets me 26,000 results. View in Query Interface
Note that this will still return artists that have "western classical music" among their genres, aw long as they are also linked to other genres. To exclude any musician ever dabbling in the classics, you'll have to start a daytime top-30 radio station use a MINUS construct to, essentially, subtract all those.
i'm trying to select any active players of an soccer Team.
for example i have selected the football team for Austria
SELECT * WHERE
{
?club a dbo:SoccerClub ;
dbo:ground ?grounds .
?grounds dbo:location ?country.
FILTER(?country = <http://dbpedia.org/resource/Austria>)
}
The
result of the query
seems very well
Now I'm trying to get all active players for one soccer team/club.
for example:http://dbpedia.org/resource/FC_Red_Bull_Salzburg
so I have tried the following query
PREFIX dbpedia: <http://dbpedia.org/property/>
SELECT *
WHERE {
?player dbpedia:currentclub ?teamName.
OPTIONAL {?teamName dbpedia:ground ?ground}.
OPTIONAL {?grounds dbo:location ?country}.
OPTIONAL {?player dbpedia:cityofbirth ?city}.
OPTIONAL {?player dbpedia:dateOfBirth ?dob}.
Filter(?country = <http://dbpedia.org/resource/Austria>)
Filter(?teamName = <http://dbpedia.org/resource/FC_Red_Bull_Salzburg>)
}
but unfortuality the query returns no results.
I would be grateful for any help.
I'm trying to extract all persons that won a (Gold) medal at the Olympics and ideally their birth location using the dbpedia SPARQL query. Basically it's this list I'm aiming at: https://de.wikipedia.org/wiki/Liste_der_olympischen_Medaillengewinner_aus_Spanien
I guess it must somehow work with this piece of code:
yago-res:wikicategory_Olympic_bronze_medalists_for_Spain
This doesn't work:
SELECT ?res
WHERE {
?res yago-res:wikicategory_Olympic_bronze_medalists_for_Spain .
}
any ideas?
To get all the spanish persons that have won the gold medal in olympic
select ?person where
{
?person a <http://dbpedia.org/class/yago/OlympicGoldMedalistsForSpain>
}
If you look at what dbpedia has, there is no class:
http://dbpedia.org/class/yago/OlympicGoldMedalists
but there is
http://dbpedia.org/class/yago/OlympicGoldMedalistsForItaly
and
http://dbpedia.org/class/yago/OlympicGoldMedalistsForFrance
and
http://dbpedia.org/class/yago/OlympicGoldMedalistsForGermany
so a work around could be:
select distinct ?person ?birthPlace where
{
?goldForCountry rdfs:subClassOf yago:Medalist110305062 .
?person a ?goldForCountry .
optional{
?person dbo:birthPlace ?birthPlace
}
filter (contains(str(?goldForCountry), "http://dbpedia.org/class/yago/OlympicGoldMedalistsFor"))
}
The birthPlace should be optional because there are 3994 persons that dbpedia doesn't have their birth place
I have a Sparql query:
SELECT DISTINCT ?film_title ?title ?year
WHERE {
?film_title rdf:type <http://dbpedia.org/ontology/Film> .
?film_title rdfs:label ?title .
?film_title <http://dbpedia.org/ontology/releaseDate> ?year .
FILTER (LANG(?title)='en')
} ORDER BY DESC(?year) LIMIT 100 OFFSET 0
I have used descending order for release year. But some movies are missing, like https://en.wikipedia.org/wiki/The_Lady_in_the_Car_with_Glasses_and_a_Gun_(2015_film). It was released on 5th Aug 2015, but it is still not in the list.
Am I doing something wrong here?
It doesn't appear that DBpedia has an entry for that film. If the article was created recently enough, it might not be in the latest DBpedia.
I learnt some semantic technologies, including RDF and SPARQL, a few years ago, then I didn't have chances to work with them for some time. Now I've started a new project which uses OpenRDF 2.8.0 as a semantic store and I'm resuming my knowledge, even though I have some forgotten things to recover.
In particular, in the past days I had some troubles in correctly undestanding the FILTER NOT EXIST construct in SPARQL.
Problem: I have a semantic store imported from DbTune.org (music ontologies). A mo:MusicArtist, intended as foaf:maker of a mo:Track, can be present in four scenarios (I'm only listing relevant statements):
<http://dbtune.org/musicbrainz/resource/artist/013c8e5b-d72a-4cd3-8dee-6c64d6125823> a mo:MusicArtist ;
vocab:artist_type "1"^^xs:short ;
rdfs:label "Edvard Grieg" .
<http://dbtune.org/musicbrainz/resource/artist/032df978-9130-490e-8857-0c9ef231fae8> a mo:MusicArtist ;
vocab:artist_type "2"^^xs:short ;
rel:collaboratesWith <http://dbtune.org/musicbrainz/resource/artist/3db5dfb1-1b91-4038-8268-ae04d15b6a3e> , <http://dbtune.org/musicbrainz/resource/artist/d78afc01-f918-440c-89fc-9d546a3ba4ac> ;
rdfs:label "Doris Day & Howard Keel".
<http://dbtune.org/musicbrainz/resource/artist/1645f335-2367-427d-8e2d-ad206946a8eb> a mo:MusicArtist ;
vocab:artist_type "2"^^xs:short ;
rdfs:label "Pat Metheny & Anna Maria Jopek".
<http://dbtune.org/musicbrainz/resource/artist/12822d4f-4607-4f1d-ab16-d6bacc27cafe> a mo:MusicArtist ;
rdfs:label "René Marie".
From what I understand, the vocab:artist_type is 1 for single artists (example #1) and 2 for groups of collaborations (examples #2 and #3). In this case, there might a few rel:collaboratesWith statements that point to the description of the single members of the group or collaboration (example #2). In some cases, the vocab:artist_type statement is missing (example #4).
Now I want to extract all the artists as single entities, where possibile. I mean, I don't want to retrieve example #2, because I will get "Doris Day" and "Howard Keel" separately. I have to retrieve example #3 "Pat Metheny & Anna Maria Jopek" because I can't do anything else. Of course, I also want to retrieve "René Marie".
I've solved the problem in a satisfactory way with this SPARQL:
SELECT *
WHERE
{
?artist a mo:MusicArtist.
?artist rdfs:label ?label.
MINUS
{
?artist vocab:artist_type "2"^^xs:short.
?artist rel:collaboratesWith ?any1 .
}
}
ORDER BY ?label
It makes sense and it looks like it's readable ("retrieve all mo:MusicArtist items minus those that are collaborations with individual members listed").
I didn't find the solution immediately. I first thought of putting together the three separate cases, with UNION:
SELECT *
WHERE
{
?artist a mo:MusicArtist.
?artist rdfs:label ?label.
# Single artists
{
?artist vocab:artist_type "1"^^xs:short.
}
UNION
# Groups for which there is no defined collaboration with single persons
{
?artist vocab:artist_type "2"^^xs:short.
FILTER NOT EXISTS
{
?artist rel:collaboratesWith ?any1
}
}
UNION
# Some artists don't have this attribute
{
FILTER NOT EXISTS
{
?artist vocab:artist_type ?any2
}
}
}
ORDER BY ?label
I found that the third UNION statements, the ones which should add mo:MusicArtist items without a vocab:artist_type, didn't worked. That is, they didn't find the items such as "René Marie".
While I'm satisfied with the shortest solution I found with MINUS, I'm not ok with the fact that I don't understand why the older solution didn't work. Clearly I'm missing some point with FILTER NOT EXISTS that could be useful for some other case.
Any help is welcome.
When I run the following query, I get the results that it sounds like you're looking for:
select distinct ?label where {
?artist a mo:MusicArtist ;
rdfs:label ?label .
#-- artists with type 1
{
?artist vocab:artist_type "1"^^xs:short
}
#-- artists with no type
union {
filter not exists {
?artist vocab:artist_type ?type
}
}
#-- artists with type 2 that have no
#-- collaborators
union {
?artist vocab:artist_type "2"^^xs:short
filter not exists {
?artist rel:collaboratesWith ?another
}
}
}
------------------------------------
| label |
====================================
| "René Marie" |
| "Pat Metheny & Anna Maria Jopek" |
| "Edvard Grieg" |
------------------------------------
I'm not whether I see where this essentially differs from yours, though. I do think that you could clean this query up a bit though. You can use optional and values to specify that the type is optional, but if present must be 1 or 2. Then you can add a filter that requires that when the value is 2, there is no collaborator.
select ?label where {
#-- get an artist and their label
?artist a mo:MusicArtist ;
rdfs:label ?label .
#-- and optionally their type, if it is
#-- "1"^^xs:short or "2"^^xs:short
optional {
values ?type { "1"^^xs:short "2"^^xs:short }
?artist vocab:artist_type ?type
}
#-- if ?type is "2"^^xs:short, then ?artist
#-- must not collaborate with anyone.
filter ( !sameTerm(?type,"2"^^xs:short)
|| not exists { ?artist rel:collaboratesWith ?anyone })
}
------------------------------------
| label |
====================================
| "René Marie" |
| "Pat Metheny & Anna Maria Jopek" |
| "Edvard Grieg" |
------------------------------------