'SPARQL Query to extract subject predicate and object for persons

I'm new to semantic web and trying to figure out a way to get some data about persons in the format as it is presented in attached image. If anybody could help i'll be thankful. Subject Prediate Object



Solution 1:[1]

As you're starting out, I'm going to make a few assumptions. Firstly, that image is an over-simplification of the data that will be returned, all of the subjects and predicates will be URI's and not all that data is in DBpedia.

I'm going to assume you will be using the SPARQL endpoint at , which will return results to you, in browser in a HTML table. You can also send SPARQL requests to the same URL with appropriate software/libraries.

Here's a query to get you started, there's an awful lot of people on DBpedia, so I've made it so you can choose who you want. The query will also only return ?objects that are in English, you can remove the && lang(?object) = "en" to get all objects. The line ?subject a dbo:Person. is not strictly required, but I've left it in so that you can remove all filtering and still only get people. LIMIT 20 is the maximum number of rows it will return.

SELECT DISTINCT *
WHERE {
   ?subject a dbo:Person.
   ?subject ?predicate ?object.
   FILTER (?subject IN (dbr:John_Lennon, dbr:Yoko_Ono, dbr:Jimmy_Carter,
           dbr:Bill_Clinton) && lang(?object) = "en")
} LIMIT 20

Put that into the form here and you'll get some results as a table with three columns : ?subject, ?predicate, ?object

Solution 2:[2]

You might want to try wikidata and the command line tool https://github.com/maxlath/wikibase-cli

npm install -g wikibase-cli

Then configure your language to english

wd config lang en

now search your subjects one by one:

wd search "John Lennon"

and pick/deduplicate the entry you are looking for e.g. for John Lennon:

Q1203      John Lennon English singer and songwriter, founding member of The Beatles (1940–1980)

check that there is a claim for your predicate e.g.

wd claims Q1203 | grep instrument
instrument (P1303):    
   guitar (Q6607) | 
   piano (Q5994) | 
   harmonica (Q51290) | 
   bass guitar (Q46185) | 
   keyboard instrument (Q52954) | 
   voice (Q17172850)

repeat ...

If you are not sure about the available predicates use

wd props

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gilles-Antoine Nys
Solution 2 Wolfgang Fahl