Skip to main content

ontocore_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 [`ontocore_query::sparql_catalog`] for SPARQL; do not depend on Oxigraph types.
9
10mod builder;
11mod disk_cache;
12mod entity_api;
13mod graph;
14mod incremental;
15
16pub use builder::{CatalogError, IndexBuilder, OntologyCatalog};
17pub use entity_api::{ClassHierarchy, EntityDetail, SourceHint, SubclassEdge};
18pub use graph::{
19    GraphBuilder, GraphEdge, GraphError, GraphFilters, GraphKind, GraphNode, GraphPayload,
20    GraphRequest,
21};
22pub use incremental::IncrementalStats;
23
24use ontocore_core::{
25    Annotation, Axiom, Diagnostic, Entity, Import, Namespace, OntologyDocument, ParseStatus,
26};
27use serde::Serialize;
28
29#[derive(Debug, Clone, Serialize)]
30pub struct CatalogStats {
31    pub ontology_count: usize,
32    pub class_count: usize,
33    pub object_property_count: usize,
34    pub data_property_count: usize,
35    pub annotation_property_count: usize,
36    pub individual_count: usize,
37    pub axiom_count: usize,
38    pub annotation_count: usize,
39    pub triple_count: usize,
40    pub error_count: usize,
41    pub diagnostic_error_count: usize,
42    pub diagnostic_warning_count: usize,
43    pub diagnostic_info_count: usize,
44}
45
46#[derive(Debug, Clone)]
47pub struct OntologyCatalogData {
48    pub documents: Vec<OntologyDocument>,
49    pub entities: Vec<Entity>,
50    pub annotations: Vec<Annotation>,
51    pub axioms: Vec<Axiom>,
52    pub namespaces: Vec<Namespace>,
53    pub imports: Vec<Import>,
54    pub triple_count: usize,
55    pub diagnostics: Vec<Diagnostic>,
56}
57
58impl OntologyCatalogData {
59    pub fn stats(&self) -> CatalogStats {
60        CatalogStats {
61            ontology_count: self.documents.len(),
62            class_count: self
63                .entities
64                .iter()
65                .filter(|e| e.kind == ontocore_core::EntityKind::Class)
66                .count(),
67            object_property_count: self
68                .entities
69                .iter()
70                .filter(|e| e.kind == ontocore_core::EntityKind::ObjectProperty)
71                .count(),
72            data_property_count: self
73                .entities
74                .iter()
75                .filter(|e| e.kind == ontocore_core::EntityKind::DataProperty)
76                .count(),
77            annotation_property_count: self
78                .entities
79                .iter()
80                .filter(|e| e.kind == ontocore_core::EntityKind::AnnotationProperty)
81                .count(),
82            individual_count: self
83                .entities
84                .iter()
85                .filter(|e| e.kind == ontocore_core::EntityKind::Individual)
86                .count(),
87            axiom_count: self.axioms.len(),
88            annotation_count: self.annotations.len(),
89            triple_count: self.triple_count,
90            error_count: self
91                .documents
92                .iter()
93                .filter(|d| d.parse_status == ParseStatus::Error)
94                .count(),
95            diagnostic_error_count: self
96                .diagnostics
97                .iter()
98                .filter(|d| d.severity == ontocore_core::DiagnosticSeverity::Error)
99                .count(),
100            diagnostic_warning_count: self
101                .diagnostics
102                .iter()
103                .filter(|d| d.severity == ontocore_core::DiagnosticSeverity::Warning)
104                .count(),
105            diagnostic_info_count: self
106                .diagnostics
107                .iter()
108                .filter(|d| d.severity == ontocore_core::DiagnosticSeverity::Info)
109                .count(),
110        }
111    }
112}