shacl_validation/store/
graph.rs

1use std::path::Path;
2
3use sparql_service::RdfData;
4use srdf::{RDFFormat, ReaderMode, SRDFGraph};
5
6use crate::validate_error::ValidateError;
7
8use super::Store;
9
10pub struct Graph {
11    store: RdfData,
12}
13
14impl Default for Graph {
15    fn default() -> Self {
16        Self {
17            store: RdfData::new(),
18        }
19    }
20}
21
22impl Graph {
23    pub fn new() -> Graph {
24        Graph::default()
25    }
26
27    pub fn from_path(
28        path: &Path,
29        rdf_format: RDFFormat,
30        base: Option<&str>,
31    ) -> Result<Self, ValidateError> {
32        match SRDFGraph::from_path(
33            path,
34            &rdf_format,
35            base,
36            &ReaderMode::default(), // TODO: this should be revisited
37        ) {
38            Ok(store) => Ok(Self {
39                store: RdfData::from_graph(store)?,
40            }),
41            Err(error) => Err(ValidateError::Graph(error)),
42        }
43    }
44
45    pub fn from_graph(graph: SRDFGraph) -> Result<Graph, ValidateError> {
46        Ok(Graph {
47            store: RdfData::from_graph(graph)?,
48        })
49    }
50
51    pub fn from_data(data: RdfData) -> Graph {
52        Graph { store: data }
53    }
54}
55
56impl Store<RdfData> for Graph {
57    fn store(&self) -> &RdfData {
58        &self.store
59    }
60}