vowl-wasm 0.1.1

VOWL ontology visualisation engine in Rust/WASM: OWL parsing, force-directed layout (Barnes-Hut, SIMD), and rendering data for web explorers. A clean-room reimplementation of the WebVOWL visual notation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//! OWL Ontology parsing and representation
//!
//! This module handles parsing OWL ontologies in JSON format and markdown format,
//! converting them into internal graph representations.

#[cfg(feature = "markdown-ontology")]
#[cfg_attr(docsrs, doc(cfg(feature = "markdown-ontology")))]
pub mod loader;
#[cfg(feature = "markdown-ontology")]
#[cfg_attr(docsrs, doc(cfg(feature = "markdown-ontology")))]
pub mod markdown_parser;
pub mod model;
pub mod owl2_validator;
pub mod parser;

use crate::Result;
use serde::{Deserialize, Serialize};

/// Trait for parsing OWL ontology data
#[cfg_attr(test, mockall::automock)]
pub trait OntologyParser {
    /// Parse ontology from JSON string
    fn parse(&self, json: &str) -> Result<OntologyData>;

    /// Validate ontology structure
    fn validate(&self, data: &OntologyData) -> Result<()>;
}

/// Represents parsed OWL ontology data
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OntologyData {
    /// Ontology metadata
    pub metadata: OntologyMetadata,

    /// Class nodes in the ontology
    pub classes: Vec<ClassNode>,

    /// Properties (object and datatype properties)
    pub properties: Vec<Property>,

    /// Namespace definitions
    pub namespaces: Vec<Namespace>,
}

/// Ontology metadata
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OntologyMetadata {
    /// Ontology IRI
    pub iri: String,

    /// Version information
    pub version: Option<String>,

    /// Title/label
    pub title: Option<String>,

    /// Description
    pub description: Option<String>,
}

/// Represents an OWL class
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ClassNode {
    /// Unique identifier
    pub id: String,

    /// IRI of the class
    pub iri: String,

    /// Label for display
    pub label: String,

    /// Class type (e.g., owl:Class, rdfs:Class)
    pub class_type: String,

    /// Equivalent classes
    pub equivalent: Vec<String>,

    /// Attributes for visualization
    pub attributes: ClassAttributes,

    /// Ontology metadata from Phase 2 parser
    pub ontology_meta: Option<ClassOntologyMetadata>,
}

/// Visual and semantic attributes for a class
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ClassAttributes {
    /// Whether this is an external class
    pub external: bool,

    /// Individuals count
    pub individuals: Option<usize>,

    /// Additional properties
    pub properties: std::collections::HashMap<String, String>,
}

/// Represents an OWL property (object or datatype property)
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Property {
    /// Unique identifier
    pub id: String,

    /// IRI of the property
    pub iri: String,

    /// Label for display
    pub label: String,

    /// Property type
    pub property_type: PropertyType,

    /// Domain class ID
    pub domain: String,

    /// Range class/datatype ID
    pub range: String,

    /// Property characteristics
    pub characteristics: PropertyCharacteristics,

    /// Inverse of this property (Phase 11)
    pub inverse_of: Option<String>,

    /// Properties equivalent to this one (Phase 11)
    pub equivalent_to: Vec<String>,

    /// Properties disjoint with this one (Phase 11)
    pub disjoint_with: Vec<String>,
}

/// Type of OWL property
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum PropertyType {
    /// Object property
    ObjectProperty,

    /// Datatype property
    DatatypeProperty,

    /// Annotation property
    AnnotationProperty,

    /// Special property (e.g., subclass, disjoint)
    SpecialProperty(String),
}

/// Property characteristics (functional, transitive, etc.)
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct PropertyCharacteristics {
    /// Is functional
    pub functional: bool,

    /// Is inverse functional
    pub inverse_functional: bool,

    /// Is transitive
    pub transitive: bool,

    /// Is symmetric
    pub symmetric: bool,

    /// Cardinality constraints
    pub cardinality: Option<Cardinality>,
}

/// Cardinality constraint
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Cardinality {
    /// Minimum cardinality
    pub min: Option<u32>,

    /// Maximum cardinality
    pub max: Option<u32>,

    /// Exact cardinality
    pub exact: Option<u32>,
}

/// Namespace definition
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Namespace {
    /// Prefix
    pub prefix: String,

    /// IRI
    pub iri: String,
}

/// Class-level ontology metadata (from Phase 2 OWL extractor)
/// This is separate from OntologyMetadata which represents ontology header data
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ClassOntologyMetadata {
    /// Term identifier
    pub term_id: String,

    /// Preferred term name
    pub preferred_term: Option<String>,

    /// Domain/category
    pub domain: Option<String>,

    /// Maturity level
    pub maturity: Option<String>,

    /// Status (active, deprecated, etc.)
    pub status: Option<String>,

    /// Authority/confidence score
    pub authority_score: Option<f32>,
}

