Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SPARQL 3.16 KB | None | 0 0
  1. PREFIX entity: <http://www.wikidata.org/entity/>
  2. SELECT ?entity ?propNumber ?propLabel ?val  WHERE   {
  3.   {
  4.     BIND(entity:Q42 AS ?entity)
  5.  
  6.     {
  7.       BIND(?entity AS ?valUrl)
  8.       BIND("N/A" AS ?propUrl)
  9.       BIND("Label"@en AS ?propLabel)
  10.       ?entity rdfs:label ?val.
  11.       FILTER((LANG(?val)) = "en")
  12.     }
  13.     UNION
  14.     {
  15.       BIND(?entity AS ?valUrl)
  16.       BIND("AltLabel"@en AS ?propLabel)
  17.       OPTIONAL { ?entity skos:altLabel ?val. }
  18.       FILTER((LANG(?val)) = "en")
  19.     }
  20.     UNION
  21.     {
  22.       BIND(?entity AS ?valUrl)
  23.       BIND("Description"@en AS ?propLabel)
  24.       OPTIONAL { ?entity schema:description ?val. }
  25.       FILTER((LANG(?val)) = "en")
  26.     }
  27.     UNION
  28.     {
  29.       # get the value of each property on this entity
  30.       ?entity ?propUrl ?valUrl.
  31.       ?property ?ref ?propUrl.
  32.       ?property rdf:type wikibase:Property.
  33.       ?property rdfs:label ?propLabel.
  34.  
  35.       BIND(?valUrl AS ?val)
  36.       FILTER((LANG(?val)) = "en")
  37.       FILTER((LANG(?propLabel)) = "en")
  38.       FILTER(ISLITERAL(?valUrl))
  39.     }
  40.     UNION
  41.     {
  42.       # special case: get the quantity amount and unit
  43.       ?entity ?propUrl ?valUrl.
  44.       ?property ?ref ?propUrl.
  45.       ?property rdf:type wikibase:Property.
  46.       ?property rdfs:label ?propLabel.
  47.      
  48.       ?property wikibase:claim ?p;
  49.                 wikibase:statementValue ?pv.
  50.       ?entity ?p [
  51.         ?pv [
  52.           wikibase:quantityAmount     ?qm ;
  53.           wikibase:quantityUnit       ?qu
  54.         ]
  55.       ].
  56.       ?qu rdfs:label ?quLabel.
  57.  
  58.       BIND(CONCAT(STR(?qm), " ", STR(?quLabel)) AS ?val)
  59.       FILTER((LANG(?propLabel)) = "en")
  60.       FILTER((LANG(?quLabel)) = "en")
  61.       FILTER(ISLITERAL(?valUrl))
  62.     }
  63.     UNION
  64.     {
  65.       # special case: get the time value.
  66.       ?entity ?propUrl ?valUrl.
  67.       ?property ?ref ?propUrl.
  68.       ?property rdf:type wikibase:Property.
  69.       ?property rdfs:label ?propLabel.
  70.  
  71.       ?property wikibase:claim ?p;
  72.                 wikibase:statementValue ?pv.
  73.       ?entity ?p [?pv [wikibase:timeValue ?tm ;]].
  74.  
  75.       BIND(?tm AS ?val)
  76.       FILTER((LANG(?propLabel)) = "en")
  77.       FILTER(ISLITERAL(?valUrl))
  78.     }
  79.     UNION
  80.     {
  81.       # special case: keep IRIs that aren't wikidata IRIs (eg, commons media)
  82.       ?entity ?propUrl ?valUrl.
  83.       ?property ?ref ?propUrl.
  84.       ?property rdf:type wikibase:Property.
  85.       ?property rdfs:label ?propLabel.
  86.  
  87.       BIND(?valUrl AS ?val)
  88.  
  89.       FILTER((LANG(?propLabel)) = "en")
  90.       FILTER(ISIRI(?valUrl))
  91.       FILTER(!CONTAINS(STR(?valUrl), "wikidata.org"))
  92.     }
  93.     UNION
  94.     {
  95.       # special case: get Wolfram Entity IDs for values, if they exist
  96.       ?entity ?propUrl ?valUrl.
  97.       ?property ?ref ?propUrl.
  98.       ?property rdf:type wikibase:Property.
  99.       ?property rdfs:label ?propLabel.
  100.       ?valUrl rdfs:label ?valLabel.
  101.       OPTIONAL { ?valUrl wdt:P4839 ?wlEntity. }
  102.  
  103.       BIND(IF((BOUND(?wlEntity)) && ((STRLEN(?wlEntity)) > 0), CONCAT(?wlEntity), CONCAT(?valLabel)) AS ?val)
  104.  
  105.       FILTER((LANG(?valLabel)) = "en")
  106.       FILTER((LANG(?propLabel)) = "en")
  107.     }
  108.     BIND(SUBSTR(STR(?propUrl), 38, 250) AS ?propNumber)
  109.   }
  110. } ORDER BY xsd:integer(?propNumber)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement