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
use std::collections::HashMap;

use crate::{error::Error, owl::Declaration, parser::matcher::RdfMatcher, rdf_match};

use super::collector::{get_iri_var, MatcherHandler};

/// declarations
/// https://www.w3.org/TR/2012/REC-owl2-mapping-to-rdf-20121211/#Analyzing_Declarations
/// https://www.w3.org/TR/2012/REC-owl2-mapping-to-rdf-20121211/#Parsing_of_Axioms
pub(crate) fn match_declarations(
    matchers: &mut Vec<(RdfMatcher, MatcherHandler)>,
    prefixes: &HashMap<String, String>,
) -> Result<(), Error> {
    matchers.push((
        rdf_match!("OntologyIRI", prefixes, [*:subject] [rdf:type] [owl:Ontology] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.set_iri(iri);
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("Class", prefixes, [*:subject] [rdf:type] [owl:Class] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::Class(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("Datatype",prefixes, [*:subject] [rdf:type] [rdfs:Datatype] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::Datatype(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("ObjectProperty", prefixes, [*:subject] [rdf:type] [owl:ObjectProperty] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::ObjectProperty(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("DataProperty", prefixes, [*:subject] [rdf:type] [owl:DatatypeProperty] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::DataProperty(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("AnnotationProperty", prefixes, [*:subject] [rdf:type] [owl:AnnotationProperty] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::AnnotationProperty(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    matchers.push((
        rdf_match!("NamedIndividual", prefixes, [*:subject] [rdf:type] [owl:NamedIndividual] .)?,
        Box::new(|mstate, o, _| {
            if let Some(iri) = get_iri_var("subject", mstate)? {
                o.push_declaration(Declaration::NamedIndividual(iri.into(), vec![]));
            }
            Ok(true)
        }),
    ));
    Ok(())
}