Skip to content

ontology check: event classes and their kinds; refuse xt:example and extraction results - #2262

Merged
aaj3f merged 6 commits into
mainfrom
feat/ontology-event-class
Nov 11, 2026
Merged

aaj3f merged 6 commits into
mainfrom
feat/ontology-event-class

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Behavior change (release note)

fluree ontology check now fails an ontology that uses xt:example, and a reader refuses a request that carries it, so an ontology that relied on example phrases will start being refused. fluree ontology from drops them (and extraction results), and saying what the examples show in the description (rdfs:comment for a class or property, skos:definition for a catalog record) keeps what they carried.

What

fluree ontology check (and from) now follow an HTTP reader's current input policy for event classes and for the statements a reader refuses:

Event classes and their kinds

  • A class declared xt:EventClass (https://ns.flur.ee/extract#) beside rdfs:Class is an event class. Its declaration is shown, no longer counted under "not read".
  • The report counts event classes (an event subclass counts as a kind of its parent, not as an event class) and the kinds a reader will read (event_classes, event_kinds in --json; "2 classes, 1 property (1 event class with 2 kinds)" in the header). Kinds come one of two ways:
    • A kind class and kind records. One class labelled "<the event's label> kind", exactly one property labelled "kind", and the catalog records of that class.
    • Event subclasses. A subclass of an event class that is an event class too is read as a kind of its parent, in place of itself. Its own statements therefore count under (not a shown term), as a reader reports them.
  • New advice for what leaves a reader finding no events or no kinds:
    • event-class-not-marked: a class with a kind class but no xt:EventClass. This is the expensive one: the reader finds no events of it at all.
    • event-class-undeclared: xt:EventClass without rdfs:Class or owl: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 from drops 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 what from writes passes check; a subject with a label or description of its own keeps it, and the summary counts those.

docs/cli/ontology.md gains 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 (check refuses xt:example, from drops 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:

    • the same refusals;
    • the same adapted and not_shown counts;
    • the same number of kinds.

    One file, an rdf:reifies with a <<( … )>> triple term, doesn't get that far here: the Turtle parser on main doesn't accept triple terms on this path yet, so check stops with a parse error (exit 1). An rdf:reifies with an IRI object is caught as extraction-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

…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
@aaj3f aaj3f self-assigned this Nov 4, 2026
@aaj3f
aaj3f requested a review from bplatz November 4, 2026 18:24

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fluree-db-ontology/src/check.rs Outdated
) -> 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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fluree-db-ontology/src/write.rs Outdated
quads.retain(|q| &*q.predicate != XT_EXAMPLE);
let examples = before - quads.len();
let before = quads.len();
quads.retain(|q| !RESULT_PREDICATES.contains(&&*q.predicate));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fails catalog-blank-node.
  • The same record with an IRI (ex:c1 …) keeps ex:c1 a ex:Claim, which fails catalog-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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the ex:c1 a ex:Claim record that fails catalog-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.

Comment thread fluree-db-ontology/src/check.rs Outdated
classes: shown.classes.len(),
properties: shown.properties.len(),
records: records.len(),
event_classes: shown.events.len(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread docs/cli/ontology.md Outdated
`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`),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code accepts owl:Class here too; the finding's own message says "(rdfs:Class or owl:Class)".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/cli/ontology.md
meeting"), in place of itself.

```turtle
@prefix xt: <https://ns.flur.ee/extract#> .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only xt: is declared, so pasting this example fails to parse. It needs ex:, rdf:, rdfs: and skos: as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/cli/ontology.md
`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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@aaj3f

aaj3f commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@bplatz one small addition since your approval, in 1a9615213, so it doesn't land unannounced. Testing the CLI end to end against the live reader turned up that fluree ontology check filed rdfs:domain / rdfs:range under "Not read by the reader". The counts were right: the model isn't shown them, and the reader's own X-Fluree-Ontology-Not-Shown header says exactly rdfs:domain=2,rdfs:range=2 on the same input. The wording was wrong, though, because the decoder still writes by them. A datatype range types the value (one it can't read in that type is kept with xt:accepted false), and a domain or class range keeps an entity a node.

So the heading is now "Not shown to the model", and the domain-range-not-shown advice and docs/cli/ontology.md say what the reader still does with those terms. No counts or refusals change. Ontology and CLI ontology tests, fmt and clippy all pass. The event-class half was already right in this PR (xt:EventClass is in SHOWN_TYPES here; it's main that still lists it), so merging this fixes that too.

Happy to talk it through if you'd rather word it differently.

aaj3f and others added 4 commits November 10, 2026 23:34
…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]>
@aaj3f aaj3f added enhancement New feature or request area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows labels Nov 11, 2026
@aaj3f

aaj3f commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

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 1a9615213; none of this was in it.)

  • The check slowdown (65fe699): kind classes are now looked up through a label map built once, so check is linear again. On generated ontologies with no event classes (debug test build): 20,000 classes went from 68 s to 0.87 s, 10,000 from 16.6 s to 0.43 s, back to the pre-PR numbers. The timing table is in the thread.
  • from leaving parts of result records (6f9e96d): a subject that can only be a result goes whole. That's a blank node carrying a result, or an IRI with nothing but types besides its results, plus anything pointing at a blank node that went. A subject with its own label or description is kept without its results, and the summary counts both cases. Your two examples are a test, and the rewritten output passes check.
  • The event-class count no longer counts event subclasses (65fe699). The docs example parses as written, owl:Class is named, and event_classes is described accurately (d2100b8).
  • Labels: enhancement and area:cli are on.
  • Release note: the PR body now opens with a "Behavior change" section for refusing xt:example, pointing at fluree ontology from.

I also merged origin/main in (fbe09c0). cargo fmt --all --check, clippy on fluree-db-ontology and fluree-db-cli with --all-targets, and cargo test -p fluree-db-ontology -p fluree-db-cli pass.

@aaj3f
aaj3f merged commit 0fd55f5 into main Nov 11, 2026
19 checks passed
@aaj3f
aaj3f deleted the feat/ontology-event-class branch November 11, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants