Daniele Buonadonna
Daniele Buonadonna

Reputation: 77

Why do I get different result?

i'm a newbie of SPARQL and probably I'm doing a logical mistake, but this is the problem i have:

i want to retrieve "Freddie_Mercury" from a list of people, each one having rdf:Type like dbo:MusicalArtist too.

The first query I have done is this:

select ?x where{?x a dbo:MusicalArtist; dbo:birthName ?realName. FILTER regex(?realName,"Farrokh Bulsara")}

This works great. I get a link to Freddie Mercury page and I can go. But if I run the following python code, Freddie Mercury do not enter in list. Why?

 from SPARQLWrapper import SPARQLWrapper, JSON
#select all people with type MusicalArtist#
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery(
"""select ?singer where{?singer a dbo:MusicalArtist} """)
sparql.setReturnFormat(JSON)
resultsSingers = sparql.query().convert()
#creating list of singers (only complete name)#
singerNames = []
iFoundFreddie = False
#for result in "bindings"#
for result in resultsSingers["results"]["bindings"]:
    try:
        #get string in "singer" in "value", after "/resource/"#
        singerN = result["singer"]["value"].split("/resource/")[1]
        #add string to list#
        singerNames.append(singerN)
        if "_Mercury" in singerN:
            iFoundFreddie = True
    except:
        print("",end="")

print(iFoundFreddie)

Upvotes: 0

Views: 64

Answers (1)

Jeen Broekstra
Jeen Broekstra

Reputation: 22042

DBpedia has a limit of 10,000 on the resultset size you can get by a single query, and there are 71,014 musical artists in DBpedia. Use limit and offset to simulate pagination and get all results by multiple queries (in fact, 8 queries to get all musical artists here).

You can find how many entities there are for a particular type like this:

select (count(?x) as ?cnt) {?x a dbo:MusicalArtist }

Upvotes: 1

Related Questions