1use std::{collections::HashMap, fmt::Display};
2
3use crate::shape::Shape;
4use iri_s::IriS;
5use prefixmap::PrefixMap;
6use srdf::RDFNode;
7
8#[derive(Debug, Clone, Default)]
9pub struct Schema {
10 shapes: HashMap<RDFNode, Shape>,
13 prefixmap: PrefixMap,
14 base: Option<IriS>,
15}
16
17impl Schema {
18 pub fn new() -> Schema {
19 Schema::default()
20 }
21
22 pub fn with_prefixmap(mut self, prefixmap: PrefixMap) -> Self {
23 self.prefixmap = prefixmap;
24 self
25 }
26
27 pub fn with_shapes(mut self, shapes: HashMap<RDFNode, Shape>) -> Self {
28 self.shapes = shapes;
29 self
30 }
31
32 pub fn prefix_map(&self) -> PrefixMap {
33 self.prefixmap.clone()
34 }
35
36 pub fn base(&self) -> Option<IriS> {
37 self.base.clone()
38 }
39
40 pub fn iter(&self) -> impl Iterator<Item = (&RDFNode, &Shape)> {
41 self.shapes.iter()
42 }
43
44 pub fn get_shape(&self, sref: &RDFNode) -> Option<&Shape> {
45 self.shapes.get(sref)
46 }
47}
48
49impl Display for Schema {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 for (id, shape) in self.shapes.iter() {
62 writeln!(f, "{id} -> {shape}")?;
63 }
64 Ok(())
65 }
66}