diff --git a/docs/DEBUGGING.md b/docs/DEBUGGING.md index cc84b92..c2c1fc7 100644 --- a/docs/DEBUGGING.md +++ b/docs/DEBUGGING.md @@ -731,3 +731,49 @@ out-of-memory, one reporting only 2.9 MB available, while a full pipeline run of mine was hammering the same endpoint. Re-run alone, they failed differently, as planning timeouts. The header of `query-matrix.mts` warns about this; it applies to ad-hoc curl measurements just as much. + +## 2026-09-20: Adding an industry filter broke a question that worked (FIXED) + +Found while answering "what does this result really mean" about the York County +map. The unfiltered question, facilities within 5 km upstream from PFOS +detections, returns 418 facilities in 3s. It also returns dentists and schools, +because block A carries no industry filter and "facility" means anything with a +NAICS code. The obvious next step is to filter block A to PFAS source +categories. Doing that returned nothing: 429, `Operation timed out. Last +operation: Query planning`, on both projections. + +**Root cause, one level up from the 2026-09-20 seed-side entry above.** +`sideIsConstrained` treated a region, an entity filter and an IRI pin as the +same thing. An industry filter made the anchor count as constrained, so the +reorder stopped firing, so the query seeded from block A, which with a filter +and no region means every facility in that industry across the country. + +Isolated by varying one thing at a time, all at 5 km, York, detections only: + +| Block A | Result | +| --- | --- | +| no filter, no region | works, 418 facilities, 3s | +| 1 code, no region | 429, query planning | +| 21 codes, region Maine | 429 Cartesian Product, then 500 at 728 MB | +| 21 codes, region York | 500 at 728 MB | +| 1 code, region York | works, 21 facilities, 13s | + +The pattern is that block A had to be *small*, not merely filtered, and only a +region made it small. + +**The fix** replaces the boolean with a rank: IRI pin 3, region 2, entity filter +1, nothing 0, lead with the higher, ties keep anchor-first. Only questions with +both sides constrained at different levels change plan. See +`docs/QUERY-MATRIX.md` Part 11 for the measurements. + +**Long selections: measure before blaming the clause.** The first version of +this entry said selections beyond about ten codes still fail. Re-measured after +the ranking landed, that is wrong. 21 codes answers at 5 km (101 facilities, +13s; 84 samples, 23s) and only fails unbounded (500, 430 MB). Code count is a +cost on the closure, which a distance bound already caps. + +The suspected culprit was cleared too. `fio:subcodeOf` is materialised +transitively, so `?ic fio:subcodeOf? ?sel` is an exact rewrite of +`FILTER(?ic = ?sel || EXISTS { ?ic fio:subcodeOf ?sel })`. Measured: 13s with +the FILTER, query-planning timeout with the path. The FILTER is the fast form +here; do not "optimise" it. diff --git a/docs/QUERY-MATRIX.md b/docs/QUERY-MATRIX.md index 1445292..d69deb5 100644 --- a/docs/QUERY-MATRIX.md +++ b/docs/QUERY-MATRIX.md @@ -907,3 +907,77 @@ This is what ignoring it looks like in practice: a plausible number, in the right direction, that attributes a cache effect to a code change. The pre-fix engine was re-run warm into `2026-09-20-raw-e84a11f.csv`, and that file, not the cold one, is the before-half of 10.2. The cold sweep carries a `.note` saying so. + +## Part 11: Narrowness is a ranking, not a boolean (2026-09-20) + +Part 10 made the distance bound work when block A is left open. Putting an +industry filter on block A broke it again, and for a reason one level up from +the seed side. + +`sideIsConstrained` answered yes for a region, a filter or an IRI pin alike. An +industry filter therefore made the anchor "constrained", the reorder stopped +firing, and the query seeded from block A again. Only now block A meant every +facility in that industry nationwide rather than every facility in the graph, +which is smaller and still far too large to seed an aggregate from. + +### 11.1 What it cost + +"What facilities are within 5 km upstream from PFOS samples", York County, +detections only, block A carrying no region: + +| Block A | Before | After | +| --- | --- | --- | +| no filter | 418 facilities, 3s | unchanged | +| 1 code, unbounded | 429, query planning | 35 facilities, 16s | +| 1 code, 5 km | 429, query planning | 22 facilities, 8s | +| 8 codes, 5 km | 429, query planning | **88 facilities, 3s** | +| 8 codes, unbounded | 429, query planning | 192 facilities, 15s | + +Adding a filter to a working question made it fail. That is the shape of the +report: a user narrowing a result set that was too broad, and getting nothing. + +### 11.2 The rank + + 3 an IRI pin. The executor chose this slice; re-seeding discards it. + 2 a region. Bounded by geography at any level, and indexed for. + 1 an entity filter only. Selective in kind, unbounded in extent. + 0 nothing. + +The body leads with the higher rank, and ties keep the anchor-first order. So +this only changes questions where both sides are constrained at *different* +levels; everything where one side was constrained and the other was not keeps +the plan it had. Of the 375 shapes in `scripts/__snapshots__/query-shapes.txt`, +2 move, both variants with a region on one side and a bare filter on the other. + +### 11.3 What it does not fix + +**Long industry selections fail only without a bound.** An earlier draft of +this part said 21 codes fails outright. Re-measured after the ranking landed, +that is wrong: the code count only matters when the trace is unbounded. + +| Codes | 5 km | Unbounded | +| ---: | --- | --- | +| 1 | 22 facilities, 8s | 35 facilities, 16s | +| 8 | 88 facilities, 3s | 192 facilities, 15s | +| 21 | 101 facilities, 13s | 500, out of memory at 430 MB | + +Which is what a bound is for: the unbounded form walks the whole closure from +every matched facility, so more codes means more seeds and more work, while the +bounded form caps it. A long selection is a reason to set a distance, not a +reason to shorten the list. + +**A rewrite of the industry clause was tried and rejected.** The obvious suspect +was `FILTER(?ic = ?sel || EXISTS { ?ic fio:subcodeOf ?sel })`, evaluated per +selected code and duplicated inside the bounded aggregate. `fio:subcodeOf` is +materialised transitively (`325110` is a direct subcode of `32`, `325` and +`3251`), so `?ic fio:subcodeOf? ?sel` says exactly the same thing as a +zero-or-one path. It is slower, not faster: the 21-code bounded query answers in +13s with the FILTER and times out in query planning with the path. Leave the +clause alone. + +**One dashboard question changes plan.** `samples-downstream-waste-indiana` +scopes samples to Indiana and filters block C to NAICS 5622 with no region, so +its anchor is nationwide and its target is one state. Both orders were measured +before accepting the change: identical answers, 136 samples and 415 facilities +either way, and the reordered form is no slower at 13s and 2s against 16s and +3s. diff --git a/docs/changelog/2026-W38.md b/docs/changelog/2026-W38.md index 4cef85e..0383502 100644 --- a/docs/changelog/2026-W38.md +++ b/docs/changelog/2026-W38.md @@ -177,3 +177,16 @@ **Known limit, recorded so it is not discovered later:** the snapshot drives everything through `planPipeline`, so it covers shapes a user can ask for and is blind to builder arguments the planner never produces. A reordering of the anchor-seeded `upstream` branch of `boundedTrace` passes all seven checks. The guarantee is "no reachable shape moved unintentionally", not "no emitted SPARQL moved". *Files:* `scripts/query-matrix.mts`, `scripts/check-query-snapshots.mts` (new), `scripts/__snapshots__/query-shapes.txt` (new), `package.json`, `.github/workflows/checks.yml` + +17. **Fixed: Narrowing a Question by Industry Made It Fail** (2026-09-20) + Found immediately after entry 15, by doing the obvious next thing with the map it fixed. "What facilities are within 5 km upstream from PFOS samples in York County" answers in 3s and returns 418 facilities, of which 261 distinct industries include dentists, schools and hospitals, because block A carries no industry filter and "facility" means anything with a NAICS code. Filtering block A to PFAS source categories returned nothing at all: a 30s timeout in query planning, on both projections. + + The cause sits one level above entry 15. `sideIsConstrained` answered yes for a region, an entity filter or an IRI pin alike, so an industry filter made the anchor count as constrained, the reorder stopped firing, and the query seeded from block A again. With a filter and no region that means every facility in that industry nationwide. The comment two lines above the predicate already read "narrowed is not small"; the predicate did not act on its own warning. + + It now returns a rank instead: an IRI pin 3, a region 2, an entity filter 1, nothing 0. The body leads with the higher, and ties keep the anchor-first order, so only questions with both sides constrained at *different* levels change plan. Of the 375 shapes in the query snapshot, 2 move. + + Measured with block A carrying no region: one code goes from a planning timeout to **35 facilities in 16s** unbounded and **22 in 8s** at 5 km; eight codes go from a planning timeout to **88 facilities in 3s** at 5 km. The filtered map is the useful one, 88 candidates rather than 418, with the dentists gone and sewage treatment, dry cleaners, boatyards, airports and petroleum terminals at the top. + + **One limit, and one that turned out not to exist.** A long industry selection fails only without a distance bound: 21 codes answers at 5 km (101 facilities, 13s) and runs out of memory unbounded, because the unbounded form walks the whole closure from every matched facility. That is a reason to set a distance, not to shorten the list. The clause first blamed for it, `FILTER(?ic = ?sel || EXISTS { ?ic fio:subcodeOf ?sel })`, was cleared by measurement: `fio:subcodeOf` is materialised transitively, so a zero-or-one path is an exact rewrite, and it is slower, 13s against a planning timeout. And one dashboard question changes plan, `samples-downstream-waste-indiana`, whose anchor is NAICS 5622 with no region against samples scoped to Indiana. Both orders were run before accepting it: identical answers, 136 samples and 415 facilities either way, reordered no slower. + + *Files:* `src/engine/templates/fusedQueries.ts`, `scripts/check-query-joins.mts` (30 new assertions), `scripts/__snapshots__/query-shapes.txt`, `docs/QUERY-MATRIX.md` (Part 11), `docs/DEBUGGING.md` diff --git a/scripts/__snapshots__/query-shapes.txt b/scripts/__snapshots__/query-shapes.txt index 731b554..69cae52 100644 --- a/scripts/__snapshots__/query-shapes.txt +++ b/scripts/__snapshots__/query-shapes.txt @@ -2437,8 +2437,8 @@ HYDRATE_TARGET_BY_IRI [federation] 86920d0a3b5f HYDRATE_ANCHOR_BY_IRI [federation] ec6ed949be4d GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa ## VARIANT: sample filters -FIND_TARGET_IRIS [federation] 7b1c835798e7 -FIND_ANCHOR_IRIS [federation] b4f373f3b10c +FIND_TARGET_IRIS [federation] 3ae8e5cca3a7 +FIND_ANCHOR_IRIS [federation] d9a6c533c502 GET_FLOWLINE_GEOMETRIES [federation] 10a063aa6d84 HYDRATE_TARGET_BY_IRI [federation] 225ebb47d1ba HYDRATE_ANCHOR_BY_IRI [federation] f15a49a11b96 @@ -2450,8 +2450,8 @@ HYDRATE_TARGET_BY_IRI [federation] 9498222e580a HYDRATE_ANCHOR_BY_IRI [hydrologykg] 025d57e51b2a GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa ## VARIANT: stream ftype filter as target -FIND_TARGET_IRIS [federation] f484f51fbc63 -FIND_ANCHOR_IRIS [federation] 3b68e8810ae7 +FIND_TARGET_IRIS [federation] a8825c1ad3c8 +FIND_ANCHOR_IRIS [federation] 744604955bf5 HYDRATE_TARGET_BY_IRI [federation] 86920d0a3b5f HYDRATE_ANCHOR_BY_IRI [hydrologykg] 3da8119633c2 GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa @@ -2605,7 +2605,7 @@ GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa 3a2bb0cd96e0 SELECT DISTINCT (?wellA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?upstream_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?upstream_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?upstream_flowline WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . } } ?upstream_flowline hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?upstream_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd hyf:downstreamFlowPath? ?ds_flowline . } } ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } 3a5de06aa701 SELECT DISTINCT (?streamC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?waterBodyA . ?waterBodyA rdf:type hyf:HY_WaterBody . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . BIND(?ds_flowline AS ?streamC) } 3ac013fb1120 SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?upstream_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?upstream_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?upstream_flowline WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . } } ?upstream_flowline hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?upstream_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd hyf:downstreamFlowPath? ?ds_flowline . } } ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . } -3b68e8810ae7 SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?streamA nhdplusv2:hasFTYPE ?flFtypeA . VALUES ?flFtypeA { "460" } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . } +3ae8e5cca3a7 SELECT DISTINCT (?spC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC coso:observedAtSamplePoint ?spC . ?observationC coso:ofDSSToxSubstance ?substanceC . ?observationC coso:analyzedSample ?sampleC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?observationC coso:hasResult ?resultC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?resultC coso:measurementUnit ?unitC . VALUES ?substanceC { } VALUES ?matTypeC { } BIND(xsd:decimal(?numericResultC) as ?numericValueC) FILTER(BOUND(?numericValueC) && ?unitC = && ?numericValueC >= 4 && ?numericValueC <= 100) ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . VALUES ?selectedIndustryA { naics:NAICS-562212 } FILTER(?industryCodeA = ?selectedIndustryA || EXISTS { ?industryCodeA fio:subcodeOf ?selectedIndustryA }) } 3b88da2bc6f2 SELECT DISTINCT ?waterBody ?wbWKT ?wbName ?ftype ?comid ?reachcode ?fcode ?s2cell WHERE { VALUES ?waterBody { } ?s2cell spatial:connectedTo ?waterBody ; rdf:type kwg-ont:S2Cell_Level13 . ?waterBody rdf:type hyf:HY_WaterBody ; geo:hasGeometry/geo:asWKT ?wbWKT . OPTIONAL { ?waterBody schema:name ?wbName . } OPTIONAL { ?waterBody nhdplusv2:hasFTYPE ?ftype . } OPTIONAL { ?waterBody nhdplusv2:hasCOMID ?comid . } OPTIONAL { ?waterBody nhdplusv2:hasReachCode ?reachcode . } OPTIONAL { ?waterBody nhdplusv2:hasFCODE ?fcode . } } 3bcbbc61caae SELECT DISTINCT (?streamC AS ?iri) WHERE { ?ds_flowline rdf:type hyf:HY_FlowPath . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . BIND(?ds_flowline AS ?streamC) ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?spA rdf:type coso:SamplePoint ; spatial:connectedTo ?s2anchor . } 3bce92acebce SELECT DISTINCT (?wellA AS ?well) ?wellWKT (?s2anchor AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?wellA geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellA rdfs:label ?wellName . } OPTIONAL { ?wellA me_mgs:hasUse ?meUse . } OPTIONAL { ?wellA me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellA me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellA me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellA il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellA il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellA il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellA il_isgs:wellYield/qudt:numericValue ?ilYield . } } @@ -2735,6 +2735,7 @@ GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa 73934d7aae0d SELECT DISTINCT (?waterBodyA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?waterBodyA . ?waterBodyA rdf:type hyf:HY_WaterBody . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } 73c37175d3a3 SELECT DISTINCT (?wellC AS ?well) ?wellWKT (?s2target AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?wellC geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellC rdfs:label ?wellName . } OPTIONAL { ?wellC me_mgs:hasUse ?meUse . } OPTIONAL { ?wellC me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellC me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellC me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellC il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellC il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellC il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellC il_isgs:wellYield/qudt:numericValue ?ilYield . } } 74340ac75507 SELECT DISTINCT (?wellA AS ?well) ?wellWKT (?s2anchor AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?upstream_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?upstream_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?upstream_flowline WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . } } ?upstream_flowline hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?upstream_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd hyf:downstreamFlowPath? ?ds_flowline . } } ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?wellA geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellA rdfs:label ?wellName . } OPTIONAL { ?wellA me_mgs:hasUse ?meUse . } OPTIONAL { ?wellA me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellA me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellA me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellA il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellA il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellA il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellA il_isgs:wellYield/qudt:numericValue ?ilYield . } } +744604955bf5 SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?streamA nhdplusv2:hasFTYPE ?flFtypeA . VALUES ?flFtypeA { "460" } } 748a8ca41a32 SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . } 74c3d0bb8bf8 SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(10)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . } 74f6726cb460 SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?aquiferC . ?aquiferC rdf:type gwml2:GW_Aquifer . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?aquiferC . ?aquiferC rdf:type gwml2:GW_Aquifer . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . } @@ -2754,7 +2755,6 @@ GET_REGION_BOUNDARIES [spatialkg] d52aaecf97fa 79e0bd042512 SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?streamC . ?streamC rdf:type hyf:HY_FlowPath . } 7aa05f4cf432 SELECT DISTINCT (?spA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spA rdf:type coso:SamplePoint ; spatial:connectedTo ?s2anchor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . } 7ab11f2c9448 SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?upstream_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?upstream_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?upstream_flowline WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . } } ?upstream_flowline hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?upstream_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd hyf:downstreamFlowPath? ?ds_flowline . } } ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } -7b1c835798e7 SELECT DISTINCT (?spC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . VALUES ?selectedIndustryA { naics:NAICS-562212 } FILTER(?industryCodeA = ?selectedIndustryA || EXISTS { ?industryCodeA fio:subcodeOf ?selectedIndustryA }) ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC coso:observedAtSamplePoint ?spC . ?observationC coso:ofDSSToxSubstance ?substanceC . ?observationC coso:analyzedSample ?sampleC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?observationC coso:hasResult ?resultC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?resultC coso:measurementUnit ?unitC . VALUES ?substanceC { } VALUES ?matTypeC { } BIND(xsd:decimal(?numericResultC) as ?numericValueC) FILTER(BOUND(?numericValueC) && ?unitC = && ?numericValueC >= 4 && ?numericValueC <= 100) } 7b5980388f2c SELECT DISTINCT ?flowline ?flowlineWKT ?fl_type ?streamName WHERE { { SELECT DISTINCT ?flowline WHERE { { SELECT DISTINCT ?s2cellus WHERE { VALUES ?wellA { } ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2cellus . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2cellus ; hyf:downstreamFlowPathTC ?flowline . } } { SELECT DISTINCT ?flowline WHERE { { SELECT DISTINCT ?s2celltarget WHERE { VALUES ?waterBodyC { } ?s2celltarget rdf:type kwg-ont:S2Cell_Level13 . ?s2celltarget spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } } ?_flTarget spatial:connectedTo ?s2celltarget . ?flowline hyf:downstreamFlowPathTC ?_flTarget . } } ?flowline geo:hasGeometry/geo:asWKT ?flowlineWKT ; nhdplusv2:hasFTYPE ?fl_type . OPTIONAL { ?flowline rdfs:label ?streamName } } 7b8a451b6ce6 SELECT DISTINCT ?facility ?facWKT ?facilityName ?industryCode ?industryName ?s2cell WHERE { VALUES ?facility { } ?s2cell kwg-ont:sfContains ?facility ; rdf:type kwg-ont:S2Cell_Level13 . ?facility fio:ofIndustry ?industryCode ; geo:hasGeometry/geo:asWKT ?facWKT ; rdfs:label ?facilityName . ?industryCode a naics:NAICS-IndustryCode ; rdfs:label ?industryName . } 7c9c4702ede4 SELECT DISTINCT (?aquiferA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?streamC . ?streamC rdf:type hyf:HY_FlowPath . } @@ -2865,6 +2865,7 @@ a7b4475fa918 SELECT DISTINCT (?facilityC AS ?iri) WHERE { ?s2anchor rdf:type kwg a7ba4bf786b6 SELECT DISTINCT ?flowline ?flowlineWKT ?fl_type ?streamName ?path_length WHERE { { SELECT ?flowline (MIN(?_ptotal) AS ?path_length) WHERE { { SELECT ?_flSeed ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?_flSeed ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?_flSeed WHERE { { SELECT DISTINCT ?s2cellus WHERE { VALUES ?aquiferA { } ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2cellus . } } ?_flSeed rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2cellus . } } ?_flSeed hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?_flSeed ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_endLen . ?_flEnd hyf:downstreamFlowPath? ?flowline . BIND(IF(?flowline = ?_flEnd, 0.0, ?_endLen) AS ?_extra) BIND(xsd:float(?_plen) + xsd:float(?_extra) AS ?_ptotal) } GROUP BY ?flowline } { SELECT DISTINCT ?flowline WHERE { { SELECT DISTINCT ?s2celltarget WHERE { VALUES ?spC { } ?s2celltarget rdf:type kwg-ont:S2Cell_Level13 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2celltarget . } } ?_flTarget spatial:connectedTo ?s2celltarget . ?flowline hyf:downstreamFlowPathTC ?_flTarget . } } ?flowline geo:hasGeometry/geo:asWKT ?flowlineWKT ; nhdplusv2:hasFTYPE ?fl_type . OPTIONAL { ?flowline rdfs:label ?streamName } } a7c3f2ccff0c SELECT DISTINCT (?facilityC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?upstream_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?upstream_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?upstream_flowline WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . } } ?upstream_flowline hyf:downstreamFlowPathTC ?_flMid . ?_flMid hyf:downstreamFlowPathTC ?_flEnd . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?upstream_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?_flEnd hyf:downstreamFlowPath? ?ds_flowline . } } ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . } a7e872d51a0f SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . } +a8825c1ad3c8 SELECT DISTINCT (?spC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?streamA nhdplusv2:hasFTYPE ?flFtypeA . VALUES ?flFtypeA { "460" } } a963e5be882c SELECT DISTINCT (?aquiferC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?aquiferC . ?aquiferC rdf:type gwml2:GW_Aquifer . } a99936a88d0b SELECT DISTINCT (?aquiferA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . } aa5fdb59ec6f SELECT DISTINCT (?wellC AS ?well) ?wellWKT (?s2target AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?wellC geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellC rdfs:label ?wellName . } OPTIONAL { ?wellC me_mgs:hasUse ?meUse . } OPTIONAL { ?wellC me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellC me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellC me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellC il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellC il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellC il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellC il_isgs:wellYield/qudt:numericValue ?ilYield . } } @@ -2892,7 +2893,6 @@ b4008588edaf SELECT DISTINCT (?streamC AS ?iri) WHERE { ?ds_flowline rdf:type hy b43c08af1964 SELECT DISTINCT (?facilityC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . } b44db2e80018 SELECT DISTINCT (?wellA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . } b45c05b3136a SELECT DISTINCT (?aquiferC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?spA rdf:type coso:SamplePoint ; spatial:connectedTo ?s2anchor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?aquiferC . ?aquiferC rdf:type gwml2:GW_Aquifer . } -b4f373f3b10c SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . VALUES ?selectedIndustryA { naics:NAICS-562212 } FILTER(?industryCodeA = ?selectedIndustryA || EXISTS { ?industryCodeA fio:subcodeOf ?selectedIndustryA }) ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC coso:observedAtSamplePoint ?spC . ?observationC coso:ofDSSToxSubstance ?substanceC . ?observationC coso:analyzedSample ?sampleC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?observationC coso:hasResult ?resultC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?resultC coso:measurementUnit ?unitC . VALUES ?substanceC { } VALUES ?matTypeC { } BIND(xsd:decimal(?numericResultC) as ?numericValueC) FILTER(BOUND(?numericValueC) && ?unitC = && ?numericValueC >= 4 && ?numericValueC <= 100) } b57ca9e8c32e SELECT DISTINCT (?streamA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . } b58c8c35f1eb SELECT DISTINCT (?aquiferA AS ?iri) WHERE { ?ds_flowline rdf:type hyf:HY_FlowPath . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . BIND(?ds_flowline AS ?streamC) { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?ds_flowline rdf:type hyf:HY_FlowPath . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . BIND(?ds_flowline AS ?streamC) } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . } b679bd47f6b1 SELECT DISTINCT (?wellC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?waterBodyA . ?waterBodyA rdf:type hyf:HY_WaterBody . } @@ -2971,6 +2971,7 @@ d7635cc00d76 SELECT DISTINCT ?flowline ?flowlineWKT ?fl_type ?streamName ?path_l d7ee9691da5b SELECT DISTINCT ?flowline ?flowlineWKT ?fl_type ?streamName WHERE { { SELECT DISTINCT ?flowline WHERE { { SELECT DISTINCT ?s2cellus WHERE { VALUES ?waterBodyA { } ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?waterBodyA . ?waterBodyA rdf:type hyf:HY_WaterBody . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2cellus . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2cellus ; hyf:downstreamFlowPathTC ?flowline . } } { SELECT DISTINCT ?flowline WHERE { { SELECT DISTINCT ?s2celltarget WHERE { VALUES ?spC { } ?s2celltarget rdf:type kwg-ont:S2Cell_Level13 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2celltarget . } } ?_flTarget spatial:connectedTo ?s2celltarget . ?flowline hyf:downstreamFlowPathTC ?_flTarget . } } ?flowline geo:hasGeometry/geo:asWKT ?flowlineWKT ; nhdplusv2:hasFTYPE ?fl_type . OPTIONAL { ?flowline rdfs:label ?streamName } } d913d9d71840 SELECT DISTINCT (?waterBodyC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } d98072521790 SELECT DISTINCT (?waterBodyC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . } +d9a6c533c502 SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC coso:observedAtSamplePoint ?spC . ?observationC coso:ofDSSToxSubstance ?substanceC . ?observationC coso:analyzedSample ?sampleC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?observationC coso:hasResult ?resultC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?resultC coso:measurementUnit ?unitC . VALUES ?substanceC { } VALUES ?matTypeC { } BIND(xsd:decimal(?numericResultC) as ?numericValueC) FILTER(BOUND(?numericValueC) && ?unitC = && ?numericValueC >= 4 && ?numericValueC <= 100) ?s2target spatial:connectedTo ?ds_flowline . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . VALUES ?selectedIndustryA { naics:NAICS-562212 } FILTER(?industryCodeA = ?selectedIndustryA || EXISTS { ?industryCodeA fio:subcodeOf ?selectedIndustryA }) } da7010fa25fd SELECT DISTINCT (?wellA AS ?well) ?wellWKT (?s2anchor AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC rdf:type coso:ContaminantObservation ; coso:observedAtSamplePoint ?spC ; coso:ofDSSToxSubstance ?substanceC ; coso:analyzedSample ?sampleC ; coso:hasResult ?resultC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?matTypeC rdfs:label ?matTypeLabelC . ?resultC coso:measurementUnit ?unitC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . ?observationC rdf:type coso:ContaminantObservation ; coso:observedAtSamplePoint ?spC ; coso:ofDSSToxSubstance ?substanceC ; coso:analyzedSample ?sampleC ; coso:hasResult ?resultC . ?sampleC coso:sampleOfMaterialType ?matTypeC . ?matTypeC rdfs:label ?matTypeLabelC . ?resultC coso:measurementUnit ?unitC . OPTIONAL { ?resultC qudt:quantityValue/qudt:numericValue ?numericResultC } OPTIONAL { ?resultC qudt:quantityValue ?_qvC . ?_qvC rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectC) } BIND(COALESCE(STR(?numericResultC), IF(BOUND(?nonDetectC), "non-detect", "non-quantified")) AS ?result_valueC) ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?wellA geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellA rdfs:label ?wellName . } OPTIONAL { ?wellA me_mgs:hasUse ?meUse . } OPTIONAL { ?wellA me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellA me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellA me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellA il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellA il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellA il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellA il_isgs:wellYield/qudt:numericValue ?ilYield . } } da77e9a226ae SELECT DISTINCT (?aquiferA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?aquiferA . ?aquiferA rdf:type gwml2:GW_Aquifer . } daae4206ce0f SELECT DISTINCT (?streamC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?streamC . ?streamC rdf:type hyf:HY_FlowPath . } @@ -3033,7 +3034,6 @@ f1abbefd32dd SELECT DISTINCT (?wellC AS ?well) ?wellWKT (?s2target AS ?s2cell) ? f1e4ac3d1adc SELECT DISTINCT (?facilityA AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . } f2161e75506a SELECT DISTINCT (?wellC AS ?well) ?wellWKT (?s2target AS ?s2cell) ?wellName ?meUse ?meWellType ?meDepth ?meOverburden ?ilOwner ?ilDepth ?ilPurpose ?ilYield WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?spA rdf:type coso:SamplePoint ; spatial:connectedTo ?s2anchor . ?observationA rdf:type coso:ContaminantObservation ; coso:observedAtSamplePoint ?spA ; coso:ofDSSToxSubstance ?substanceA ; coso:analyzedSample ?sampleA ; coso:hasResult ?resultA . ?sampleA coso:sampleOfMaterialType ?matTypeA . ?matTypeA rdfs:label ?matTypeLabelA . ?resultA coso:measurementUnit ?unitA . OPTIONAL { ?resultA qudt:quantityValue/qudt:numericValue ?numericResultA } OPTIONAL { ?resultA qudt:quantityValue ?_qvA . ?_qvA rdf:type coso:NonDetectQuantityValue . BIND(true AS ?nonDetectA) } BIND(COALESCE(STR(?numericResultA), IF(BOUND(?nonDetectA), "non-detect", "non-quantified")) AS ?result_valueA) ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } ?wellC geo:hasGeometry/geo:asWKT ?wellWKT . OPTIONAL { ?wellC rdfs:label ?wellName . } OPTIONAL { ?wellC me_mgs:hasUse ?meUse . } OPTIONAL { ?wellC me_mgs:ofWellType ?meWellType . } OPTIONAL { ?wellC me_mgs:wellDepth/qudt:numericValue ?meDepth . } OPTIONAL { ?wellC me_mgs:wellOverburden/qudt:numericValue ?meOverburden . } OPTIONAL { ?wellC il_isgs:hasOwner ?ilOwner . } OPTIONAL { ?wellC il_isgs:wellDepth/qudt:numericValue ?ilDepth . } OPTIONAL { ?wellC il_isgs:wellPurpose ?ilPurpose . } OPTIONAL { ?wellC il_isgs:wellYield/qudt:numericValue ?ilYield . } } f2ec010e4080 SELECT DISTINCT (?waterBodyA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?waterBodyA . ?waterBodyA rdf:type hyf:HY_WaterBody . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target kwg-ont:sfContains ?facilityC . ?facilityC fio:ofIndustry ?industryCodeC . ?industryCodeC a naics:NAICS-IndustryCode . } -f484f51fbc63 SELECT DISTINCT (?spC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?streamA nhdplusv2:hasFTYPE ?flFtypeA . VALUES ?flFtypeA { "460" } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?spC rdf:type coso:SamplePoint ; spatial:connectedTo ?s2target . } f560ebd6282b SELECT DISTINCT (?waterBodyC AS ?iri) WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?s2target spatial:connectedTo ?ds_flowline . { SELECT DISTINCT ?upstream_flowline ?ds_flowline WHERE { { SELECT ?ds_flowline ?_flEnd (SUM(?_flLen) AS ?_plen) WHERE { { SELECT ?ds_flowline ?_flMid ?_flEnd WHERE { { SELECT DISTINCT ?ds_flowline WHERE { ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . ?s2target spatial:connectedTo ?ds_flowline . } } ?_flMid hyf:downstreamFlowPathTC ?ds_flowline . ?_flEnd hyf:downstreamFlowPathTC ?_flMid . } } ?_flMid nhdplusv2:hasFlowPathLength/qudt:quantityValue/qudt:numericValue ?_flLen . } GROUP BY ?ds_flowline ?_flEnd } FILTER (xsd:float(?_plen) < xsd:float(30)) ?upstream_flowline hyf:downstreamFlowPath? ?_flEnd . } } ?upstream_flowline rdf:type hyf:HY_FlowPath ; spatial:connectedTo ?s2neighbor . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor kwg-ont:sfContains ?facilityA . ?facilityA fio:ofIndustry ?industryCodeA . ?industryCodeA a naics:NAICS-IndustryCode . } f56b87fc7251 SELECT DISTINCT (?wellC AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2anchor spatial:connectedTo ?streamA . ?streamA rdf:type hyf:HY_FlowPath . ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2neighbor . ?s2neighbor spatial:connectedTo ?upstream_flowline . ?upstream_flowline rdf:type hyf:HY_FlowPath . ?upstream_flowline hyf:downstreamFlowPathTC ?ds_flowline . ?s2target spatial:connectedTo ?ds_flowline ; rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo ?wellC . { ?wellC rdf:type il_isgs:ISGS-Well } UNION { ?wellC rdf:type me_mgs:MGS-Well } } f58221d89287 SELECT DISTINCT (?wellA AS ?iri) WHERE { ?s2anchor rdf:type kwg-ont:S2Cell_Level13 . ?s2anchor spatial:connectedTo ?wellA . { ?wellA rdf:type il_isgs:ISGS-Well } UNION { ?wellA rdf:type me_mgs:MGS-Well } ?s2anchor kwg-ont:sfTouches | owl:sameAs ?s2target . ?s2target rdf:type kwg-ont:S2Cell_Level13 . ?s2target spatial:connectedTo kwgr:administrativeRegion.USA.23 . ?s2target spatial:connectedTo ?waterBodyC . ?waterBodyC rdf:type hyf:HY_WaterBody . } diff --git a/scripts/check-query-joins.mts b/scripts/check-query-joins.mts index d491807..1d659c6 100644 --- a/scripts/check-query-joins.mts +++ b/scripts/check-query-joins.mts @@ -252,7 +252,67 @@ for (const c of joinCases) { } } -// --- 3. The prebuilt dashboard questions must not change plan. +// --- 2b. Narrowness is a ranking, not a boolean. A region beats a bare entity +// filter, because a filter with no region is selective in kind and unbounded in +// extent: "all sewage treatment facilities" is a nationwide set. Getting this +// wrong is not a slow query, it is no query at all. Adding an industry filter +// to block A of "facilities upstream from PFOS samples in York" used to turn a +// 3s answer into a 30s timeout in query planning, because the filter alone +// counted as constrained and switched the reorder off. +for (const targetType of ENTITY_TYPES) { + for (const maxDistanceKm of [undefined, 30]) { + const base = { project: 'target' as const, direction: 'downstream' as const, ...(maxDistanceKm ? { maxDistanceKm } : {}) }; + const label = `${targetType} <- facilities${maxDistanceKm ? `, bounded ${maxDistanceKm}km` : ''}`; + + // Anchor filtered but unscoped, target scoped: the region wins. + const filteredAnchor = buildFusedHydrologyQuery({ + ...base, + anchor: { type: 'facilities', ...filtersFor('facilities') }, + target: { type: targetType, ...filtersFor(targetType) }, + targetRegion: ['23005'], + }); + check( + leadsWith(filteredAnchor) === 'target', + `${label}: a bare industry filter must not outrank a region, or the seed is nationwide`, + ); + if (maxDistanceKm) { + check( + seedsFrom(filteredAnchor) === 'target', + `${label}: the bounded aggregate must seed from the region-scoped side`, + ); + } + + // The mirror: anchor scoped, target only filtered. The anchor keeps it. + const filteredTarget = buildFusedHydrologyQuery({ + ...base, + anchor: { type: 'facilities' }, + target: { type: targetType, ...filtersFor(targetType) }, + anchorRegion: ['23005'], + }); + check( + leadsWith(filteredTarget) === 'anchor', + `${label}: a region on the anchor outranks a bare filter on the target`, + ); + } +} + +// --- 3. The prebuilt dashboard questions lead with their narrower side. +// +// This used to assert that no prebuilt reorders, on the grounds that every one +// of them has a constrained anchor. That was a description of the old boolean +// predicate rather than a rule, and it stopped being true when "constrained" +// became a ranking: an industry filter with no region is constrained but not +// narrow. One prebuilt legitimately reorders under the ranking. +// +// `samples-downstream-waste-indiana` has samples scoped to Indiana on block A +// and NAICS 5622 with no region on block C, so the anchor is every waste +// treatment facility in the country and the target is one state. Both orders +// were measured on the live endpoint: identical answers, 136 samples and 415 +// facilities either way, with the reordered form no slower (13s and 2s against +// 16s and 3s). It reorders because the rule says the state-scoped side is the +// narrower one, and the measurement agrees. +const EXPECTED_REORDER = new Set(['samples-downstream-waste-indiana']); + for (const prebuilt of PREBUILT_QUERIES) { const question: AnalysisQuestion = prebuilt.question; if (question.relationship.type === 'near') continue; @@ -261,9 +321,10 @@ for (const prebuilt of PREBUILT_QUERIES) { { question, targetIris: [], anchorIris: [], results: {} } as never, undefined, ); + const expected = EXPECTED_REORDER.has(prebuilt.id) ? 'target' : 'anchor'; check( - leadsWith(query) === 'anchor', - `${prebuilt.id}: every prebuilt has a constrained anchor, so none of them may reorder`, + leadsWith(query) === expected, + `${prebuilt.id}: expected the body to lead with the ${expected}, the narrower of its two sides`, ); } diff --git a/src/engine/templates/fusedQueries.ts b/src/engine/templates/fusedQueries.ts index 481b853..5789d5c 100644 --- a/src/engine/templates/fusedQueries.ts +++ b/src/engine/templates/fusedQueries.ts @@ -408,7 +408,7 @@ function buildFusedWhereBody(opts: FusedBodyOpts): string { // shape whose constrained side was the target failed before this (MD in // docs/query-matrix): timeouts in query planning, or 4.3 GB allocation // failures. Reordered, the same three shapes answer in seconds. - if (sideIsConstrained(opts, 'target') && !sideIsConstrained(opts, 'anchor')) { + if (sideNarrowness(opts, 'target') > sideNarrowness(opts, 'anchor')) { // The target's own entity and filters come first, then the hop onto the // river network. A streams target *is* the flowline, so it needs no hop. const targetHead = @@ -473,11 +473,31 @@ export function blockIsFiltered(block: EntityBlock): boolean { // A side is constrained when the question already narrows it: a region, any // entity filter, or an IRI pin from chunking. Unconstrained means "every // facility in the graph", which is the side that must not lead the query. -function sideIsConstrained(opts: FusedBodyOpts, side: 'anchor' | 'target'): boolean { +// How narrow a side is, not whether it is narrowed at all. The seed walks +// outward from whichever side leads, so the question is always which of the two +// is *smaller*, and a boolean cannot answer it: an industry filter with no +// region says "constrained" while meaning every sewage plant in the country. +// Answering the boolean is what made "facilities upstream from PFOS samples in +// York" fail the moment an industry filter was added to block A, after the same +// question had just been fixed without one. +// +// 3 an IRI pin. The executor chose this slice; re-seeding from the other +// side would throw the slice away. +// 2 a region. Bounded by geography at any level, and the graph is indexed +// for it. +// 1 an entity filter only. Selective in kind, unbounded in extent. +// 0 nothing. +// +// Ties keep the anchor-first order, so this only ever changes cases where both +// sides are constrained at different levels. Every shape where one side was +// constrained and the other was not keeps the order it had. +function sideNarrowness(opts: FusedBodyOpts, side: 'anchor' | 'target'): 0 | 1 | 2 | 3 { const block = side === 'anchor' ? opts.anchor : opts.target; const region = side === 'anchor' ? opts.anchorRegion : opts.targetRegion; const pins = side === 'anchor' ? opts.anchorIris : opts.targetIris; - return Boolean(pins?.length || region?.length) || blockIsFiltered(block); + if (pins?.length) return 3; + if (region?.length) return 2; + return blockIsFiltered(block) ? 1 : 0; } export interface FusedBaseOpts {