Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving most specific classes of instances

Is it possible to have a definition of an resource (from DBpedia) with a SPARQL query? I want to have something like the TBox and ABox that are shown in (Conceptual) Clustering methods for the Semantic Web: issues and applications (slides 10–11). For example, for DBpedia resource Stephen King, I would like to have:

Stephen_King : Person ⊓ Writer ⊓ Male ⊓ … (most specific classes)

like image 928
user2837896 Avatar asked Oct 28 '13 11:10

user2837896


1 Answers

You can use a query like the following to ask for the classes of which Stephen King is an instance which have no subclasses of which Stephen King is also an instance. This seems to align well with the idea of “most specific classes.” However, since (as far as I know) there's no reasoner attached to the DBpedia SPARQL endpoint, there may be subclass relationships that could be inferred but which aren't explicitly present in the data.

select distinct ?type where { 
   dbr:Stephen_King a ?type .
  filter not exists { 
    ?subtype ^a  dbr:Stephen_King ;
             rdfs:subClassOf ?type .
  }
}

SPARQL results

Actually, since every class is an rdfs:subClassOf itself, you might want to add another line to that query to exclude the case where ?subtype and ?type are the same:

select distinct ?type where { 
   dbr:Stephen_King a ?type .
  filter not exists { 
    ?subtype ^a  dbr:Stephen_King ;
             rdfs:subClassOf ?type .
    filter ( ?subtype != ?type )
  }
}

SPARQL results

If you actually want a result string like the one shown in those slides, you could use values to bind a variable to dbr:Stephen_King, and then use some grouping and string concatenation to get something nicer looking (sort of):

select
  (concat( ?person, " =\n", group_concat(?type; separator=" AND\n")) as ?sentence)
where { 
  values ?person {  dbr:Stephen_King }
  ?type ^a ?person .
  filter not exists { 
    ?subtype ^a ?person ;
             rdfs:subClassOf ?type .
    filter ( ?subtype != ?type )
  }
}
group by ?person

SPARQL results

http://dbpedia.org/resource/Stephen_King =
http://dbpedia.org/class/yago/AuthorsOfBooksAboutWritingFiction AND
http://dbpedia.org/ontology/Writer AND
http://schema.org/Person AND
http://xmlns.com/foaf/0.1/Person AND
http://dbpedia.org/class/yago/AmericanSchoolteachers AND
http://dbpedia.org/class/yago/LivingPeople AND
http://dbpedia.org/class/yago/PeopleFromBangor,Maine AND
http://dbpedia.org/class/yago/PeopleFromPortland,Maine AND
http://dbpedia.org/class/yago/PeopleFromSarasota,Florida AND
http://dbpedia.org/class/yago/PeopleSelf-identifyingAsAlcoholics AND
http://umbel.org/umbel/rc/Artist AND
http://umbel.org/umbel/rc/Writer AND
http://dbpedia.org/class/yago/20th-centuryNovelists AND
http://dbpedia.org/class/yago/21st-centuryNovelists AND
http://dbpedia.org/class/yago/AmericanHorrorWriters AND
http://dbpedia.org/class/yago/AmericanNovelists AND
http://dbpedia.org/class/yago/AmericanShortStoryWriters AND
http://dbpedia.org/class/yago/CthulhuMythosWriters AND
http://dbpedia.org/class/yago/HorrorWriters AND
http://dbpedia.org/class/yago/WritersFromMaine AND
http://dbpedia.org/class/yago/PeopleFromDurham,Maine AND
http://dbpedia.org/class/yago/PeopleFromLisbon,Maine AND
http://dbpedia.org/class/yago/PostmodernWriters
like image 116
Joshua Taylor Avatar answered Sep 20 '22 05:09

Joshua Taylor