owlish/parser/
object_property_assertions.rs1use super::collector::MatcherHandler;
2use crate::error::Error;
3use crate::get_vars;
4use crate::owl::ObjectPropertyAssertion;
5use crate::owl::IRI;
6use crate::parser::matcher::RdfMatcher;
7use crate::parser::matcher::Value;
8use crate::rdf_match;
9use std::collections::HashMap;
10
11pub(crate) fn push(
17 matchers: &mut Vec<(RdfMatcher, MatcherHandler)>,
18 _prefixes: &HashMap<String, String>,
19) -> Result<(), Error> {
20 matchers.push((
21 rdf_match!("ObjectPropertyAssertion", _prefixes,
22 [+:subject] [*:predicate] [+:object] .
24 )?,
25 Box::new(|mstate, o, options| {
26 let Some(vars) = get_vars!(mstate, subject, predicate, object) else {
27 return Ok(false);
28 };
29 let Value::Iri(iri) = vars.subject else {
30 return Ok(false);
31 };
32 let Ok(subject) = IRI::new(iri) else {
33 return Ok(false);
34 };
35 let Ok(predicate) = vars.predicate.clone().try_into() else {
36 return Ok(false);
37 };
38
39 match vars.object {
40 Value::Iri(iri) => {
41 if let Ok(object) = IRI::new(iri) {
42 if o.object_property_declaration(&predicate).is_some()
43 || options.is_object_prop(&predicate)
44 {
45 o.push_axiom(
46 ObjectPropertyAssertion::new(
47 predicate.into(),
48 subject.into(),
49 object.into(),
50 vec![],
51 vec![]
52 )
53 .into(),
54 )
55 }
56 }
57 }
58 Value::Blank(bn) => {
59 let mut object = Vec::new();
60 let mut b = Some(bn);
61 while let Some(bn) = b {
62 b = None;
63 if let Some(super::collector::CollectedBlankNode::Sequence {
64 first,
65 rest,
66 }) = o.get_blank(bn)
67 {
68 if let Some(Value::Iri(iri)) = first {
69 if let Ok(iri) = IRI::new(iri) {
70 object.push(iri);
71 b = rest.as_ref();
72 }
73 }
74 }
75 }
76 if object.len() > 0 {
77 o.push_axiom(
78 ObjectPropertyAssertion::new_with_list(
79 predicate.into(),
80 subject.into(),
81 object,
82 vec![],
83 vec![],
84 )
85 .into(),
86 )
87 }
88 }
89 Value::Literal { .. } => {
90 unreachable!("Branch should be unreachable, as matcher shouldn't match literal objects.")
91 }
92 }
93 Ok(false)
94 }),
95 ));
96 Ok(())
97}