i using dbpedia first time. download people in dataset of people along properties commonname, nationality, birthdate, , knownfor (i stick excel spread sheet using sort of scripting language think).
this first attempt @ query job, not work. tried piecing other bits of code i've seen on internet. know how 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 { ?person 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 version of code: returns commonname (with non-english duplicates). still missing 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 * { ?person dbpedia-owl:person ; dbpedia-owl:commonname ?commonname . filter(lang(?commonname) = 'en') } limit 30
first, query has bunch of 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/> ^ want use dbpedia-owl properties # in <http://dbpedia.org/ontology/> select ?person ?commonname ?nationality ?knownfor ? birthdate ^ space between ? , varname { ?person type:person . ?person prop:commonname ?commonnamefilter(lang(?commonname) = 'en') . ^ needs "?commonname . filter(..." # , same thing applies other # filters ?person prop:nationality ?nationality(lang(?nationality) = 'en') . ?person prop:knownfor ?knownfor(lang(?knownfor) = 'en') . ?person prop:birthdate ?birthdate . }
it's easier build of these queries incrementally, because can find out properties of resources actually have, , can extend query more. public endpoint has number of predefined namespaces, , using make easier others read query. so, can start asking people:
select * { ?person dbpedia-owl:person . } limit 10
seeing that's working, can @ of returned instances , see have dbpedia-owl:commonname
properties, , extend query:
select * { ?person dbpedia-owl:person ; dbpedia-owl:commonname ?commonname . } limit 10
it's easy enough extend dbpedia-owl:birthdate
property. don't see nationality
predicate on instances i've looked at, i'm not sure basing nationality query on. while saw use of knownfor
property, didn't see on many instances, if make required property, you're going exclude lots of people. sort of incremental approach out in long run, though.
finding properties
while browseable ontology provides nice way find classes, i'm not sure whether there's such nice way of finding properties. however, can in brute force manner. e.g., find properties have been used person
s, can run query following. (note: query takes while execute, if use it, should download results.)
select distinct ?p { [] dbpedia-owl:person ; ?p [] . }
i'll note dbpedia-owl:nationality
does appear in list.
to properties everything, can download ontology, , run query like:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix owl: <http://www.w3.org/2002/07/owl#> select * { { ?p owl:objectproperty } union { ?p owl:datatypeproperty } }
i ran locally using jena's 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> | ----------------------------------------------------------------------------
that won't provide rdfs:domain
, rdfs:range
, ask these, or properties rdfs:range dbpedia-owl:person
(but note won't properties used person
, since range 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 { { ?p owl:objectproperty } union { ?p 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 | --------------------------------------------------------------------------------------------------------
Comments
Post a Comment