KnowWhereGraph doesn't supply data dumps, datasets, or an API for querying various types of information. Instead, each version of the graph has a SPARQL endpoint and it's left to you to construct SPARQL queries to fetch data.
KnowWhereGraph keeps old versions of the graph around so that existing users don't experience breaking changes. Each successive graph contains bug fixes and possibly new data. For these reasons, it's suggested that you use the latest.
The most recent, cutting edge graph will always be named KWG. This is almost certainly the graph that you want to query.
To find the names of the supported graphs,
-
Navigate to https://stko-kwg.geog.ucsb.edu/graphdb/
-
On the upper right side, there's a dropdown for
Repositories, shown in the image below. These are the names of each graph within the project. In the image below, theKWGrepository is selected, with options for previous versions of the graph.
The endpoint is constructed as https://stko-kwg.geog.ucsb.edu/graphdb/repositories/repository_name_here.
The endpoint to the latest graph is always https://stko-kwg.geog.ucsb.edu/graphdb/repositories/KWG. You almost certainly want to use this one.
There are a number of clients and libraries for downloading data from SPARQL endpoints. We recommend SPARQLWrapper with Python.
Example
from SPARQLWrapper import SPARQLWrapper, JSON
# Set the SPARQL endpoint and request that the response is in JSON
sparql = SPARQLWrapper("https://stko-kwg.geog.ucsb.edu/graphdb/repositories/KWG")
sparql.setReturnFormat(JSON)
query = """
PREFIX kwg-ont: <http://stko-kwg.geog.ucsb.edu/lod/ontology/>
SELECT * WHERE {
?s ?p ?o .
} LIMIT 1
"""
sparql.setQuery(query)
query_result = sparql.queryAndConvert()
print(query_result)Chances are, you'll want to do more than just select one node from the graph. To successfully obtain the data that you need you'll need to first understand the structure of the ontology, which is admittedly not a small task. Rather than becoming familiar with the entire ontology — it's recommended that you understand the local area that you're interested in. For example, view the ontology documentation for nodes of type Hazard and their connections to numerical data. For a refresher on key points of KWG's ontology, jump Here.
Reading the ontology, writing a SPARQL query, and referring back to the ontology will undoubtedly be a staple of your data acquisition workflow.
It is highly suggested that you go through the Walkthrough. This page will cover how to use GraphDB's interface rather than relying solely on the ontology to figure out how nodes are connected and how to find the data you need.
To download data
- Pick which graph you want (almost certainly
KWG) - Construct the endpoint (almost certainly
https://stko-kwg.geog.ucsb.edu/graphdb/repositories/KWG) - Choose a SPARQL interface (we suggest SPARQLWrapper)
- Figure out the local structure of the graph for the data you need (refer to the walkthrough)
- Write your SPARQL queries
- Submit the queries to the SPARQL endpoint for the data
