0

How do I form the query to look up the English label of a property on a given entity.

This query provides the ID of P31:

SELECT ?item ?itemLabel ?instance_of WHERE {
  ?item wdt:P646 "/m/09c7w0".
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  OPTIONAL {
    ?item wdt:P31 ?instance_of.}
  }
}
LIMIT 1

How can I get the label of P31 instead?

Also, is there a smart way to get the "best" value of P31, possibly the one with the lowest numeric ID? Some detailed entities have very noisy values. For example, for Q30, "United States" I would prefer to see "country" as my instance_of instead of "member state of the United Nations".

logi-kal
  • 7,107
  • 6
  • 31
  • 43
bhan
  • 2,489
  • 3
  • 19
  • 26
  • You should understand *how* the label service works...don't copy and paste from other sources without knowing what the query does! Append `Label` to existing variables is the way to go -> `?instance_ofLabel` By the way, do you know what the instance_of relation ship means? If so, I'd use another variable name, but indeed it's your decision. From my point of view, this property denotes the type(s) of an entity. – UninformedUser Jul 26 '17 at 19:41
  • Define "best way". The lowest numeric ID indicates what? Exactly, nothing - it's just an ID. Indeed LIMIT 1 returns one type of the entity randomly. So again, how do you define "best type" of an entity? You need some formal criteria as SPARQL is a formal query language. – UninformedUser Jul 26 '17 at 19:45
  • I don't disagree about type, but `instance of` is the verbatim English label of predicate `P31`. No, ID doesn't represent anything in itself, but its an easy proxy for importance in wikidata. ID's are generally created in ascending order and entities created earlier tend to be more general concepts while newer ones are typically more obscure or esoteric. – bhan Jul 26 '17 at 22:52
  • But I guess for types there are "better" and more formal ways to define a ranking. Usually what you have is the number of instances of a type and the level in the type hierarchy to sue or maybe combine in a more complex measure. Other ranking methods are beyond a single SPARQL query and have to be computed offline and are still research topic called *entity ranking*. – UninformedUser Jul 27 '17 at 03:41

1 Answers1

0

Thanks AKSW. label service applies to the property given a variable with the matching suffix Label:

SELECT ?item ?itemLabel ?instance_of ?instance_ofLabel WHERE {
  ?item wdt:P646 "/m/09c7w0".
  OPTIONAL {
    ?item wdt:P31 ?instance_of.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 1
bhan
  • 2,489
  • 3
  • 19
  • 26