|
|
@ -31,7 +31,7 @@ use std::io::BufReader; |
|
|
|
/// >>> str(store)
|
|
|
|
/// >>> str(store)
|
|
|
|
/// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n'
|
|
|
|
/// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n'
|
|
|
|
#[pyclass(name = "SledStore", module = "oxigraph")] |
|
|
|
#[pyclass(name = "SledStore", module = "oxigraph")] |
|
|
|
#[text_signature = "(path = None)"] |
|
|
|
#[pyo3(text_signature = "(path = None)")] |
|
|
|
#[derive(Clone)] |
|
|
|
#[derive(Clone)] |
|
|
|
pub struct PySledStore { |
|
|
|
pub struct PySledStore { |
|
|
|
inner: SledStore, |
|
|
|
inner: SledStore, |
|
|
@ -61,7 +61,7 @@ impl PySledStore { |
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> list(store)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
#[text_signature = "($self, quad)"] |
|
|
|
#[pyo3(text_signature = "($self, quad)")] |
|
|
|
fn add(&self, quad: &PyQuad) -> PyResult<()> { |
|
|
|
fn add(&self, quad: &PyQuad) -> PyResult<()> { |
|
|
|
self.inner.insert(quad).map_err(map_io_err) |
|
|
|
self.inner.insert(quad).map_err(map_io_err) |
|
|
|
} |
|
|
|
} |
|
|
@ -78,7 +78,7 @@ impl PySledStore { |
|
|
|
/// >>> store.remove(quad)
|
|
|
|
/// >>> store.remove(quad)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// []
|
|
|
|
/// []
|
|
|
|
#[text_signature = "($self, quad)"] |
|
|
|
#[pyo3(text_signature = "($self, quad)")] |
|
|
|
fn remove(&self, quad: &PyQuad) -> PyResult<()> { |
|
|
|
fn remove(&self, quad: &PyQuad) -> PyResult<()> { |
|
|
|
self.inner.remove(quad).map_err(map_io_err) |
|
|
|
self.inner.remove(quad).map_err(map_io_err) |
|
|
|
} |
|
|
|
} |
|
|
@ -101,7 +101,7 @@ impl PySledStore { |
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> list(store.quads_for_pattern(NamedNode('http://example.com'), None, None, None))
|
|
|
|
/// >>> list(store.quads_for_pattern(NamedNode('http://example.com'), None, None, None))
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
#[text_signature = "($self, subject, predicate, object, graph_name = None)"] |
|
|
|
#[pyo3(text_signature = "($self, subject, predicate, object, graph_name = None)")] |
|
|
|
fn quads_for_pattern( |
|
|
|
fn quads_for_pattern( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
subject: &PyAny, |
|
|
|
subject: &PyAny, |
|
|
@ -156,7 +156,9 @@ impl PySledStore { |
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
|
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
|
|
|
|
/// >>> store.query('ASK { ?s ?p ?o }')
|
|
|
|
/// >>> store.query('ASK { ?s ?p ?o }')
|
|
|
|
/// True
|
|
|
|
/// True
|
|
|
|
#[text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)"] |
|
|
|
#[pyo3(
|
|
|
|
|
|
|
|
text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)" |
|
|
|
|
|
|
|
)] |
|
|
|
#[args(
|
|
|
|
#[args(
|
|
|
|
query, |
|
|
|
query, |
|
|
|
"*", |
|
|
|
"*", |
|
|
@ -214,7 +216,7 @@ impl PySledStore { |
|
|
|
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
|
|
|
|
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
|
|
|
|
/// >>> list(store)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// []
|
|
|
|
/// []
|
|
|
|
#[text_signature = "($self, update)"] |
|
|
|
#[pyo3(text_signature = "($self, update)")] |
|
|
|
fn update(&self, update: &str) -> PyResult<()> { |
|
|
|
fn update(&self, update: &str) -> PyResult<()> { |
|
|
|
self.inner.update(update).map_err(map_evaluation_error) |
|
|
|
self.inner.update(update).map_err(map_evaluation_error) |
|
|
|
} |
|
|
|
} |
|
|
@ -249,7 +251,7 @@ impl PySledStore { |
|
|
|
/// >>> store.load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
|
|
|
|
/// >>> store.load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
|
|
|
|
/// >>> list(store)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
/// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
|
|
|
|
#[text_signature = "($self, data, /, mime_type, *, base_iri = None, to_graph = None)"] |
|
|
|
#[pyo3(text_signature = "($self, data, /, mime_type, *, base_iri = None, to_graph = None)")] |
|
|
|
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")] |
|
|
|
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")] |
|
|
|
fn load( |
|
|
|
fn load( |
|
|
|
&self, |
|
|
|
&self, |
|
|
@ -319,7 +321,7 @@ impl PySledStore { |
|
|
|
/// >>> store.dump(output, "text/turtle", from_graph=NamedNode("http://example.com/g"))
|
|
|
|
/// >>> store.dump(output, "text/turtle", from_graph=NamedNode("http://example.com/g"))
|
|
|
|
/// >>> output.getvalue()
|
|
|
|
/// >>> output.getvalue()
|
|
|
|
/// b'<http://example.com> <http://example.com/p> "1" .\n'
|
|
|
|
/// b'<http://example.com> <http://example.com/p> "1" .\n'
|
|
|
|
#[text_signature = "($self, output, /, mime_type, *, from_graph = None)"] |
|
|
|
#[pyo3(text_signature = "($self, output, /, mime_type, *, from_graph = None)")] |
|
|
|
#[args(output, mime_type, "*", from_graph = "None")] |
|
|
|
#[args(output, mime_type, "*", from_graph = "None")] |
|
|
|
fn dump(&self, output: PyObject, mime_type: &str, from_graph: Option<&PyAny>) -> PyResult<()> { |
|
|
|
fn dump(&self, output: PyObject, mime_type: &str, from_graph: Option<&PyAny>) -> PyResult<()> { |
|
|
|
let from_graph_name = if let Some(graph_name) = from_graph { |
|
|
|
let from_graph_name = if let Some(graph_name) = from_graph { |
|
|
@ -363,7 +365,7 @@ impl PySledStore { |
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
|
|
|
|
/// >>> list(store.named_graphs())
|
|
|
|
/// >>> list(store.named_graphs())
|
|
|
|
/// [<NamedNode value=http://example.com/g>]
|
|
|
|
/// [<NamedNode value=http://example.com/g>]
|
|
|
|
#[text_signature = "($self)"] |
|
|
|
#[pyo3(text_signature = "($self)")] |
|
|
|
fn named_graphs(&self) -> GraphNameIter { |
|
|
|
fn named_graphs(&self) -> GraphNameIter { |
|
|
|
GraphNameIter { |
|
|
|
GraphNameIter { |
|
|
|
inner: self.inner.named_graphs(), |
|
|
|
inner: self.inner.named_graphs(), |
|
|
@ -380,7 +382,7 @@ impl PySledStore { |
|
|
|
/// >>> store.add_graph(NamedNode('http://example.com/g'))
|
|
|
|
/// >>> store.add_graph(NamedNode('http://example.com/g'))
|
|
|
|
/// >>> list(store.named_graphs())
|
|
|
|
/// >>> list(store.named_graphs())
|
|
|
|
/// [<NamedNode value=http://example.com/g>]
|
|
|
|
/// [<NamedNode value=http://example.com/g>]
|
|
|
|
#[text_signature = "($self, graph_name)"] |
|
|
|
#[pyo3(text_signature = "($self, graph_name)")] |
|
|
|
fn add_graph(&self, graph_name: &PyAny) -> PyResult<()> { |
|
|
|
fn add_graph(&self, graph_name: &PyAny) -> PyResult<()> { |
|
|
|
match PyGraphNameRef::try_from(graph_name)? { |
|
|
|
match PyGraphNameRef::try_from(graph_name)? { |
|
|
|
PyGraphNameRef::DefaultGraph => Ok(()), |
|
|
|
PyGraphNameRef::DefaultGraph => Ok(()), |
|
|
@ -407,7 +409,7 @@ impl PySledStore { |
|
|
|
/// >>> store.remove_graph(NamedNode('http://example.com/g'))
|
|
|
|
/// >>> store.remove_graph(NamedNode('http://example.com/g'))
|
|
|
|
/// >>> list(store)
|
|
|
|
/// >>> list(store)
|
|
|
|
/// []
|
|
|
|
/// []
|
|
|
|
#[text_signature = "($self, graph_name)"] |
|
|
|
#[pyo3(text_signature = "($self, graph_name)")] |
|
|
|
fn remove_graph(&self, graph_name: &PyAny) -> PyResult<()> { |
|
|
|
fn remove_graph(&self, graph_name: &PyAny) -> PyResult<()> { |
|
|
|
match PyGraphNameRef::try_from(graph_name)? { |
|
|
|
match PyGraphNameRef::try_from(graph_name)? { |
|
|
|
PyGraphNameRef::DefaultGraph => self.inner.clear_graph(GraphNameRef::DefaultGraph), |
|
|
|
PyGraphNameRef::DefaultGraph => self.inner.clear_graph(GraphNameRef::DefaultGraph), |
|
|
|