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 b7de570
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
26 changes: 20 additions & 6 deletions shacl_ast/src/ast/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ impl Component {
}
}
Self::UniqueLang(value) => {
Self::write_literal(
&Literal::BooleanLiteral(*value),
Self::write_boolean(
*value,
SH_UNIQUE_LANG_STR,
rdf_node,
rdf,
Expand Down Expand Up @@ -175,8 +175,8 @@ impl Component {
is_closed,
ignored_properties,
} => {
Self::write_literal(
&Literal::BooleanLiteral(*is_closed),
Self::write_boolean(
*is_closed,
SH_CLOSED_STR,
rdf_node,
rdf,
Expand Down Expand Up @@ -235,8 +235,8 @@ impl Component {
}

if let Some(value) = qualified_value_shapes_disjoint {
Self::write_literal(
&Literal::BooleanLiteral(*value),
Self::write_boolean(
*value,
SH_QUALIFIED_MAX_COUNT_STR,
rdf_node,
rdf,
Expand Down Expand Up @@ -266,6 +266,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
16 changes: 11 additions & 5 deletions shacl_ast/src/ast/node_shape.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
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,
};
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};
use iri_s::iri;
use oxrdf::{Literal as OxLiteral, Term as OxTerm};
use srdf::{RDFNode, SRDFBuilder};
Expand Down Expand Up @@ -143,6 +139,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 b7de570

Please sign in to comment.