Skip to content

Commit

Permalink
fix: write is_closed and boolean format
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoine-Arnaud committed Jun 12, 2024
1 parent 31c56d6 commit 65c9e90
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
35 changes: 17 additions & 18 deletions shacl_ast/src/ast/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ impl Component {
}
}
Self::UniqueLang(value) => {
Self::write_literal(
&Literal::BooleanLiteral(*value),
SH_UNIQUE_LANG_STR,
rdf_node,
rdf,
)?;
Self::write_boolean(*value, SH_UNIQUE_LANG_STR, rdf_node, rdf)?;
}
Self::LanguageIn { langs } => {
langs.iter().try_for_each(|lang| {
Expand Down Expand Up @@ -175,12 +170,7 @@ impl Component {
is_closed,
ignored_properties,
} => {
Self::write_literal(
&Literal::BooleanLiteral(*is_closed),
SH_CLOSED_STR,
rdf_node,
rdf,
)?;
Self::write_boolean(*is_closed, SH_CLOSED_STR, rdf_node, rdf)?;

ignored_properties.iter().try_for_each(|iri| {
Self::write_iri(iri, SH_IGNORED_PROPERTIES_STR, rdf_node, rdf)
Expand Down Expand Up @@ -235,12 +225,7 @@ impl Component {
}

if let Some(value) = qualified_value_shapes_disjoint {
Self::write_literal(
&Literal::BooleanLiteral(*value),
SH_QUALIFIED_MAX_COUNT_STR,
rdf_node,
rdf,
)?;
Self::write_boolean(*value, SH_QUALIFIED_MAX_COUNT_STR, rdf_node, rdf)?;
}
}
}
Expand All @@ -266,6 +251,20 @@ impl Component {
Self::write_term(&RDF::term_s2term(&term), predicate, rdf_node, rdf)
}

fn write_boolean<RDF>(
value: bool,
predicate: &str,
rdf_node: &RDFNode,
rdf: &mut RDF,
) -> Result<(), RDF::Err>
where
RDF: SRDFBuilder,
{
let term = OxTerm::Literal(OxLiteral::from(value));

Self::write_term(&RDF::term_s2term(&term), predicate, rdf_node, rdf)
}

fn write_literal<RDF>(
value: &Literal,
predicate: &str,
Expand Down
14 changes: 12 additions & 2 deletions shacl_ast/src/ast/node_shape.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
component::Component, message_map::MessageMap, severity::Severity, target::Target,
SH_DEACTIVATED_STR, SH_DESCRIPTION_STR, SH_GROUP_STR, SH_INFO_STR, SH_NAME_STR, SH_NODE_SHAPE,
SH_PROPERTY_STR, SH_SEVERITY_STR, SH_VIOLATION_STR, SH_WARNING_STR,
SH_CLOSED_STR, SH_DEACTIVATED_STR, SH_DESCRIPTION_STR, SH_GROUP_STR, SH_INFO_STR, SH_NAME_STR,
SH_NODE_SHAPE, SH_PROPERTY_STR, SH_SEVERITY_STR, SH_VIOLATION_STR, SH_WARNING_STR,
};
use iri_s::iri;
use oxrdf::{Literal as OxLiteral, Term as OxTerm};
Expand Down Expand Up @@ -143,6 +143,16 @@ impl NodeShape {
)?;
}

if self.closed {
let term = OxTerm::Literal(OxLiteral::from(true));

rdf.add_triple(
&RDF::object_as_subject(&self.id).unwrap(),
&RDF::iri_s2iri(&iri!(SH_CLOSED_STR)),
&RDF::term_s2term(&term),
)?;
}

Ok(())
}
}
Expand Down

0 comments on commit 65c9e90

Please sign in to comment.