Skip to content

fix: support rdf:Description typed-node syntax in RDF import (Brick) - #96

Open
mathewtbenjamin wants to merge 1 commit into
microsoft:mainfrom
mathewtbenjamin:fix/turtle-import-error
Open

fix: support rdf:Description typed-node syntax in RDF import (Brick)#96
mathewtbenjamin wants to merge 1 commit into
microsoft:mainfrom
mathewtbenjamin:fix/turtle-import-error

Conversation

@mathewtbenjamin

Copy link
Copy Markdown

Summary

Fixes #85 — importing the Brick ontology failed with RDF parse error: No ontology metadata or OWL classes found in the RDF document.

Root cause: the parser only recognizes typed node elements (<owl:Class rdf:about="...">). Brick's official RDF/XML (and the output of Python's rdflib generally) declares resources exclusively in the equivalent rdf:Description form:

<rdf:Description rdf:about="https://brickschema.org/schema/Brick#AHU">
  <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  ...
</rdf:Description>

Brick 1.4 contains 0 typed <owl:Class> elements and 1,532 classes declared via rdf:type — so the parser found nothing and threw.

Changes

  • getTypedElements() (new helper in src/lib/rdf/parser.ts): collects both syntaxes for owl:Ontology, owl:Class, owl:DatatypeProperty, and owl:ObjectProperty. Both RDF/XML forms are semantically identical per the spec, and downstream child-element reading (rdfs:label, rdfs:domain, …) is unchanged.
  • Turtle detection: brickschema.org's default download is .ttl; that input previously produced Malformed XML: …. Content starting with @prefix/@base now gets a clear, actionable error (convert to RDF/XML first).
  • Perf drive-by: the DataBinding scan iterated the live getElementsByTagName('*') collection by index — quadratic in some DOM implementations (measured 3m30s for Brick's ~500k elements under jsdom). Swapped for a static querySelectorAll('*') snapshot (no mutation occurs during the loop): same semantics, linear time.

Validation

  • npx tsc --noEmit — clean
  • npx vitest run — 24 files, 401/401 tests pass (9 new: rdf:Description extraction for all four types, mixed-syntax dedupe, Turtle detection)
  • Real-world check: Brick 1.4 RDF/XML (5.3 MB, fetched via content negotiation from brickschema.org) now parses to 1,530 entity types, ontology name Brick, in ~8s under jsdom (previously: error after 3m35s)

Notes

  • Rendering a 1,530-node graph is a separate concern (tracked by the navigation items in Usability issues #87); this PR makes the import succeed per RDF parse error #85.
  • Relationship extraction yields 0 for Brick because its object properties don't carry rdfs:domain/rdfs:range pairs the current mapper uses — faithful to current behavior, could be a follow-up.

Importing the Brick ontology (and any ontology serialized by rdflib or
similar tools) failed with 'No ontology metadata or OWL classes found'.
The parser only recognized typed node elements (<owl:Class rdf:about>),
but many serializers emit the equivalent rdf:Description form:

  <rdf:Description rdf:about='...'>
    <rdf:type rdf:resource='http://www.w3.org/2002/07/owl#Class'/>
  </rdf:Description>

Brick 1.4's official RDF/XML declares all 1,530 classes this way and
contains zero typed elements.

- Add getTypedElements(): collects both typed node elements and
  rdf:Description elements typed via rdf:type, used for owl:Ontology,
  owl:Class, owl:DatatypeProperty and owl:ObjectProperty extraction.
- Detect Turtle input (@prefix/@base) and raise a clear, actionable
  error instead of 'Malformed XML' (brickschema.org defaults to .ttl).
- Replace the live getElementsByTagName('*') collection in the
  DataBinding scan with a static querySelectorAll('*') snapshot;
  repeated indexed access on live collections is quadratic in some DOM
  implementations, making large imports pathologically slow.
- 9 new tests: rdf:Description extraction for all four types, mixed
  syntax dedupe, and Turtle detection.

Verified against Brick 1.4 RDF/XML (5.3 MB): parses to 1,530 entity
types, ontology name 'Brick'.

Fixes microsoft#85
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.

RDF parse error

1 participant