/// Domain enumeration for the multi-ontology architecture
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Domain {
    /// Artificial Intelligence domain (ai:)
    #[serde(rename = "ai")]
    AI,

    /// Metaverse and Virtual Worlds domain (mv:)
    #[serde(rename = "mv")]
    Metaverse,

    /// Telecollaboration domain (tc:)
    #[serde(rename = "tc")]
    Telecollaboration,

    /// Robotics and Autonomous Systems domain (rb:)
    #[serde(rename = "rb")]
    Robotics,

    /// Disruptive Technologies domain (dt:)
    #[serde(rename = "dt")]
    DisruptiveTech,

    /// Blockchain and Cryptography domain (bc:)
    #[serde(rename = "bc")]
    Blockchain,
}

impl Domain {
    /// Parse domain from string prefix
    pub fn from_prefix(prefix: &str) -> Option<Self> {
        match prefix.to_lowercase().as_str() {
            "ai" | "aigo" => Some(Domain::AI),
            "mv" => Some(Domain::Metaverse),
            "tc" => Some(Domain::Telecollaboration),
            "rb" => Some(Domain::Robotics),
            "dt" => Some(Domain::DisruptiveTech),
            "bc" => Some(Domain::Blockchain),
            _ => None,
        }
    }

    /// Get the namespace prefix for this domain
    pub fn prefix(&self) -> &'static str {
        match self {
            Domain::AI => "ai",
            Domain::Metaverse => "mv",
            Domain::Telecollaboration => "tc",
            Domain::Robotics => "rb",
            Domain::DisruptiveTech => "dt",
            Domain::Blockchain => "bc",
        }
    }

    /// Get the base URI for this domain
    pub fn base_uri(&self) -> &'static str {
        match self {
            Domain::AI => "http://narrativegoldmine.com/ai#",
            Domain::Metaverse => "http://narrativegoldmine.com/metaverse#",
            Domain::Telecollaboration => "http://narrativegoldmine.com/telecollaboration#",
            Domain::Robotics => "http://narrativegoldmine.com/robotics#",
            Domain::DisruptiveTech => "http://narrativegoldmine.com/disruptive-tech#",
            Domain::Blockchain => "http://narrativegoldmine.com/blockchain#",
        }
    }
}

/// Ontology block from markdown format (new standardized format)
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OntologyBlock {
    /// Full IRI (e.g. `http://narrativegoldmine.com/ai#LargeLanguageModel`)
    pub iri: String,

    /// Term identifier (e.g., "AI-0850")
    pub term_id: String,

    /// Preferred term name
    pub preferred_term: String,

    /// Domain classification
    pub domain: Domain,

    /// Core properties from Identification section
    pub core_properties: std::collections::HashMap<String, String>,

    /// Domain-specific extension properties (e.g., ai:*, bc:*)
    pub extension_properties: std::collections::HashMap<String, String>,

    /// OWL axioms in functional syntax (if present)
    pub owl_axioms: Option<String>,

    /// Whether this is publicly accessible
    pub is_public: bool,

    /// Ontology metadata
    pub metadata: ClassOntologyMetadata,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ontology_data_creation() {
        let metadata = OntologyMetadata {
            iri: "http://example.org/ontology".to_string(),
            version: Some("1.0".to_string()),
            title: Some("Test Ontology".to_string()),
            description: None,
        };

        let data = OntologyData {
            metadata,
            classes: vec![],
            properties: vec![],
            namespaces: vec![],
        };

        assert_eq!(data.classes.len(), 0);
        assert_eq!(data.metadata.iri, "http://example.org/ontology");
    }

    #[test]
    fn test_class_node_with_attributes() {
        let class = ClassNode {
            id: "class1".to_string(),
            iri: "http://example.org/Class1".to_string(),
            label: "Class 1".to_string(),
            class_type: "owl:Class".to_string(),
            equivalent: vec![],
            attributes: ClassAttributes {
                external: false,
                individuals: Some(10),
                properties: std::collections::HashMap::new(),
            },
            ontology_meta: None,
        };

        assert_eq!(class.attributes.individuals, Some(10));
        assert!(!class.attributes.external);
    }

    #[test]
    fn test_class_ontology_metadata() {
        let meta = ClassOntologyMetadata {
            term_id: "term1".to_string(),
            preferred_term: Some("PreferredTerm".to_string()),
            domain: Some("TechnologyDomain".to_string()),
            maturity: Some("Stable".to_string()),
            status: Some("Active".to_string()),
            authority_score: Some(0.95),
        };

        assert_eq!(meta.term_id, "term1");
        assert_eq!(meta.preferred_term, Some("PreferredTerm".to_string()));
        assert_eq!(meta.authority_score, Some(0.95));
    }

    #[test]
    fn test_property_with_characteristics() {
        let prop = Property {
            id: "prop1".to_string(),
            iri: "http://example.org/prop1".to_string(),
            label: "Property 1".to_string(),
            property_type: PropertyType::ObjectProperty,
            domain: "class1".to_string(),
            range: "class2".to_string(),
            characteristics: PropertyCharacteristics {
                functional: true,
                transitive: false,
                symmetric: false,
                inverse_functional: false,
                cardinality: Some(Cardinality {
                    min: Some(1),
                    max: Some(1),
                    exact: None,
                }),
            },
            inverse_of: None,
            equivalent_to: vec![],
            disjoint_with: vec![],
        };

        assert!(prop.characteristics.functional);
        assert_eq!(
            prop.characteristics.cardinality.as_ref().unwrap().min,
            Some(1)
        );
    }
}