Skip to content

feat: fix SHACL discovery and enrich cross-domain references#4

Open
jdsika wants to merge 1 commit into
mainfrom
feat/enrich-cross-domain-references
Open

feat: fix SHACL discovery and enrich cross-domain references#4
jdsika wants to merge 1 commit into
mainfrom
feat/enrich-cross-domain-references

Conversation

@jdsika
Copy link
Copy Markdown
Contributor

@jdsika jdsika commented May 13, 2026

Summary

Fix queryDomainReferences to properly discover cross-domain reference relationships from the ontology's nested SHACL structure, and enrich sample scenario data with rich referenced artifacts.

Problem

The queryDomainReferences function used sh:class to discover which domains reference others via manifest:hasReferencedArtifacts. But the actual SHACL uses deeply nested structures (sh:node → sh:or → rdf:list → sh:node → sh:targetClass), so discovery found nothing. This meant cross-domain queries (e.g., "scenarios on motorways with many intersections") could not work.

Additionally, sample data was sparse: only 17/50 scenarios had HD map references, each with just 2 stub properties. No environment model references existed.

Solution

SHACL Discovery Fix (schema-queries.ts)

Multi-strategy approach using separate queries (UNION + property paths crash Oxigraph WASM):

  1. Strategy 1 (direct sh:class) — kept for forward compatibility
  2. Strategy 2 (nested walk)sh:node → sh:or → rdf:rest*/rdf:first → sh:node → sh:targetClass
  3. Parent resolution — 3 fallback strategies:
    • A: Direct sh:targetClass on constraint shape
    • B: Walk up through sh:and conjunction list
    • C: Walk up through sh:or disjunction list

Result: Discovers scenario → hdmap and scenario → environment-model from the real ontology.

Sample Data Enrichment

  • All 50 scenarios now reference HD maps with full properties (format, content with road/lane types, quantity with intersections/signs/speed limits, quality, data source, georeference)
  • 20 scenarios additionally reference environment models (format, content, project tools, quantity, quality, georeference)
  • All property selection uses generic modular arithmetic over value arrays — no manual mapping tables
  • Output path corrected (packages/search/data/ not packages/ontology/data/)

Test Improvements

Strengthened discovery tests from weak if (refs.length > 0) guards to assertive checks that scenario → hdmap and scenario → environment-model are actually discovered.

Files Changed

File Change
packages/search/src/schema-queries.ts Fix discovery with multi-strategy SHACL walk
packages/search/src/__tests__/schema-queries.test.ts Strengthen discovery assertions
scripts/generate-sample-scenarios.js Full rewrite with rich cross-domain references
packages/search/data/sample-scenarios.ttl Regenerated (174KB, 50 HD map + 20 env model refs)

Validation

  • ✅ 58 tests pass (was 57 — added scenario → environment-model test)
  • ✅ TypeScript strict mode clean
  • ✅ ESLint clean
  • ✅ Prettier formatted
  • pnpm run validate passes

Fix queryDomainReferences to walk nested SHACL structures
(sh:node → sh:or → rdf:list → sh:node → sh:targetClass) instead of
relying on sh:class which finds nothing in the real ontology. Uses
multi-strategy approach with separate queries to avoid Oxigraph WASM
crashes from UNION + property path expansion.

Parent discovery uses 3 fallback strategies:
- Direct sh:targetClass on constraint shape
- Walk up through sh:and conjunction list
- Walk up through sh:or disjunction list

Enrich sample scenario data:
- All 50 scenarios now reference HD maps with full properties
  (format, content, quantity, quality, data source, georeference)
- 20 scenarios additionally reference environment models
- All property selection uses generic modular arithmetic — no
  manual mapping tables
- Fix output path (packages/search/data/ not packages/ontology/data/)

Strengthen discovery tests to assert actual results instead of
using if-guard patterns that pass on empty results.

Closes: cross-domain reference discovery and sample data enrichment
Signed-off-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant