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
use crate::owl::{
    AnnotationAssertion, Axiom, ClassIRI, DataPropertyDomain, ObjectPropertyDomain,
    ObjectPropertyRange, SubClassOf,
};

#[derive(Debug)]
pub struct Class<'a> {
    pub(crate) iri: &'a ClassIRI,
    pub(crate) axioms: Vec<&'a Axiom>,
}

impl<'a> Class<'a> {
    /// Get all annotations asserted with this class
    pub fn annotations(&self) -> Vec<&AnnotationAssertion> {
        self.axioms
            .iter()
            .filter_map(|a| match a {
                Axiom::AnnotationAssertion(a) => Some(a),
                _ => None,
            })
            .collect()
    }

    /// Get all direct super classes of this class
    pub fn super_classes(&self) -> Vec<&'a SubClassOf> {
        self.axioms
            .iter()
            .filter_map(|a| match a {
                Axiom::SubClassOf(sco) => {
                    if sco.subject().is_iri(self.iri.as_iri()) {
                        Some(sco)
                    } else {
                        None
                    }
                }
                _ => None,
            })
            .collect()
    }

    /// Get all DataProperties whose domain contains this class.
    pub fn data_property_domains(&self) -> Vec<&'a DataPropertyDomain> {
        self.axioms
            .iter()
            .filter_map(|a| match a {
                Axiom::DataPropertyDomain(d) => Some(d),
                _ => None,
            })
            .collect()
    }

    /// Get all ObjectProperties whose domain contains this class.
    pub fn object_property_domains(&self) -> Vec<&'a ObjectPropertyDomain> {
        self.axioms
            .iter()
            .filter_map(|a| match a {
                Axiom::ObjectPropertyDomain(d) => Some(d),
                _ => None,
            })
            .collect()
    }

    /// Get all ObjectProperties whose range contains this class.
    pub fn object_property_ranges(&self) -> Vec<&'a ObjectPropertyRange> {
        self.axioms
            .iter()
            .filter_map(|a| match a {
                Axiom::ObjectPropertyRange(r) => Some(r),
                _ => None,
            })
            .collect()
    }

    // pub fn to_owned_class(&self) -> OwnedClass {
    //     OwnedClass {
    //         iri: self.iri.clone(),
    //         axioms: self.axioms.iter().map(|a| (*a).clone()).collect(),
    //     }
    // }
}

// #[derive(Debug)]
// #[wasm_bindgen]
// pub struct OwnedClass {
//     iri: ClassIRI,
//     axioms: Vec<Axiom>,
// }

// #[wasm_bindgen]
// impl OwnedClass {
//     #[wasm_bindgen(getter)]
//     pub fn iri(&self) -> String {
//         self.iri.to_string()
//     }

//     #[wasm_bindgen(getter)]
//     pub fn label(&self) -> Option<String> {
//         self.axioms.iter().find_map(|a| match a {
//             Axiom::AnnotationAssertion(an) => {
//                 if well_known::rdfs_label() == an.0 {
//                     an.2.as_str().map(|s| s.to_string())
//                 } else {
//                     None
//                 }
//             }
//             _ => None,
//         })
//     }
// }