Use DBPedia to download all people along with some data

I am using DBpedia for the first time. I would like to load all the people in the people’s dataset along with the properties for commonName, nationality, birthDate and knownFor (I will eventually bind it to an extension sheet using some kind of scripting language that seems to me).

This was my first request attempt to complete this work, however it does not work. I tried to assemble it along with other bits of code that I saw on the Internet. Does anyone know how to fix this? Thanks

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?person ?commonName ?nationality ?knownFor ? birthDate WHERE { ?person a type:Person . ?person prop:commonName ?commonNameFilter(lang(?commonName) = 'en') . ?person prop:nationality ?nationality(lang(?nationality) = 'en') . ?person prop:knownFor ?knownFor(lang(?knownFor) = 'en') . ?person prop:birthDate ?birthDate . } 

EDIT: NEW CODE VERSION: COMMUNITY RETURNS (WITH UNCERTAIN DUBLINES). STILL DO NOT MISS OTHER PROPERTIES.

 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/ontology/> SELECT DISTINCT * WHERE { ?person a dbpedia-owl:Person ; dbpedia-owl:commonName ?commonName . FILTER(lang(?commonName) = 'en') } LIMIT 30 
+4
source share
2 answers

Firstly, your request contains many syntax issues:

 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> ^ you probably want to use the dbpedia-owl properties which are # in <http://dbpedia.org/ontology/> SELECT ?person ?commonName ?nationality ?knownFor ? birthDate ^ space between ? and varname WHERE { ?person a type:Person . ?person prop:commonName ?commonNameFilter(lang(?commonName) = 'en') . ^ This needs to be "?commonName . FILTER(..." # and the same thing applies to your other # filters ?person prop:nationality ?nationality(lang(?nationality) = 'en') . ?person prop:knownFor ?knownFor(lang(?knownFor) = 'en') . ?person prop:birthDate ?birthDate . } 

Gradually create some of these queries gradually, because then you can find out what properties some of the resources have, and then you can expand your query a little more. The public endpoint has a number of predefined namespaces , and using these methods will make it easier to read by your other request. So you can start by asking for people:

 SELECT * WHERE { ?person a dbpedia-owl:Person . } LIMIT 10 

SPARQL Results

After seeing that this works, you can look at some of the returned instances and see that they have the dbpedia-owl:commonName properties, and then expand the query:

 SELECT * WHERE { ?person a dbpedia-owl:Person ; dbpedia-owl:commonName ?commonName . } LIMIT 10 

SPARQL Results

It is easy enough to expand it with the dbpedia-owl:birthDate . I don’t see the nationality predicate for the instances I was looking at, so I'm not sure what you based your query on nationality on. Although I have seen some use of the knownFor property, I have not seen it in many cases, so if you make it mandatory, you will exclude many people. However, such an incremental approach is likely to help you in the long run.

Property Search

While a searchable ontology provides a good way to search for classes, I'm not sure if there is such a good way to search for properties. However, you can do something rude. For example, to find all the properties that were actually used for Person s, you can run a query like the one below. (Note: this query takes some time to complete, so if you use it, you should probably download the results.)

 select distinct ?p where { [] a dbpedia-owl:Person ; ?p [] . } 

SPARQL Results

I note that dbpedia-owl:nationality appears in this list.

To get all the properties for everything, you can load the ontology and run a query like:

 prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> select * where { { ?pa owl:ObjectProperty } UNION { ?pa owl:DatatypeProperty } } 

I ran this locally using Jena ARQ:

 $ arq --query properties.sparql --data dbpedia_3.8.owl ---------------------------------------------------------------------------- | p | ============================================================================ | <http://dbpedia.org/ontology/regionServed> | | <http://dbpedia.org/ontology/coachedTeam> | | <http://dbpedia.org/ontology/legalForm> | | <http://dbpedia.org/ontology/goldenCalfAward> | | <http://dbpedia.org/ontology/composer> | | <http://dbpedia.org/ontology/owningOrganisation> | | <http://dbpedia.org/ontology/branchFrom> | | <http://dbpedia.org/ontology/iso6393Code> | ... | <http://dbpedia.org/ontology/classification> | | <http://dbpedia.org/ontology/bgafdId> | | <http://dbpedia.org/ontology/currencyCode> | | <http://dbpedia.org/ontology/onChromosome> | | <http://dbpedia.org/ontology/course> | | <http://dbpedia.org/ontology/frequentlyUpdated> | | <http://dbpedia.org/ontology/distance> | | <http://dbpedia.org/ontology/volume> | | <http://dbpedia.org/ontology/description> | ---------------------------------------------------------------------------- 

This will not provide rdfs:domain and rdfs:range , but you can also request them or just for these properties using rdfs:range dbpedia-owl:Person (but note that this will not get all the properties that Person can use as the range may be more or less specific):

 prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> prefix dbpedia-owl: <http://dbpedia.org/ontology/> prefix xsd: <http://www.w3.org/2001/XMLSchema#> select ?p ?range where { { ?pa owl:ObjectProperty } UNION { ?pa owl:DatatypeProperty } ?p rdfs:domain dbpedia-owl:Person ; rdfs:range ?range . } $ arq --query properties.sparql --data dbpedia_3.8.owl | head -------------------------------------------------------------------------------------------------------- | p | range | ======================================================================================================== | dbpedia-owl:restingPlacePosition | <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing> | | dbpedia-owl:opponent | dbpedia-owl:Person | | dbpedia-owl:employer | dbpedia-owl:Organisation | | dbpedia-owl:hometown | dbpedia-owl:Settlement | | dbpedia-owl:militaryBranch | dbpedia-owl:MilitaryUnit | | dbpedia-owl:school | dbpedia-owl:EducationalInstitution | | dbpedia-owl:ethnicity | dbpedia-owl:EthnicGroup | ... | dbpedia-owl:sex | xsd:string | | dbpedia-owl:hipSize | xsd:double | | dbpedia-owl:individualisedPnd | xsd:nonNegativeInteger | | dbpedia-owl:weddingParentsDate | xsd:date | | dbpedia-owl:birthName | xsd:string | | dbpedia-owl:networth | xsd:double | | dbpedia-owl:birthYear | xsd:gYear | | dbpedia-owl:bustSize | xsd:double | | dbpedia-owl:description | xsd:string | -------------------------------------------------------------------------------------------------------- 
+6
source

I'm not very good at SPARQL yet, but I see some syntax issues. I rewrote the request like this:

 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?person, ?commonName, ?nationality, ?knownFor, ?birthDate WHERE { ?person a type:Person . ?person prop:commonName ?commonName . FILTER (lang(?commonName) = 'en') . ?person prop:nationality ?nationality . FILTER (lang(?nationality) = 'en') . ?person prop:knownFor ?knownFor . FILTER (lang(?knownFor) = 'en') . ?person prop:birthDate ?birthDate . } 

and now it at least executes the request without error. but I do not see the results. not sure why

+2
source

Source: https://habr.com/ru/post/1491487/


All Articles