Only explicitly supplied local bundles can satisfy imports. This function never resolves imports by making network or additional filesystem requests.
(directory: &Path)
| 80 | /// Only explicitly supplied local bundles can satisfy imports. This function |
| 81 | /// never resolves imports by making network or additional filesystem requests. |
| 82 | pub 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 | |
| 111 | fn term_value(term: &Term) -> String { |
| 112 | match term { |