|
| 1 | +//! SKOS (Simple Knowledge Organization System, `http://www.w3.org/2004/02/skos/core#`) |
| 2 | +//! hydration glue. |
| 3 | +//! |
| 4 | +//! L2 universal ontology for thesauri, classification schemes, subject-heading |
| 5 | +//! lists, taxonomies, and other controlled vocabularies. Defines `Concept`, |
| 6 | +//! `ConceptScheme`, `Collection`, `OrderedCollection`, plus the canonical |
| 7 | +//! semantic-relation surface (`broader`/`narrower`/`related` plus their |
| 8 | +//! transitive variants and the `*Match` mapping siblings). |
| 9 | +//! |
| 10 | +//! Multi-file hydration: SKOS Core + SKOS-XL (eXtension for Labels — adds |
| 11 | +//! `skosxl:Label` so labels can be first-class resources with their own |
| 12 | +//! IRIs rather than literals) hydrate into one bundle keyed by |
| 13 | +//! `OGIT::SKOS_V1.0`. SKOS-XL declares `owl:imports` against Core so the |
| 14 | +//! merged bundle gives consumers both surfaces in a single G slot. |
| 15 | +//! |
| 16 | +//! Declares `inherits_from: Some(OGIT::DOLCE_V1.0)`. Alignment with DUL: |
| 17 | +//! `skos:Concept ⊑ dul:Concept`, `skos:Collection ⊑ dul:Collection`. |
| 18 | +//! Downstream consumers assert these axioms when they need cross-G |
| 19 | +//! traversal between SKR-style classification trees and DOLCE |
| 20 | +//! upper-category cascade. |
| 21 | +
|
| 22 | +use std::path::{Path, PathBuf}; |
| 23 | + |
| 24 | +use lance_graph_contract::manifest::OGIT; |
| 25 | + |
| 26 | +use super::owl::{HydrateErr, OwlHydrator}; |
| 27 | +use crate::registry::OntologyRegistry; |
| 28 | + |
| 29 | +const SKOS_CORE_RELATIVE_PATH: &str = "data/ontologies/skos/skos-core.rdf"; |
| 30 | +const SKOS_XL_RELATIVE_PATH: &str = "data/ontologies/skos/skos-xl.rdf"; |
| 31 | + |
| 32 | +const SKOS_EDGE_WHITELIST: &[&str] = &[ |
| 33 | + "http://www.w3.org/2000/01/rdf-schema#subClassOf", |
| 34 | + "http://www.w3.org/2000/01/rdf-schema#subPropertyOf", |
| 35 | + "http://www.w3.org/2002/07/owl#equivalentClass", |
| 36 | + // Hierarchical (intra-scheme) relations |
| 37 | + "http://www.w3.org/2004/02/skos/core#broader", |
| 38 | + "http://www.w3.org/2004/02/skos/core#narrower", |
| 39 | + "http://www.w3.org/2004/02/skos/core#broaderTransitive", |
| 40 | + "http://www.w3.org/2004/02/skos/core#narrowerTransitive", |
| 41 | + "http://www.w3.org/2004/02/skos/core#related", |
| 42 | + "http://www.w3.org/2004/02/skos/core#semanticRelation", |
| 43 | + // Scheme membership |
| 44 | + "http://www.w3.org/2004/02/skos/core#inScheme", |
| 45 | + "http://www.w3.org/2004/02/skos/core#hasTopConcept", |
| 46 | + "http://www.w3.org/2004/02/skos/core#topConceptOf", |
| 47 | + "http://www.w3.org/2004/02/skos/core#member", |
| 48 | + "http://www.w3.org/2004/02/skos/core#memberList", |
| 49 | + // Cross-scheme mapping (load-bearing for SKR03/SKR04 alignment) |
| 50 | + "http://www.w3.org/2004/02/skos/core#mappingRelation", |
| 51 | + "http://www.w3.org/2004/02/skos/core#broadMatch", |
| 52 | + "http://www.w3.org/2004/02/skos/core#narrowMatch", |
| 53 | + "http://www.w3.org/2004/02/skos/core#relatedMatch", |
| 54 | + "http://www.w3.org/2004/02/skos/core#exactMatch", |
| 55 | + "http://www.w3.org/2004/02/skos/core#closeMatch", |
| 56 | + // Lexical labels (Core + XL) |
| 57 | + "http://www.w3.org/2004/02/skos/core#prefLabel", |
| 58 | + "http://www.w3.org/2004/02/skos/core#altLabel", |
| 59 | + "http://www.w3.org/2004/02/skos/core#hiddenLabel", |
| 60 | + "http://www.w3.org/2004/02/skos/core#notation", |
| 61 | + "http://www.w3.org/2008/05/skos-xl#literalForm", |
| 62 | + "http://www.w3.org/2008/05/skos-xl#prefLabel", |
| 63 | + "http://www.w3.org/2008/05/skos-xl#altLabel", |
| 64 | + "http://www.w3.org/2008/05/skos-xl#hiddenLabel", |
| 65 | + "http://www.w3.org/2008/05/skos-xl#labelRelation", |
| 66 | +]; |
| 67 | + |
| 68 | +/// Hydrate SKOS as `OGIT::SKOS_V1` (L2 universal knowledge-organization). |
| 69 | +/// |
| 70 | +/// Hydrates both Core and XL artifacts into a single bundle. |
| 71 | +pub fn hydrate_skos(registry: &OntologyRegistry) -> Result<u32, HydrateErr> { |
| 72 | + let core = skos_core_path(); |
| 73 | + let xl = skos_xl_path(); |
| 74 | + hydrate_skos_from(&[&core, &xl], registry) |
| 75 | +} |
| 76 | + |
| 77 | +/// Test-friendly variant: hydrate SKOS from explicit paths. Accepts a slice |
| 78 | +/// so callers can opt into Core-only, or substitute the `skos-owl1dl.rdf` |
| 79 | +/// OWL-DL-conformant variant (also shipped under `data/ontologies/skos/`). |
| 80 | +pub fn hydrate_skos_from( |
| 81 | + ttl_paths: &[&Path], |
| 82 | + registry: &OntologyRegistry, |
| 83 | +) -> Result<u32, HydrateErr> { |
| 84 | + let hydrator = OwlHydrator { |
| 85 | + g: OGIT::SKOS_V1.0, |
| 86 | + version: OGIT::SKOS_V1.1, |
| 87 | + domain_name: "skos".to_string(), |
| 88 | + inherits_from: Some(OGIT::DOLCE_V1.0), |
| 89 | + starting_entity_id: 100, |
| 90 | + }; |
| 91 | + hydrator.hydrate_many(ttl_paths, registry)?; |
| 92 | + registry |
| 93 | + .register_edge_types(OGIT::SKOS_V1.0, SKOS_EDGE_WHITELIST) |
| 94 | + .map_err(|reason| HydrateErr::Registry { |
| 95 | + g: OGIT::SKOS_V1.0, |
| 96 | + reason, |
| 97 | + })?; |
| 98 | + Ok(OGIT::SKOS_V1.0) |
| 99 | +} |
| 100 | + |
| 101 | +fn skos_core_path() -> PathBuf { |
| 102 | + Path::new(env!("CARGO_MANIFEST_DIR")) |
| 103 | + .join("..") |
| 104 | + .join("..") |
| 105 | + .join(SKOS_CORE_RELATIVE_PATH) |
| 106 | +} |
| 107 | + |
| 108 | +fn skos_xl_path() -> PathBuf { |
| 109 | + Path::new(env!("CARGO_MANIFEST_DIR")) |
| 110 | + .join("..") |
| 111 | + .join("..") |
| 112 | + .join(SKOS_XL_RELATIVE_PATH) |
| 113 | +} |
0 commit comments