Project:SPARQL/examples: Difference between revisions

From geokb
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 42: Line 42:
}
}
GROUP BY ?item ?itemLabel ?item_alt_label ?instance_ofLabel
GROUP BY ?item ?itemLabel ?item_alt_label ?instance_ofLabel
</sparql>
== Organization URL Lookup ==
Sometimes, we need to use a URL for an organization as an identifier to find that organization entity. The following query pulls all USGS organizations with official website claims along with an optional "previous address" qualifier that can contain one or more alternate URLs that apply to the organization. These may or may not be active, resolvable URLs but can show up as references.
<sparql tryit="1">
PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>
PREFIX p: <https://geokb.wikibase.cloud/prop/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel ?url ?alt_url
WHERE {
  ?item wdt:P1/wdt:P2* wd:Q50862 ;
        wdt:P1 ?instance_of ;
        wdt:P145 ?url ;
        p:P145 ?url_statement .
  OPTIONAL {
    ?url_statement pq:P202 ?alt_url .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
</sparql>
</sparql>


Line 98: Line 120:
   ?item wdt:P2* wd:Q158710 ;
   ?item wdt:P2* wd:Q158710 ;
         skos:altLabel ?itemAltLabel .
         skos:altLabel ?itemAltLabel .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
</sparql>
= USGS Model Catalog =
<sparql tryit="1">
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel ?instance_of ?instance_ofLabel
?model_cat_id ?pub_date
?author ?authorLabel ?has_part ?has_partLabel
?subject_of ?subject_ofLabel
?addresses_subject ?addresses_subjectLabel
WHERE {
  ?item wdt:P219 ?model_cat_id ;
        wdt:P1 ?instance_of .
  OPTIONAL {
    ?item wdt:P7 ?pub_date .
  }
  OPTIONAL {
    ?item wdt:P102 ?author .
  }
  OPTIONAL {
    ?item wdt:P63 ?has_part .
  }
  OPTIONAL {
    ?item wdt:P218 ?subject_of .
  }
  OPTIONAL {
    ?item wdt:P94 ?addresses_subject .
  }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
}
Line 108: Line 163:


<sparql tryit="1">
<sparql tryit="1">
PREFIX schema: <http://schema.org/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
Line 113: Line 169:
PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>
PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>


SELECT ?item ?itemLabel ?orcid ?email ?url ?end_time
SELECT ?item ?itemLabel ?orcid ?email ?url ?end_time ?dateModified
WHERE {
WHERE {
   ?item wdt:P107 wd:Q44210 ; # Employed by the USGS
   ?item wdt:P107 wd:Q44210 ; # Employed by the USGS
         p:P107 ?prop_statement .
         p:P107 ?emp_statement ;
        schema:dateModified ?dateModified .
   OPTIONAL {
   OPTIONAL {
     ?prop_statement pq:P61 ?end_time . # Any value here indicates that employment status ended at some point
     ?emp_statement pq:P61 ?end_time . # Any value here indicates that employment status ended at some point
   }
   }
   OPTIONAL {
   OPTIONAL {
Line 131: Line 188:
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
}
</sparql>
== USGS Climate Change Science Ontology ==
=== Climate Change Science Topics ===
<sparql tryit="1">
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
SELECT ?loi ?loiLabel ?loiDescription
?topic ?topicLabel ?topicDescription
?subject ?subjectLabel ?subjectDescription
WHERE {
  ?loi wdt:P62 wd:Q160059 . # Highest level grouping concepts representing broad scientific lines of inquiry
  ?topic wdt:P62 ?loi . # Next-level set of research topics and scientific methods directly associated with the lines of inquiry
  {
    ?subject wdt:P94* ?topic . # addresses subject
  } UNION {
    ?subject wdt:P95* ?topic . # addresses place
  } UNION {
    ?subject wdt:P208* ?topic . # uses
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
</sparql>
=== Climate Change Science Linked Entities ===
<sparql tryit="1">
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
SELECT ?loi ?loiLabel
?topic ?topicLabel
?subject ?subjectLabel
?person ?personLabel
WHERE {
  ?loi wdt:P62 wd:Q160059 .
  ?topic wdt:P62 ?loi .
  {
    ?subject wdt:P94* ?topic . # addresses subject
  } UNION {
    ?subject wdt:P95* ?topic . # addresses place
  } UNION {
    ?subject wdt:P208* ?topic . # uses
  }
  {
    ?person wdt:P203 ?topic .
  } UNION {
    ?person wdt:P203 ?subject .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 1000
</sparql>
</sparql>

Latest revision as of 18:54, 30 September 2024

Organizations

Classification of organizations

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" . }
}

Try it!


USGS Organizations

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

Try it!


Organization URL Lookup

Sometimes, we need to use a URL for an organization as an identifier to find that organization entity. The following query pulls all USGS organizations with official website claims along with an optional "previous address" qualifier that can contain one or more alternate URLs that apply to the organization. These may or may not be active, resolvable URLs but can show up as references.

PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>
PREFIX p: <https://geokb.wikibase.cloud/prop/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>

SELECT ?item ?itemLabel ?url ?alt_url
WHERE {
  ?item wdt:P1/wdt:P2* wd:Q50862 ;
        wdt:P1 ?instance_of ;
        wdt:P145 ?url ;
        p:P145 ?url_statement .
  OPTIONAL {
    ?url_statement pq:P202 ?alt_url .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


People

People and their identifiers

PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX p: <https://geokb.wikibase.cloud/prop/>
PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>

SELECT ?item ?itemLabel ?itemDescription ?itemAltLabel ?email ?orcid ?url ?alt_url
WHERE {
  ?item wdt:P1 wd:Q3 .
  OPTIONAL {
    ?item wdt:P145 ?url ;
          p:P145 ?url_statement .
    OPTIONAL {
      ?url_statement pq:P202 ?alt_url .
    }
  }
  OPTIONAL {
    ?item wdt:P109 ?email .
  }
  OPTIONAL {
    ?item wdt:P106 ?orcid .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


Occupations

PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>

SELECT ?item ?itemLabel ?itemAltLabel
WHERE {
  ?item wdt:P2* wd:Q3 ;
        skos:altLabel ?itemAltLabel .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


Academic Disciplines

PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>

SELECT ?item ?itemLabel ?itemAltLabel
WHERE {
  ?item wdt:P2* wd:Q158710 ;
        skos:altLabel ?itemAltLabel .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


USGS Model Catalog

PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>

SELECT ?item ?itemLabel ?instance_of ?instance_ofLabel
?model_cat_id ?pub_date
?author ?authorLabel ?has_part ?has_partLabel
?subject_of ?subject_ofLabel
?addresses_subject ?addresses_subjectLabel
WHERE {
  ?item wdt:P219 ?model_cat_id ;
        wdt:P1 ?instance_of .
  OPTIONAL {
    ?item wdt:P7 ?pub_date .
  }
  OPTIONAL {
    ?item wdt:P102 ?author .
  }
  OPTIONAL {
    ?item wdt:P63 ?has_part .
  }
  OPTIONAL {
    ?item wdt:P218 ?subject_of .
  }
  OPTIONAL {
    ?item wdt:P94 ?addresses_subject .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


iSAID

The following queries focus on the entities and linkages in the GeoKB related to USGS staff and capacity assessment analyses.

USGS Current and Former Staff

PREFIX schema: <http://schema.org/>
PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>
PREFIX p: <https://geokb.wikibase.cloud/prop/>
PREFIX pq: <https://geokb.wikibase.cloud/prop/qualifier/>

SELECT ?item ?itemLabel ?orcid ?email ?url ?end_time ?dateModified
WHERE {
  ?item wdt:P107 wd:Q44210 ; # Employed by the USGS
        p:P107 ?emp_statement ;
        schema:dateModified ?dateModified .
  OPTIONAL {
    ?emp_statement pq:P61 ?end_time . # Any value here indicates that employment status ended at some point
  }
  OPTIONAL {
    ?item wdt:P106 ?orcid .
  }
  OPTIONAL {
    ?item wdt:P109 ?email .
  }
  OPTIONAL {
    ?item wdt:P145 ?url .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!


USGS Climate Change Science Ontology

Climate Change Science Topics

PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>

SELECT ?loi ?loiLabel ?loiDescription
?topic ?topicLabel ?topicDescription
?subject ?subjectLabel ?subjectDescription
WHERE {
  ?loi wdt:P62 wd:Q160059 . # Highest level grouping concepts representing broad scientific lines of inquiry
  ?topic wdt:P62 ?loi . # Next-level set of research topics and scientific methods directly associated with the lines of inquiry
  {
    ?subject wdt:P94* ?topic . # addresses subject
  } UNION {
    ?subject wdt:P95* ?topic . # addresses place
  } UNION {
    ?subject wdt:P208* ?topic . # uses
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!


Climate Change Science Linked Entities

PREFIX wd: <https://geokb.wikibase.cloud/entity/>
PREFIX wdt: <https://geokb.wikibase.cloud/prop/direct/>

SELECT ?loi ?loiLabel
?topic ?topicLabel
?subject ?subjectLabel
?person ?personLabel
WHERE {
  ?loi wdt:P62 wd:Q160059 .
  ?topic wdt:P62 ?loi .
  {
    ?subject wdt:P94* ?topic . # addresses subject
  } UNION {
    ?subject wdt:P95* ?topic . # addresses place
  } UNION {
    ?subject wdt:P208* ?topic . # uses
  }
  {
    ?person wdt:P203 ?topic .
  } UNION {
    ?person wdt:P203 ?subject .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 1000

Try it!