Skip to main content

strixonomy_catalog/
lib.rs

1//! Workspace indexing: scan files, parse ontologies, build queryable catalog + Oxigraph store.
2//!
3//! Entry points: [`IndexBuilder`], [`OntologyCatalog`].
4//!
5//! # API stability
6//!
7//! **Pre-1.0:** catalog shapes and method signatures may change until v1.0.
8//! Use [`strixonomy_query::sparql_catalog`] for SPARQL; do not depend on Oxigraph types.
9
10mod builder;
11mod disk_cache;
12mod entity_api;
13mod graph;
14mod incremental;
15pub mod xml_catalog;
16
17pub use builder::{CatalogError, IndexBuilder, OntologyCatalog};
18pub use entity_api::{ClassHierarchy, EntityDetail, SourceHint, SubclassEdge};
19pub use graph::{
20    GraphBuilder, GraphEdge, GraphError, GraphFilters, GraphKind, GraphNode, GraphPayload,
21    GraphRequest,
22};
23pub use incremental::IncrementalStats;
24pub use xml_catalog::{
25    discover_workspace_catalogs, load_workspace_xml_catalogs, load_xml_catalog, parse_xml_catalog,
26    parse_xml_catalog_in_workspace, XmlCatalog, XmlCatalogError,
27};
28
29use serde::Serialize;
30use strixonomy_core::{
31    Annotation, Axiom, Diagnostic, Entity, Import, Namespace, OntologyDocument, ParseStatus,
32};
33
34#[derive(Debug, Clone, Serialize)]
35pub struct CatalogStats {
36    pub ontology_count: usize,
37    pub class_count: usize,
38    pub object_property_count: usize,
39    pub data_property_count: usize,
40    pub annotation_property_count: usize,
41    pub individual_count: usize,
42    pub axiom_count: usize,
43    pub annotation_count: usize,
44    pub triple_count: usize,
45    pub error_count: usize,
46    pub diagnostic_error_count: usize,
47    pub diagnostic_warning_count: usize,
48    pub diagnostic_info_count: usize,
49}
50
51#[derive(Debug, Clone)]
52pub struct OntologyCatalogData {
53    pub documents: Vec<OntologyDocument>,
54    pub entities: Vec<Entity>,
55    pub annotations: Vec<Annotation>,
56    pub axioms: Vec<Axiom>,
57    pub namespaces: Vec<Namespace>,
58    pub imports: Vec<Import>,
59    pub triple_count: usize,
60    pub diagnostics: Vec<Diagnostic>,
61}
62
63impl OntologyCatalogData {
64    pub fn stats(&self) -> CatalogStats {
65        CatalogStats {
66            ontology_count: self.documents.len(),
67            class_count: self
68                .entities
69                .iter()
70                .filter(|e| e.kind == strixonomy_core::EntityKind::Class)
71                .count(),
72            object_property_count: self
73                .entities
74                .iter()
75                .filter(|e| e.kind == strixonomy_core::EntityKind::ObjectProperty)
76                .count(),
77            data_property_count: self
78                .entities
79                .iter()
80                .filter(|e| e.kind == strixonomy_core::EntityKind::DataProperty)
81                .count(),
82            annotation_property_count: self
83                .entities
84                .iter()
85                .filter(|e| e.kind == strixonomy_core::EntityKind::AnnotationProperty)
86                .count(),
87            individual_count: self
88                .entities
89                .iter()
90                .filter(|e| e.kind == strixonomy_core::EntityKind::Individual)
91                .count(),
92            axiom_count: self.axioms.len(),
93            annotation_count: self.annotations.len(),
94            triple_count: self.triple_count,
95            error_count: self
96                .documents
97                .iter()
98                .filter(|d| d.parse_status == ParseStatus::Error)
99                .count(),
100            diagnostic_error_count: self
101                .diagnostics
102                .iter()
103                .filter(|d| d.severity == strixonomy_core::DiagnosticSeverity::Error)
104                .count(),
105            diagnostic_warning_count: self
106                .diagnostics
107                .iter()
108                .filter(|d| d.severity == strixonomy_core::DiagnosticSeverity::Warning)
109                .count(),
110            diagnostic_info_count: self
111                .diagnostics
112                .iter()
113                .filter(|d| d.severity == strixonomy_core::DiagnosticSeverity::Info)
114                .count(),
115        }
116    }
117}