Repository navigation
fluree ontology check / from: see what an extraction model reads of an ontology, and rewrite or slice one - #2208
Conversation
…tology A new top-level `fluree ontology` command and a small library crate, `fluree-db-ontology`, with ontology tools for document extraction: - `check` applies the extraction model's ontology input policy (ontology-adapter-v1) locally and reports what a request would be refused for, what the model reads another way (SKOS text for missing RDFS text, labels from IRIs, OWL restrictions dropped), what it never sees (by predicate, with the keys an extraction response uses), advice, and an estimate of the serialized tokens per window. Exits 1 only when a request would be refused. --json for machines, --catalog to check records with it. - `from` writes an RDF ontology in the shape the model reads well (SKOS copied into RDFS, identifier-style labels in words, restrictions dropped, catalog records given SKOS labels). - --seed slices a large vocabulary to the classes a seed set reaches. The policy port matches the reference request reader's counts on saved requests and adversarial fixtures; three are pinned in tests/parity.rs. docs/cli/ontology.md documents both commands. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX
bplatz
left a comment
There was a problem hiding this comment.
Approving. The policy port, the report and the slice are in good shape, and pinning the parity counts is a good guard. Below are a few things I'd like you to take a pass at. Since the rest of the stack builds on this, I'll leave it to you to decide where each belongs given where you're taking these tools: fix it here, fold it into one of the stacked PRs, or file a follow-up. I've left reviews on each of the stacked PRs too.
1. Which extractor check describes. check mirrors the HTTP reader's input policy (the reader #2207 adds to doc ingest). But the extractor fluree doc ingest already has on main reads rdfs:domain/rdfs:range, schema:domainIncludes and every parent class (the class and property queries in fluree-db-doc/src/model.rs). So for that path, "the extraction model doesn't see rdfs:domain" and the domain-range-not-shown / one-parent-shown advice are wrong, and the docs' "See also" sends readers to doc. I'd name the HTTP reader ([doc.reader]) in the docs, help and report text. This probably reads best landing after #2207.
2. A seed that names no class gives an empty result. resolve_seed returns a prefixed name or <IRI> without checking that it's a declared class. So --seed ex:Persn makes check report no-ontology, and from writes an empty ontology with exit 0. A bare Persn already errors with "no class in the ontology matches"; the prefixed and IRI forms should do the same.
3. from doesn't fix common OWL files. Take a Protégé-style file with [] a owl:AllDisjointClasses ; owl:members (ex:A ex:B) and dc:creator a owl:AnnotationProperty. The flat split files both as catalog records, since SCHEMA_TYPES doesn't include them. check then reports catalog-blank-node and catalog-no-label, and the output of from fails check the same way. Either the reader really refuses these files, in which case from should drop them (or set them aside as it does document nodes), or it doesn't, and the split needs to know about them. Either way, one of these is worth adding to the parity set.
Smaller:
- The help and docs say SKOS labels and definitions are "copied" into
rdfs:label/rdfs:comment, butrewritemoves them (the borrowed SKOS triple is removed). Either is fine; they should just agree. label_wordsrewrites a camel-case label like "iPhone" to "i phone".- Follow-up, not for this PR:
Dialect::TriGinfluree-graph-turtle(#2042) is onnext. Once it reaches main, this crate can read the TriG requests #2207 sends without depending onfluree-db-transact.
Several of the converter issues in the stacked PRs come from the shared emitter, where two source names get merged into one IRI or something is dropped with no count. It may be worth settling one rule for those before the rest land.
…class, drop OWL machinery
Review follow-ups on the first ontology tools PR:
- `check` describes the input policy of an HTTP reader (an extraction
model reached over HTTP, `fluree doc ingest`'s [doc.reader]), and now
says so in its help, report and docs. `fluree doc ingest`'s
language-model extractor reads domains, ranges and every parent class,
so the "not read" counts and the domain/range/parent advice don't
describe it, and the docs say that.
- A --seed given as a prefixed name or an IRI must name a class the file
declares, as a label already had to: `--seed ex:Persn` is refused
instead of giving an empty report or an empty ontology with exit 0.
- OWL axioms written as nodes (`[] a owl:AllDisjointClasses`, AllDifferent,
...) and declarations of annotation properties and datatypes are read
as catalog records by a reader splitting a flat graph, which refuses
them (the reference reader does, for both). `check` reports them as
`owl-machinery` rather than as generic catalog errors, and `from` drops
them and counts them. A Protégé-style fixture joins the parity tests.
- Docs and help say SKOS text is moved into RDFS (as `from` does), not
copied.
- `from` no longer rewrites brand-style labels ("iPhone", "eBay") into
words.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX
|
Thanks @bplatz, this was a really useful pass, and the point about the shared emitter turned out to be the big one. I went with fixing everything in the PR where it lives rather than filing follow-ups, so here's where each landed: 1. Which extractor 2. A seed that names no class. Fixed in 80a7504: a prefixed or 3. Common OWL files. I checked this against the reference reader rather than guessing, and it really does refuse both shapes: Smaller:
The shared emitter. I took your rule as the one rule for every converter: two source names never become one term. That landed in #2210 (e98dfe8) and was merged up the stack:
I've replied on each inline comment with the commit and the test that covers it. Both ends of the stack merge cleanly with |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX
Brings #2217 (SPARQL reads list members as values; CONSTRUCT writes lists), #2218 (schema writes judged by modify policy), #2208, #2169, #2168, #2153, #2149 and #2148 into next. Resolutions: - Nameservice: branch_records is the one branch listing (strict, retracted branches kept for GC) on every backend, resolved through next's bindings; Fluree::list_branches filters retracted ones. The lifecycle conformance suite reads live branches through a helper. DynamoDB's narrow listing is wired into its trait impl. - JSON-LD adapter: main's graph scoping (Walk, Scope, node_graph, selectors) with next's triple terms, @annotation, @reifies, blank-label and number datatype handling. to_graph_events writes a JSON-LD named graph under its @id and refuses a graph selector. main's f:reifiesGraph anchor is dropped: next writes an annotation as an rdf:reifies link in its graph. emit_quad_list_item takes (graph, index). - Bulk import: an annotation's link is written to the graph its slots name, and a triple-term statement in a named graph is spooled under that graph (both landed in the default graph); emit_quad_reified_triple is implemented. resolve_object_value keeps main's vector refusals and next's term-table path. - Ledger manager: a store that fails to load fails the load or keeps the reloaded ledger's state (main), over next's load_decoding_root and activation swap rule. - Novelty keeps main's KeptEffects without the retired arena's reifies capture. The pool's resolve_events_at and compaction's split_lifecycles follow fluree_db_core::same_t. - Retired annotation arena files stay deleted. - Tests from main adapted to next: one Fluree per storage directory, async genesis_ledger, storage-namespace content stores, u32 graph ids, a store broken by hiding a dictionary branch (next has no disk cache), a refused import leaving no ledger. next's tests that pinned bulk import refusing @graph and SPARQL's RDF list view now check what main changed them to.
This adds a top-level
fluree ontologycommand with two subcommands,checkandfrom, plus a small library crate (fluree-db-ontology) that holds the logic so the Python package (or anything else) can reuse it later. Both are ontology tools for document extraction: an extraction model that reads documents against a caller's ontology only sees part of that ontology, and how the ontology is written turns out to matter a lot for what gets read (labels in words vs. column names, descriptions vs. none, a sliced vocabulary vs. all of schema.org). These commands make that visible locally, before anything is sent anywhere.fluree ontology check <FILE> [--catalog <FILE>] [--seed <CLASSES>] [--json]applies the extraction model's ontology input policy (ontology-adapter-v1) and reports four things:skos:prefLabel/skos:definitionstanding in for a missingrdfs:label/rdfs:comment, a label made from the IRI's local name, OWL restrictions and other non-SHACL blank nodes dropped);rdfs:domain,owl:equivalentClass, a secondrdfs:subClassOfparent, SHACL constraints it doesn't support, ...);employer_id,employerId), IRIs whose local names read as key columns even when the label is fine, a vocabulary large enough that it should be sliced, domains/ranges that ought to be said in a description instead.It exits 1 only when a request would be refused; adaptations and advice exit 0. The
adapted/not_shownmaps in--jsonuse the exact keys an extraction response reports those same counts under (X-Fluree-Ontology-Adapted/-Not-Shown), so the two can be compared line for line. It also estimates the serialized tokens the ontology and catalog cost per window. The model's tokenizer isn't in the CLI, so that number is an estimate from character counts, fitted against reported token counts for saved requests (catalogs from 68 to 3,250 records), and is good to roughly a tenth; the docs say so.fluree ontology from <FILE> [--seed <CLASSES>] [--format turtle|jsonld] [-o <FILE>]writes the ontology back out with what the model reads made explicit: SKOS text copied into RDFS, missing labels filled from the IRI, identifier-style labels rewritten in words (worksFor→ "works for"), OWL declarations also declared as their RDFS equivalents, restrictions dropped. Domains/ranges and other axioms are kept. Catalog records with onlyrdfs:label(a vocabulary's enumeration members, e.g. schema.org'sschema:Female) getskos:prefLabelsince that is what catalog records are read by.--seedslices a large vocabulary to what a set of seed classes reach: the seeds and their ancestors, then properties whose domain is one of them (rdfs:domain, schema.org'sdomainIncludes, or a member of anowl:unionOfdomain) and the classes in their ranges,--depthtimes (default 1). I stopped "reachable" at a depth on purpose, since following every range out of a vocabulary rooted in oneThingclass reaches nearly all of it. Against schema.org (1,016 classes, 1,694 properties),--seed Person,Organizationkeeps 64 classes and 127 properties, about 12.5K tokens instead of ~170K.How I checked parity with the policy
The policy port in
fluree-db-ontology/src/policy.rsis a line-for-line port of the extraction service's request reader (itsadapt_ontologyand its not-shown counter, plus the SHACL compile rules those depend on). I ran the service's own reader (CPU only, no model) and this command side by side over 31 inputs — saved benchmark requests with their catalogs, SHACL-heavy and range-overlay ontologies, and adversarial fixtures for each rule (multilingual SKOS, OWL restrictions,unionOfdomains, second parents, anowl:Ontologyheader, unsupported SHACL constraints and non-direct paths, the failure cases) — and every adapted/not-shown count and every refusal (with the same reason) matched. The three adversarial fixtures are pinned influree-db-ontology/tests/parity.rswith the counts the reader produced, so drift shows up as a test failure; I mutated the shown-predicate list to confirm those tests actually fail when the port is wrong.One known gap, deliberately: the policy also treats one event-class declaration type and one example predicate as shown, and those live in a vocabulary namespace that hasn't been settled yet, so I left them out for now. Until they're added, a file that uses them will see those triples counted under "not read" when the model would actually show them. It's a two-line addition once the namespace is final.
Scope notes
xt:ontology/xt:instancesgraph roles, so a saved request can be checked as-is). TriG isn't read yet: the only TriG driver in the workspace lives insidefluree-db-transact's RDF-text path and builds transaction templates, not a plain dataset, and I didn't want to pull that crate in here.check request.trigsays so plainly. Happy to follow up by moving the TriG block locator somewhere shared if we think it's worth it.fluree catalog fromcome in follow-up PRs stacked on this one;fromcurrently refuses non-RDF input with a clear message.docs/cli/ontology.mddocuments both commands, the JSON report shape and finding codes; it's linked fromdocs/cli/README.mdandSUMMARY.md(sodocs_coveragestays green).fluree-db-cli/tests/ontology.rs) rather thanintegration.rs.cargo test -p fluree-db-ontology -p fluree-db-cliandcargo clippy -p fluree-db-ontology -p fluree-db-cli --all-targets --no-depsare clean locally.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmQVZNYkCgGd38GYUyX