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
use srdf::RDFNode;
use std::fmt::Display;
use crate::{component::Component, target::Target};
#[derive(Debug, Clone)]
pub struct NodeShape {
id: RDFNode,
components: Vec<Component>,
targets: Vec<Target>,
property_shapes: Vec<RDFNode>,
closed: bool,
// ignored_properties: Vec<IriRef>,
// deactivated: bool,
// message: MessageMap,
// severity: Option<Severity>,
// name: MessageMap,
// description: MessageMap,
// SHACL spec says that the values of sh:order should be decimals but in the examples they use integers. `NumericLiteral` also includes doubles.
// order: Option<NumericLiteral>,
// group: Option<RDFNode>,
// source_iri: Option<IriRef>,
}
impl NodeShape {
pub fn new(id: RDFNode) -> Self {
NodeShape {
id,
components: Vec::new(),
targets: Vec::new(),
property_shapes: Vec::new(),
closed: false,
// ignored_properties: Vec::new(),
// deactivated: false,
// message: MessageMap::new(),
// severity: None,
// name: MessageMap::new(),
// description: MessageMap::new(),
// order: None,
// group: None,
// source_iri: None,
}
}
pub fn id(&self) -> RDFNode {
self.id.clone()
}
pub fn with_targets(mut self, targets: Vec<Target>) -> Self {
self.targets = targets;
self
}
pub fn set_targets(&mut self, targets: Vec<Target>) {
self.targets = targets;
}
pub fn with_property_shapes(mut self, property_shapes: Vec<RDFNode>) -> Self {
self.property_shapes = property_shapes;
self
}
pub fn with_components(mut self, components: Vec<Component>) -> Self {
self.components = components;
self
}
pub fn with_closed(mut self, closed: bool) -> Self {
self.closed = closed;
self
}
}
impl Display for NodeShape {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{{")?;
if self.closed {
writeln!(f, " closed: {}", self.closed)?
}
for target in self.targets.iter() {
writeln!(f, " {target}")?
}
for property in self.property_shapes.iter() {
writeln!(f, " Property {property}")?
}
for component in self.components.iter() {
writeln!(f, " {component}")?
}
write!(f, "}}")?;
Ok(())
}
}