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

Use deo ontology for searching for hazards #374

Merged
merged 4 commits into from
Sep 6, 2024
Merged
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
31 changes: 14 additions & 17 deletions src/app/services/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class QueryService {
'http://www.ontotext.com/connectors/elasticsearch/instance#',
iospress: 'http://ld.iospress.nl/rdf/ontology/',
usgs: 'http://gnis-ld.org/lod/usgs/ontology/',
deo: 'http://knowwheregraph/ontology/deo/',
}
// A string representation of the prefixes
prefixesCombined: string = ''
Expand Down Expand Up @@ -69,7 +70,6 @@ export class QueryService {
}).catch((error) => {
console.error('There was an error while running a query: ', error)
})

// Status codes need to be manually checked here
if (d_res.status !== 200) {
console.warn('There was an error running the query', query, d_res)
Expand Down Expand Up @@ -286,12 +286,10 @@ export class QueryService {
* @returns A portion of a SPARQL query
*/
getHazardsQueryBody() {
let query = `?entity rdf:type ?type;
let query = `?entity rdf:type deo:Hazard;
rdfs:label ?label;
kwg-ont:hasImpact|sosa:isFeatureOfInterestOf ?observationCollection.
?type rdfs:subClassOf ?superClass;
rdfs:label ?typeLabel.
values ?superClass {kwg-ont:Hazard kwg-ont:Fire}
`
return query
}
Expand Down Expand Up @@ -424,7 +422,7 @@ export class QueryService {
* @param offset The results offset
* @returns A string of SPARQL without the SELECT predicate
*/
async getPlaces(placesFacets, limit, offset) {
async getPlaces(placesFacets, limit: number, offset: number) {
let formattedResults: Array<any> = []
let placeQuery = `SELECT DISTINCT ?entity ?label ?quantifiedName ?type ?typeLabel where {`

Expand Down Expand Up @@ -712,11 +710,11 @@ export class QueryService {
.join(' ')

placeSearchQuery += `
?gnis_entity a ?gnisPlaceType;
geo:hasGeometry ?gnisGeo;
kwg-ont:sfWithin ?s2Cell.
?entity kwg-ont:sfWithin ?s2Cell .
?s2Cell rdf:type kwg-ont:S2Cell_Level13;
kwg-ont:spatialRelation ?gnisEntity.
?gnisEntity kwg-ont:sfWithin ?s2cellGNIS;
rdf:type ?gnisPlaceType.
values ?gnisPlaceType {${gnisTypeArray}}
`
if (placeEntities.length > 0) {
Expand Down Expand Up @@ -800,17 +798,17 @@ export class QueryService {

//Build the full query
hazardQuery += `
?entity rdf:type ?type;
?entity rdf:type ?type ;
rdfs:label ?label;
kwg-ont:hasTemporalScope|sosa:isFeatureOfInterestOf/sosa:phenomenonTime ?time.
optional
{
?entity geo:hasGeometry/geo:asWKT ?wkt.
}
?type rdfs:subClassOf kwg-ont:Hazard.
?entity kwg-ont:sfWithin ?place.

?time time:inXSDDateTime|time:inXSDDate ?startTimeLabel;
time:inXSDDateTime|time:inXSDDate ?endTimeLabel.

${typeQuery}
${placeSearchQuery}
${dateQuery}
Expand All @@ -822,7 +820,6 @@ export class QueryService {
if (hazardFacets['keyword'] && hazardFacets['keyword'] != '') {
hazardQuery += ` ORDER BY desc(?score)`
}

let queryResults: Response | boolean = await this.query(
hazardQuery + ` LIMIT ` + limit + ` OFFSET ` + offset
)
Expand Down Expand Up @@ -993,7 +990,7 @@ export class QueryService {
*/
getTopLevelAdministrativeRegions() {
let query = `select ?country ?country_label where {
values ?country {kwgr:Earth.North_America.United_States.USA}
values ?country {kwgr:administrativeRegion.USA}
?country rdfs:label ?country_label .
}`
let headers = this.getRequestHeaders('KE_08')
Expand All @@ -1008,8 +1005,8 @@ export class QueryService {
*/
getStateAdministrativeRegions() {
let query = `SELECT DISTINCT ?state ?state_label where {
?state kwg-ont:sfWithin kwgr:Earth.North_America.United_States.USA .
?state a kwg-ont:AdministrativeRegion_2 .
?state kwg-ont:sfWithin kwgr:administrativeRegion.USA .
?state a kwg-ont:AdministrativeRegion_1 .
?state rdfs:label ?state_label .
} ORDER BY ?state_label`
let headers = this.getRequestHeaders('KE_09')
Expand All @@ -1029,7 +1026,7 @@ export class QueryService {
?county kwg-ont:sfWithin <` +
stateURI +
`> .
?county a kwg-ont:AdministrativeRegion_3 .
?county a kwg-ont:AdministrativeRegion_2 .
?county rdfs:label ?county_label .
} ORDER BY ?state_label`
let headers = this.getRequestHeaders('KE_10')
Expand All @@ -1053,7 +1050,7 @@ export class QueryService {
*/
getTopLevelHazards() {
let query = `SELECT DISTINCT ?hazard ?hazard_label (COUNT(DISTINCT ?child) as ?count) where {
?hazard rdfs:subClassOf kwg-ont:Hazard .
?hazard rdfs:subClassOf deo:Hazard .
?hazard rdfs:label ?hazard_label .
OPTIONAL {
?child rdfs:subClassOf ?hazard .
Expand Down
Loading