fix: support rdf:Description typed-node syntax in RDF import (Brick) - #96
Open
mathewtbenjamin wants to merge 1 commit into
Open
fix: support rdf:Description typed-node syntax in RDF import (Brick)#96mathewtbenjamin wants to merge 1 commit into
mathewtbenjamin wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 equivalentrdf:Descriptionform:Brick 1.4 contains 0 typed
<owl:Class>elements and 1,532 classes declared viardf:type— so the parser found nothing and threw.Changes
getTypedElements()(new helper insrc/lib/rdf/parser.ts): collects both syntaxes forowl:Ontology,owl:Class,owl:DatatypeProperty, andowl:ObjectProperty. Both RDF/XML forms are semantically identical per the spec, and downstream child-element reading (rdfs:label,rdfs:domain, …) is unchanged..ttl; that input previously producedMalformed XML: …. Content starting with@prefix/@basenow gets a clear, actionable error (convert to RDF/XML first).getElementsByTagName('*')collection by index — quadratic in some DOM implementations (measured 3m30s for Brick's ~500k elements under jsdom). Swapped for a staticquerySelectorAll('*')snapshot (no mutation occurs during the loop): same semantics, linear time.Validation
npx tsc --noEmit— cleannpx vitest run— 24 files, 401/401 tests pass (9 new: rdf:Description extraction for all four types, mixed-syntax dedupe, Turtle detection)Brick, in ~8s under jsdom (previously: error after 3m35s)Notes
rdfs:domain/rdfs:rangepairs the current mapper uses — faithful to current behavior, could be a follow-up.