Project:SPARQL/examples: Difference between revisions

Line 1,985: Line 1,985:


<sparql tryit="1">
<sparql tryit="1">
# which properties have corresponding wikidata IDs, restricted to properties that are instance of PPA (P12 / Q151)
# which properties have corresponding wikidata IDs, restricted to instance of PPA (P12 / Q151)
 
## **NOTES**
## a few properties have a linked wikidata "Q" rather than "P" ID. These will unfortunately not link correctly to Wikidata so wd_label/wd_description won't be present.
## a few other properties may have wikidata=yes but no wd_label and/or wd_description. This could be because the property on Wikidata has been deleted (eg performed at).


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 1,995: Line 1,999:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>


SELECT DISTINCT ?property ?label (if(bound(?wikidata_id), "yes", "no") as ?has_wikidata) ?wikidata_id ?propertyType
SELECT DISTINCT ?property (if(bound(?wikidata_id), "yes", "no") as ?has_wikidata) ?bn_label ?wd_label ?bn_description
  ?wd_description ?wikidata ?bn_propertyType


WHERE {
WHERE {
   ?property a wikibase:Property ;
   ?property a wikibase:Property ;
               wikibase:propertyType ?propertyType . # datatype
               wikibase:propertyType ?bn_propertyType . # datatype
  service wikibase:label { 
            bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb,en".
            ?property rdfs:label ?bn_label .
            ?property schema:description ?bn_description .
                            }
    # wikidata P117 
    optional { ?property bnp:P117 ?wikidata_id .
                ?wikidata_id bnpq:P14 ?wikidata_url .
            # the string to replace needs to be different for properties! 
              BIND(IRI(REPLACE(?wikidata_url, "https://www.wikidata.org/wiki/Property:", "http://www.wikidata.org/entity/")) as ?wikidata )


  optional { ?property rdfs:label ?en . filter(lang(?en)="en"). }
            SERVICE <https://query.wikidata.org/sparql> {
  optional { ?property rdfs:label ?engb . filter(lang(?engb)="en-gb").
                    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb,en".  
  BIND(COALESCE(?en, ?engb) AS ?label).
                            ?wikidata schema:description ?wd_description .
    
                            ?wikidata rdfs:label ?wd_label .  
  optional { ?property bnwdt:P117 ?wikidata_id . } # wikidata P117
                    } # / label service
              } # /wikidata service    
          } #/wikidata optional
    
    
  ?property bnwdt:P12 bnwd:Q151. # instance of PPA
    ?property bnwdt:P12 bnwd:Q151. # instance of PPA
}
}
order by ?label
order by ?bn_label
</sparql>
</sparql>


579

edits