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
use super::collector::MatcherHandler;
use crate::error::Error;
use crate::get_vars;
use crate::owl::ObjectPropertyAssertion;
use crate::owl::IRI;
use crate::parser::matcher::RdfMatcher;
use crate::parser::matcher::Value;
use crate::rdf_match;
use std::collections::HashMap;
// const WELL_KNOWN_OBJECT_PROPERTIES: [&str; 2] = [
// well_known::rdfs_subClassOf_str,
// //
// ];
pub(crate) fn push(
matchers: &mut Vec<(RdfMatcher, MatcherHandler)>,
_prefixes: &HashMap<String, String>,
) -> Result<(), Error> {
matchers.push((
rdf_match!("ObjectPropertyAssertion", _prefixes,
// [iri or blank] [iri] [iri or blank]
[+:subject] [*:predicate] [+:object] .
)?,
Box::new(|mstate, o, options| {
let Some(vars) = get_vars!(mstate, subject, predicate, object) else {
return Ok(false);
};
let Value::Iri(iri) = vars.subject else {
return Ok(false);
};
let Ok(subject) = IRI::new(iri) else {
return Ok(false);
};
let Ok(predicate) = vars.predicate.clone().try_into() else {
return Ok(false);
};
match vars.object {
Value::Iri(iri) => {
if let Ok(object) = IRI::new(iri) {
if o.object_property_declaration(&predicate).is_some()
|| options.is_object_prop(&predicate)
{
o.push_axiom(
ObjectPropertyAssertion::new(
predicate.into(),
subject.into(),
object.into(),
vec![],
vec![]
)
.into(),
)
}
}
}
Value::Blank(bn) => {
let mut object = Vec::new();
let mut b = Some(bn);
while let Some(bn) = b {
b = None;
if let Some(super::collector::CollectedBlankNode::Sequence {
first,
rest,
}) = o.get_blank(bn)
{
if let Some(Value::Iri(iri)) = first {
if let Ok(iri) = IRI::new(iri) {
object.push(iri);
b = rest.as_ref();
}
}
}
}
if object.len() > 0 {
o.push_axiom(
ObjectPropertyAssertion::new_with_list(
predicate.into(),
subject.into(),
object,
vec![],
vec![],
)
.into(),
)
}
}
Value::Literal { .. } => {
unreachable!("Branch should be unreachable, as matcher shouldn't match literal objects.")
}
}
Ok(false)
}),
));
Ok(())
}