Skip to main content

owl_structural_model/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4//! Typed OWL structural values without an RDF-store dependency.
5
6mod annotation;
7mod axiom;
8mod class_expression;
9mod entity;
10mod error;
11mod literal;
12mod ontology;
13mod patch;
14
15pub use annotation::{Annotation, AnnotationSubject, AnnotationValue, AxiomAnnotations};
16pub use axiom::Axiom;
17pub use class_expression::{ClassExpression, ObjectPropertyExpression};
18pub use entity::{Entity, EntityKind};
19pub use error::StructuralModelError;
20pub use literal::OwlLiteral;
21pub use ontology::{OntologyId, OntologyIdentity};
22pub use patch::{OntologyPatch, OntologyPatchOperation};
23
24#[cfg(test)]
25mod tests {
26    use iri_rfc3987::Iri;
27
28    use super::*;
29
30    fn iri(value: &str) -> Iri<String> {
31        Iri::parse(value).expect("test IRI is valid").into()
32    }
33
34    #[test]
35    fn constructors_preserve_structural_shape() {
36        let axiom = Axiom::sub_class_of(
37            ClassExpression::named(iri("https://example.org/Customer")),
38            ClassExpression::named(iri("https://example.org/Party")),
39        );
40
41        assert!(matches!(axiom, Axiom::SubClassOf { .. }));
42        assert_eq!(Entity::class(iri("https://example.org/Customer")).kind(), EntityKind::Class);
43    }
44
45    #[test]
46    fn invalid_structural_values_fail_at_construction() {
47        let error = ClassExpression::object_union_of(Vec::new()).unwrap_err();
48        assert!(matches!(error, StructuralModelError::InvalidFormat { .. }));
49
50        let error = OwlLiteral::language_tagged("hello", "").unwrap_err();
51        assert!(matches!(error, StructuralModelError::Empty { .. }));
52    }
53
54    #[test]
55    fn ontology_identity_rejects_version_without_name() {
56        let error = OntologyId::try_new(None, Some(iri("https://example.org/v1"))).unwrap_err();
57        assert!(matches!(error, StructuralModelError::InvalidFormat { .. }));
58    }
59
60    /// ```
61    /// use iri_rfc3987::Iri;
62    /// use owl_structural_model::{Axiom, ClassExpression};
63    ///
64    /// let parse = |value: &str| Iri::parse(value).expect("valid IRI").into();
65    /// let axiom = Axiom::sub_class_of(
66    ///     ClassExpression::named(parse("https://example.org/Customer")),
67    ///     ClassExpression::named(parse("https://example.org/Party")),
68    /// );
69    /// assert!(matches!(axiom, Axiom::SubClassOf { .. }));
70    /// ```
71    #[test]
72    fn doctest_anchor() {}
73}