Search code examples
nlpsparqlhierarchical-datasuperclasswikidata

finding super classes of an entity in SPARQL


I want to make a Name Entity Recognizer using wikipedia Data, I need to get all the super classes of a word to see in which category (Place, Human, Organization or None) the word is. I surfed the Internet a lot and find some pages like :

which when I execute the query results "No matching records found" even with the word mentioned in the page and trying other namespaces. and:

which is very similar to my work, but I get the "No matching records found" result too.

I think the queries mentioned in these links are logically correct, but I have no idea why they results nothing for me. I also tried to learn SPARQL by examples mentioned in these sites :

and I didn't find anything for finding super classes of a word.

There are some examples of the codes which I didn't get result:

PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX ns:<http://dbpedia.org/>

SELECT ?subClass ?label WHERE { 
    ?subClass rdfs:subClassOf ns:Albert . 
    ?subClass rdfs:label ?label . }

or:

SELECT * WHERE {
  dbpedia:Albert a ?c1 ; a ?c2 .
  ?c1 rdfs:subClassOf ?c2 .
}

Solution

  • Probably, you are looking for something like this query:

    SELECT DISTINCT ?c WHERE {
      ?Q wdt:P31/wdt:P279? ?c .
      ?Q rdfs:label "Tom Hanks"@en
    } 
    

    Wikidata uses its own predicates instead of rdf:type and rdfs:subClassOf (wdt:P31 and wdt:P279 respectively).