Reputation: 3
I have this function:
`def get_author_books():
sparql = SPARQLWrapper('https://dbpedia.org/sparql')
sparql.setQuery("""
SELECT distinct ?s ?author
WHERE{ ?s rdf:type dbo:Book .
?s rdfs:label ?bookLabel .
FILTER(LANGMATCHES(LANG(?bookLabel), 'en'))
?s dbo:author ?author .
?author rdfs:label ?authorLabel .
FILTER(LANGMATCHES(LANG(?authorLabel), 'en'))
?authorLabel bif:contains "St"
OPTIONAL {{ ?s dbp:country ?country .
?country rdfs:label ?countryLabel .
FILTER(LANGMATCHES(LANG(?countryLabel), 'en')) }}
OPTIONAL {{ ?s dbo:literaryGenre ?genre .
?genre rdfs:label ?genreLabel .
FILTER(LANGMATCHES(LANG(?genreLabel), 'en')) }}
OPTIONAL {{ ?s dbp:language ?language .
?language rdfs:label ?languageLabel .
FILTER(LANGMATCHES(LANG(?languageLabel), 'en')) }}
} """)
sparql.setReturnFormat(JSON)
qres = sparql.query().convert()
info = []
for i in range(len(qres)):
result = qres['results']['bindings'][i]
author, book = (result['author']['value']).split('/')[-1], (result['s']['value']).split('/')[-1]
info.append((author, book))
print(info)
print(len(qres))
return info`
when I run the code I only get 2 results : [('Lucia_St._Clair_Robson', 'Ride_the_Wind'), ('Lucia_St._Clair_Robson', 'Fearless,_A_Novel_of_Sarah_Bowman')] 2 . While, in reality, the query has more than 20 results...appreciate your help
Upvotes: 0
Views: 69