Repository navigation
ontology check: event classes and their kinds; refuse xt:example and extraction results - #2262
Conversation
…extraction results `fluree ontology check` follows the reader's current input policy for events and refused statements: - A class declared `xt:EventClass` (https://ns.flur.ee/extract#) beside rdfs:Class is an event class, and the declaration is shown, not counted as unread. The report counts event classes and the kinds the reader will read: one per catalog record of the class labelled "<event> kind" (with exactly one property labelled "kind"), and one per event subclass. An event subclass is read as a kind of its parent in place of itself, so its own statements count under "(not a shown term)", as a reader reports them. - Advice finds what leaves a reader finding no events or no kinds: a class with a kind class that isn't an event class, `xt:EventClass` without rdfs:Class, an event subclass that isn't an event class, two kind classes, not exactly one "kind" property, no kind records. - `xt:example` and extraction results (xt:entity, xt:score, xt:accepted, rdf:reifies, ...) fail a request (`example-refused`, `extraction-annotations`); `fluree ontology from` drops and counts them. Checked against the reference reader on 12 files (events, kinds, subtypes, refusals): the same refusals, adapted and not-shown counts, and kind counts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQLwTu67J9hjS5nwrh
bplatz
left a comment
There was a problem hiding this comment.
Approving, but please look at the inline feedback before merging. The two I'd fix in this PR are the check slowdown on large ontologies and from leaving parts of result records behind.
The PR also has no labels, so it would land under "Other Changes" in the release notes; enhancement and area:cli fit.
| ) -> usize { | ||
| let label = |t: &ShownTerm| t.label.as_deref().map(|l| l.trim().to_lowercase()); | ||
| let is_event = |t: &ShownTerm| shown.events.contains(&t.iri); | ||
| let kind_classes = |of: &ShownTerm| -> Vec<&ShownTerm> { |
There was a problem hiding this comment.
check now grows with the square of the class count, whether or not the ontology has any event classes. event_advice calls kind_classes for every class to find unmarked ones, and each call scans every class and lowercases its label, allocating each time. Timed on generated ontologies with no event classes, in a debug test build:
| Classes | Before this PR | With this PR |
|---|---|---|
| 2,000 | 0.08 s | 1.3 s |
| 10,000 | 0.43 s | 20.6 s |
| 20,000 | 0.88 s | 66.7 s |
A release build will be faster, but it grows the same way. Building a map from lowercased label to classes once, then looking up "<label> kind" for each class, makes it linear.
There was a problem hiding this comment.
You're right, and thank you for timing it. 65fe699 does what you suggested. event_advice now builds a map from lowercased label to the non-event classes once, and finding a class's kind class is a single lookup for "<label> kind". So check is linear again whether or not there are event classes. I didn't add a timing test, since a wall-clock assertion would be flaky in CI, so here is the timing note instead. Same setup as yours: generated ontologies with no event classes, debug test build, check alone:
| Classes | 1a9615213 (before) |
65fe6998b |
|---|---|---|
| 2,000 | 0.75 s | 0.08 s |
| 10,000 | 16.6 s | 0.43 s |
| 20,000 | 68.2 s | 0.87 s |
The right-hand column matches your "before this PR" numbers, so the event advice costs nothing measurable now.
| quads.retain(|q| &*q.predicate != XT_EXAMPLE); | ||
| let examples = before - quads.len(); | ||
| let before = quads.len(); | ||
| quads.retain(|q| !RESULT_PREDICATES.contains(&&*q.predicate)); |
There was a problem hiding this comment.
This drops each statement with a result predicate but keeps the rest of the subject, so from's output can still fail check:
- With
[] a ex:Claim ; xt:entity ex:alice ; xt:score 0.9 .in the input, the output keeps[] a ex:Claim, which failscatalog-blank-node. - The same record with an IRI (
ex:c1 …) keepsex:c1 a ex:Claim, which failscatalog-no-label.
A blank node that carries a result predicate can only be a result, so dropping all of its statements is safe. An IRI subject may be a real record, so that one is a judgment call, but the summary could at least say what was left.
There was a problem hiding this comment.
Agreed, and the [] a ex:Claim leftover was a real way for from's output to fail check. Fixed in 6f9e96d. A subject that carries a result now goes whole when it can only be a result:
- a blank node with a result predicate, for the reason you gave;
- an IRI with nothing besides its results but
rdf:type. Kept, it would be exactly theex:c1 a ex:Claimrecord that failscatalog-no-label.
Statements that point at a blank node that went are dropped too, so nothing is left referring to it. On the judgment call, an IRI subject that has a label or description of its own is kept without its results, since it may well be a real record. The summary now says so in both directions: "extraction result records dropped whole: N" and "records kept without their extraction annotations (check they are records): N". The record count is taken after the drop. a_result_record_is_dropped_whole covers your two examples (the blank node nested under a real record, and ex:c1), and checks that the rewritten output passes check with the one real record left. what_a_reader_refuses_is_dropped now also asserts that a labelled record is kept and counted.
| classes: shown.classes.len(), | ||
| properties: shown.properties.len(), | ||
| records: records.len(), | ||
| event_classes: shown.events.len(), |
There was a problem hiding this comment.
This counts the event subclasses too, though the PR describes each as read "as a kind of its parent, in place of itself". So Meeting with an event subclass Offsite reports "2 event classes with 1 kind" (the (2, 1) in event_subtypes_and_undeclared_event_classes_are_found), and three nested event classes A ⊃ B ⊃ C report 3 with 2 kinds.
If the reader sees one event class there, shown.events.len() - shown.subtypes.len() would match it. If the 12-file comparison with the reference reader didn't include nested subclasses, that case is worth one run.
There was a problem hiding this comment.
Good catch, the count contradicted the PR's own description. Fixed in 65fe699: event_classes is now shown.events.len() - shown.subtypes.len(). Meeting with the event subclass Offsite reports 1 event class with 1 kind (the test now asserts (1, 1)), and nested_event_subclasses_are_kinds_of_one_event_class covers your A ⊃ B ⊃ C case as 1 with 2. On the nested case and the reader: I didn't rerun the 12-file comparison, but I did read how the reader treats it. Every event class whose parent is an event class is read as a kind of that parent and leaves the class list, nested ones included, so one event class with two kinds is what it reads. The docs' description of event_classes says this now too (d2100b8).
| `catalog-long-definition` and `little-room-for-text` are advice. | ||
| `catalog-long-definition`, `little-room-for-text` and the event findings | ||
| `event-class-not-marked` (a class with a kind class that isn't an event class), | ||
| `event-class-undeclared` (`xt:EventClass` without `rdfs:Class`), |
There was a problem hiding this comment.
The code accepts owl:Class here too; the finding's own message says "(rdfs:Class or owl:Class)".
There was a problem hiding this comment.
Thanks, fixed in d2100b8: it now reads "xt:EventClass without rdfs:Class or owl:Class", matching the finding's message. The PR body's list says the same now.
| meeting"), in place of itself. | ||
|
|
||
| ```turtle | ||
| @prefix xt: <https://ns.flur.ee/extract#> . |
There was a problem hiding this comment.
Only xt: is declared, so pasting this example fails to parse. It needs ex:, rdf:, rdfs: and skos: as well.
There was a problem hiding this comment.
Oops, yes. d2100b8 declares rdf:, rdfs:, skos: and ex: beside xt:. I pasted the block as-is into a file and ran check on it: it parses and passes, with 2 classes, 1 event class, 2 kinds and 2 catalog records.
| `hiddenLabel` as names, and the first 300 characters of `skos:definition`. A | ||
| record needs a SKOS label and an IRI. | ||
|
|
||
| A request is refused if it carries `xt:example` (example phrases are no longer |
There was a problem hiding this comment.
Refusing xt:example changes behavior for anyone whose ontology uses it: their requests now fail. It deserves a line in the PR body for the release note, pointing at fluree ontology from to drop them.
There was a problem hiding this comment.
Agreed, that's a real behaviour change for anyone already using xt:example. The PR body now opens with a "Behavior change (release note)" section. It says check now fails an ontology with xt:example and a reader refuses a request carrying it, points at fluree ontology from to drop them, and suggests saying what the examples showed in rdfs:comment / skos:definition instead.
…read `fluree ontology check` headed its counts "Not read by the reader" and advised that a reader "doesn't see" rdfs:domain or rdfs:range. The counts are what the model is not shown (the same keys as a reader's X-Fluree-Ontology-Not-Shown), but the reader still writes its answer by domains and ranges: a datatype range types a value (and a value not in that form is kept as a claim that isn't accepted), and a domain or class range keeps an entity a node. The heading is now "Not shown to the model", and the advice and docs say what the reader still does with them. For #2262 (whose `xt:EventClass` handling already keeps an event class's type out of these counts). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@bplatz one small addition since your approval, in So the heading is now "Not shown to the model", and the Happy to talk it through if you'd rather word it differently. |
…counted as event classes event_advice looked up each class's kind class by scanning every class and lowercasing its label, so `check` grew with the square of the class count whether or not the ontology had event classes. The non-event classes are now indexed by lowercased label once, and each lookup is one map get. On generated ontologies with no event classes (debug test build): 2,000 classes 0.75 s -> 0.08 s, 10,000 16.6 s -> 0.43 s, 20,000 68 s -> 0.87 s, the same as before event classes were added. `event_classes` no longer counts event subclasses, which are read as kinds of their parent in place of themselves: Meeting with the event subclass Offsite is 1 event class with 1 kind, and nested A > B > C is 1 with 2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`from` dropped each statement with a result predicate but kept the rest
of its subject, so `[] a ex:Claim ; xt:entity ex:alice ; xt:score 0.9`
left `[] a ex:Claim` (refused as catalog-blank-node) and the same record
on an IRI left `ex:c1 a ex:Claim` (catalog-no-label). A subject carrying a
result now goes whole when it can only be a result: a blank node, or an
IRI with nothing but rdf:type besides its results; so do statements that
point at a blank node that went. A subject with a label or description of
its own keeps it, without its results, and the summary counts both cases
("extraction result records dropped whole", "records kept without their
extraction annotations"). The record count is taken after the drop.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… count; result records The event class example declares rdf:, rdfs:, skos: and ex: as well as xt:, so it parses as written (checked: it passes with 1 event class and 2 kinds). event-class-undeclared names owl:Class beside rdfs:Class, as its message does. event_classes leaves out event subclasses. `from` drops a result record whole and says what it kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, @bplatz. Both of the ones you'd fix here are fixed, along with the other four. I've replied in each thread. (My comment earlier tonight was only about the domain/range wording in
I also merged |
Behavior change (release note)
fluree ontology checknow fails an ontology that usesxt:example, and a reader refuses a request that carries it, so an ontology that relied on example phrases will start being refused.fluree ontology fromdrops them (and extraction results), and saying what the examples show in the description (rdfs:commentfor a class or property,skos:definitionfor a catalog record) keeps what they carried.What
fluree ontology check(andfrom) now follow an HTTP reader's current input policy for event classes and for the statements a reader refuses:Event classes and their kinds
xt:EventClass(https://ns.flur.ee/extract#) besiderdfs:Classis an event class. Its declaration is shown, no longer counted under "not read".event_classes,event_kindsin--json; "2 classes, 1 property (1 event class with 2 kinds)" in the header). Kinds come one of two ways:(not a shown term), as a reader reports them.event-class-not-marked: a class with a kind class but noxt:EventClass. This is the expensive one: the reader finds no events of it at all.event-class-undeclared:xt:EventClasswithoutrdfs:Classorowl:Class.event-subtype-not-marked: a subclass of an event class that isn't an event class itself.event-kind-ambiguous: two kind classes.event-kind-property: not exactly one "kind" property.event-kind-no-records: no kind records.Refused statements
xt:example(example phrases are no longer read) and extraction results (xt:entity,xt:score,xt:accepted,rdf:reifies, ...) now fail a request:example-refused,extraction-annotations.fluree ontology fromdrops them and counts them in its summary. A result record goes whole (a blank node carrying a result, or an IRI with nothing but its types besides its results), so whatfromwrites passescheck; a subject with a label or description of its own keeps it, and the summary counts those.docs/cli/ontology.mdgains an "Event classes" section with an example, plus the new codes and JSON keys.Checked
Unit tests for each finding, the counts and the subtype accounting, plus a CLI test (
checkrefusesxt:example,fromdrops it, and the result passes with "1 event class with 2 kinds").Compared with the reference reader on 12 small files covering events, kinds, subtypes and refusals:
adaptedandnot_showncounts;One file, an
rdf:reifieswith a<<( … )>>triple term, doesn't get that far here: the Turtle parser onmaindoesn't accept triple terms on this path yet, socheckstops with a parse error (exit 1). Anrdf:reifieswith an IRI object is caught asextraction-annotations.cargo fmt --all --check,cargo clippy -p fluree-db-ontology -p fluree-db-cli --all-targets -D warnings,cargo test -p fluree-db-ontology,cargo test -p fluree-db-cli --test ontology.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmQLwTu67J9hjS5nwrh