MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / load_custom_shapes

Function load_custom_shapes

atomic-shacl/src/lib.rs:82–109  ·  view source on GitHub ↗

Only explicitly supplied local bundles can satisfy imports. This function never resolves imports by making network or additional filesystem requests.

(directory: &Path)

Source from the content-addressed store, hash-verified

80/// Only explicitly supplied local bundles can satisfy imports. This function
81/// never resolves imports by making network or additional filesystem requests.
82pub fn load_custom_shapes(directory: &Path) -> Result<Vec<ShapeBundle>, ValidationError> {
83 let entries = match std::fs::read_dir(directory) {
84 Ok(entries) => entries,
85 Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()),
86 Err(error) => return Err(error.into()),
87 };
88 let mut bundles = Vec::new();
89 for entry in entries {
90 let path = entry?.path();
91 if path.extension().is_some_and(|extension| extension == "ttl") && path.is_file() {
92 let path = path.canonicalize()?;
93 let iri = url::Url::from_file_path(&path)
94 .map_err(|_| {
95 ValidationError::Shapes(format!(
96 "cannot form a base IRI for {}",
97 path.display()
98 ))
99 })?
100 .to_string();
101 bundles.push(ShapeBundle {
102 iri,
103 turtle: std::fs::read_to_string(path)?,
104 });
105 }
106 }
107 bundles.sort_by(|a, b| a.iri.cmp(&b.iri));
108 Ok(bundles)
109}
110
111fn term_value(term: &Term) -> String {
112 match term {

Callers 1

runMethod · 0.85

Calls 7

extensionMethod · 0.80
canonicalizeMethod · 0.80
kindMethod · 0.45
pathMethod · 0.45
is_fileMethod · 0.45
pushMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected