Skip to main content

owl_structural_model/
lib.rs

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