Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken cache generation #363

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

src/assets/data/*
# Compiled output
/dist
/tmp
Expand Down
3,200 changes: 0 additions & 3,200 deletions src/assets/data/admin_region_cache.csv

This file was deleted.

344 changes: 0 additions & 344 deletions src/assets/data/climate_division_cache.csv

This file was deleted.

3,255 changes: 0 additions & 3,255 deletions src/assets/data/fips_cache.csv

This file was deleted.

3,811 changes: 0 additions & 3,811 deletions src/assets/data/nwz_cache.csv

This file was deleted.

31,985 changes: 0 additions & 31,985 deletions src/assets/data/zipcode_cache.csv

This file was deleted.

16 changes: 9 additions & 7 deletions src/assets/scripts/fetch-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const fs = require('fs')
let baseAddress = process.argv.slice(2)[0]
let endpoint = `${process.argv.slice(2)[1]}/graphdb/repositories/KWG`

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
/**
* Sends a SPARQL request
* @param {string} query: The SPARQL query string
Expand Down Expand Up @@ -43,6 +43,7 @@ async function fetchCache(query, fileName, data = []) {
let offset_query = query + ` OFFSET ${count}`
try {
let results = await sparqlRequest(offset_query)
console.log(results)
results = await results.json()
results.results.bindings.forEach((res) => {
data.push([res.subject.value, res.value.value])
Expand Down Expand Up @@ -142,6 +143,7 @@ async function fetchAdministrativeCache(query, fileName, data = []) {
let fipsQuery = `PREFIX kwg-ont: <${baseAddress}/lod/ontology/>
SELECT DISTINCT ?subject ?value WHERE {
?subject kwg-ont:hasFIPS ?value .
?subject a kwg-ont:AdministrativeRegion_2 .
} ORDER BY ASC(?value)`
console.log('Getting FIPS')
fetchCache(fipsQuery, 'src/assets/data/fips_cache.csv')
Expand All @@ -161,7 +163,7 @@ let nwzQuery = `PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX kwg-ont: <${baseAddress}/lod/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?subject ?value where {
?subject rdf:type kwg-ont:NWZone;
?subject rdf:type kwg-ont:NationalWeatherZone;
rdfs:label ?value.
} ORDER BY ASC(?value)`
console.log('Getting NWZ')
Expand All @@ -171,9 +173,9 @@ fetchCache(nwzQuery, 'src/assets/data/nwz_cache.csv')
let climateDivisionQuery = `PREFIX kwg-ont: <http://stko-kwg.geog.ucsb.edu/lod/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?subject ?value {
?subject rdf:type kwg-ont:USClimateDivision;
?subject rdf:type kwg-ont:ClimateDivision;
rdfs:label ?label.
BIND(REPLACE(STR(?label),"US Climate Division with ID ","") AS ?value) .
BIND(REPLACE(STR(?label),"Climate Division from NOAA with ID ","") AS ?value) .
}`
console.log('Getting Climate Divisions')
fetchCache(climateDivisionQuery, 'src/assets/data/climate_division_cache.csv')
Expand All @@ -184,14 +186,14 @@ PREFIX kwgr: <http://stko-kwg.geog.ucsb.edu/lod/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?county ?county_label ?state ?state_label ?usa ?usa_label WHERE {
?county rdf:type kwg-ont:AdministrativeRegion_3 .
?county rdf:type kwg-ont:AdministrativeRegion_2 .
?county kwg-ont:sfWithin ?state .
?state kwg-ont:sfWithin ?usa.
values ?usa {kwgr:Earth.North_America.United_States.USA}
values ?usa {kwgr:administrativeRegion.USA}
?county rdfs:label ?county_label .
?state rdfs:label ?state_label .
?usa rdfs:label ?usa_label .
} ORDER BY ?usa_label ?state_label ?county_label`
} LIMIT 50 `
console.log('Getting Administrative Regions')
fetchAdministrativeCache(
adminRegionQuery,
Expand Down
Loading