Get a gender of a particular person in SPARQL…?

一世执手 提交于 2019-12-01 11:58:30
O. R. Mapper

DBpedia is not a particularly complete dataset. It is well possible that for the person you are looking at, there simply is no gender property of any kind defined - similar to the situation outlined in the answer in this thread.

Even if there is, keep in mind that it can be expressed by a variety of properties and values, so you would have to check all of them to at least use the data where it is defined. A quick check shows me at least the following properties that may store the information you are interested in:

Note that some of these may link to other resources such as Male or Female, whereas others will simply contain strings such as male or female (the FOAF specification explicitly says

typically but not necessarily 'male' or 'female'

).


The following query, for example, returns the gender of Scheherazade:

SELECT ?gl
WHERE {
  dbpedia:Scheherazade dbpedia-owl:gender ?g.
  ?g rdfs:label ?gl.
  FILTER(lang(?gl) = "en").
}

Likewise, the following query lists the name and gender of a number of persons:

SELECT ?pn ?gl
WHERE {
  ?person dbpedia-owl:gender ?g.
  ?person a dbpedia-owl:Person.
  ?person dbpprop:name ?pn.
  {
    ?person dbpedia-owl:gender dbpedia:Male.
  } UNION {
    ?person dbpedia-owl:gender dbpedia:Female.
  }.
  ?g rdfs:label ?gl.
  FILTER(lang(?gl) = "en").
}

However, this query can capture only those persons for which the respective type and gender attributes are set. Larry Page will never appear in that list with the current dataset as it does not have the respective gender property. As another practical example see this very similar query, which returns a different (non-empty) list:

SELECT ?pn ?gl
WHERE {
  ?person dbpedia-owl:gender ?g.
  ?person a dbpedia-owl:Person.
  ?person dbpprop:name ?pn.
  {
    ?person dbpedia-owl:gender dbpedia:Man.
  } UNION {
    ?person dbpedia-owl:gender dbpedia:Woman.
  }.
  ?g rdfs:label ?gl.
  FILTER(lang(?gl) = "en").
}

Yet another query returns yet another list:

SELECT ?pn ?gl
WHERE {
  ?person ?gender ?gl.
  ?person a dbpedia-owl:Person.
  ?person dbpprop:name ?pn.
  FILTER((?gl = "Female"@en) || (?gl = "Male"@en)).
}

EDIT: DBpedia's default namespace prefixes have changed since writing this answer. The mapping is as follows:

  • dbpedia -> http://dbpedia.org/resource/ (now dbr)
  • dbpedia-owl -> http://dbpedia.org/ontology/ (now dbo)
  • dbpprop -> http://dbpedia.org/property/ (now dbp)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!