Project:SPARQL/examples: Difference between revisions
From geokb
(Created page with "= Organizations = == Classification of organizations == <sparql tryit="1"> PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/> PREFIX wd: <https://geokb.wikibase.cloud/entity/> SELECT ?item ?itemLabel ?subclass_of ?subclass_ofLabel WHERE { { wd:Q50862 wdt:P2* ?item . ?item wdt:P2 ?subclass_of . } UNION { ?item wdt:P2* wd:Q50862 ; wdt:P2 ?subclass_of . } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } } </sparql>") |
|||
Line 3: | Line 3: | ||
== Classification of organizations == | == Classification of organizations == | ||
<sparql tryit="1"> | <sparql list="1" tryit="1"> | ||
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/> | PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/> | ||
PREFIX wd: <https://geokb.wikibase.cloud/entity/> | PREFIX wd: <https://geokb.wikibase.cloud/entity/> | ||
Line 18: | Line 18: | ||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } | SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } | ||
} | } | ||
</sparql> | |||
== USGS Organizations == | |||
<sparql list="1" tryit="1"> | |||
PREFIX wd: <https://geokb.wikibase.cloud/entity/> | |||
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/> | |||
SELECT ?item ?itemLabel ?item_alt_label ?instance_ofLabel | |||
(GROUP_CONCAT(?url; separator=",") AS ?urls) | |||
WHERE { | |||
?org_types wdt:P2 wd:Q50862 . # Gets subclasses of USGS organization | |||
?item wdt:P1 ?org_types ; # Gets items in those classes | |||
wdt:P1 ?instance_of . # Gets the individual instance of classification | |||
OPTIONAL { | |||
?item skos:altLabel ?item_alt_label . # Retrieves alternate labels into separate rows | |||
FILTER (lang(?item_alt_label)='en') | |||
} | |||
OPTIONAL { | |||
?item wdt:P145 ?url . # Get all reference URLs when available | |||
} | |||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } | |||
} | |||
GROUP BY ?item ?itemLabel ?item_alt_label ?instance_ofLabel | |||
</sparql> | </sparql> |
Revision as of 13:49, 8 August 2024
Organizations
Classification of organizations
The following query uses these:
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
SELECT ?item ?itemLabel ?subclass_of ?subclass_ofLabel
WHERE {
{
wd:Q50862 wdt:P2* ?item .
?item wdt:P2 ?subclass_of .
} UNION {
?item wdt:P2* wd:Q50862 ;
wdt:P2 ?subclass_of .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
USGS Organizations
The following query uses these:
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel ?item_alt_label ?instance_ofLabel
(GROUP_CONCAT(?url; separator=",") AS ?urls)
WHERE {
?org_types wdt:P2 wd:Q50862 . # Gets subclasses of USGS organization
?item wdt:P1 ?org_types ; # Gets items in those classes
wdt:P1 ?instance_of . # Gets the individual instance of classification
OPTIONAL {
?item skos:altLabel ?item_alt_label . # Retrieves alternate labels into separate rows
FILTER (lang(?item_alt_label)='en')
}
OPTIONAL {
?item wdt:P145 ?url . # Get all reference URLs when available
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
GROUP BY ?item ?itemLabel ?item_alt_label ?instance_ofLabel