Search code examples
sparqldbpedia

Querying dbpedia to get influenced and influence by for a particular artist


I am querying DBpedia to get all the influenced and influencedBy for a particular artist. But the query is giving me a blank result for most of the artists but is showing for some. For example, the result is blank for Andy Warhol (http://dbpedia.org/page/Andy_Warhol) but has some values for Truman Capote (http://dbpedia.org/page/Truman_Capote). I have attached my query below.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX daa: <http://data.americanartcollaborative.org#>
PREFIX cs: <http://purl.org/vocab/changeset/schema#>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX crmeh: <http://purl.org/crmeh#>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX la_vocabs: <http://linkedarc.net/vocabs/>
PREFIX re: <http://www.w3.org/2000/10/swap/reason#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX fo: <http://www.w3.org/1999/XSL/Format#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dul: <http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX db: <http://dbpedia.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT  DISTINCT ?sub ?PersonName ?obj ?influencedPerson ?
 influencedByPerson WHERE {
 ?sub rdf:type owl:Thing.
 ?sub foaf:name ?PersonName.
 ?sub dbo:influenced ?obj.
 ?sub dbo:influencedBy ?obj.
 ?obj foaf:name ?influencedPerson.  
 ?obj foaf:name ?influencedByPerson.
 Filter regex(?PersonName, "Andy Warhol", "i" ) 
}

Please do let me know what is wrong with my query.


Solution

  • The problem is in the data and both properties dbo:influenced and dbo:influencedBy. Indeed a person can occur in both subject or object position of a triple. And for Andy Warhol it's the case that he occurs only in the object position of triples with those relations. In DBpedia pages this is visualized by the pattern "is PROPERTY of", i.e. "is dbo:influenced of" and "is dbo:influencedBy of".

    As a solution for Andy Warhol you have to change your query to:

    SELECT  DISTINCT ?sub ?PersonName ?obj ?influencedPerson ?influencedByPerson WHERE {
     ?sub rdf:type owl:Thing.
     ?sub foaf:name ?PersonName.
     ?obj dbo:influenced ?sub.
     ?obj dbo:influencedBy ?sub.
     ?obj foaf:name ?influencedPerson.  
     ?obj foaf:name ?influencedByPerson.
     Filter regex(?PersonName, "Andy Warhol", "i" ) 
    }
    

    A more generic solution would be to use SPARQL 1.1 property paths, in particular, a combination of the alternative(|) and inverse(^) operators:

    SELECT  DISTINCT ?sub ?PersonName ?obj ?influencedPerson ?influencedByPerson WHERE {
         ?sub rdf:type owl:Thing.
         ?sub foaf:name ?PersonName.
         ?sub dbo:influenced|^dbo:influenced ?obj.
         ?sub dbo:influencedBy|^dbo:influencedBy ?obj.
         ?obj foaf:name ?influencedPerson.  
         ?obj foaf:name ?influencedByPerson.
         Filter regex(?PersonName, "Andy Warhol", "i" ) 
        }
    

    Some comments:

    • you have so many superfluous prefix declarations
    • your query returns only a results if there are persons that influenced Andy Warhol and vice versa because you used the same variable obj (by the way that's the reason why the result is still empty)
    • in addition to the previous point, you're assigning the foaf:name of the same resource to two different variables
    • the triple pattern ?sub rdf:type owl:Thing is semantically "useless"

    I guess your query should more look like that:

    SELECT  DISTINCT ?sub ?PersonName ?influencedPerson ?influencedPersonName ?influencedByPerson ?influencedByPersonName WHERE {
         ?sub foaf:name ?PersonName.
         ?sub dbo:influenced|^dbo:influencedBy ?influencedPerson.
         ?sub dbo:influencedBy|^dbo:influenced ?influencedByPerson.
         ?influencedPerson foaf:name ?influencedPersonName.  
         ?influencedByPerson foaf:name ?influencedByPersonName.
         Filter regex(?PersonName, "Andy Warhol", "i" ) 
    }