Fixes pyoxigraph type documentation

pull/258/head
Tpt 2 years ago committed by Thomas Tanon
parent 992137441f
commit 63412792af
  1. 6
      python/src/io.rs
  2. 23
      python/src/model.rs
  3. 8
      python/src/sparql.rs
  4. 24
      python/src/store.rs

@ -117,7 +117,7 @@ pub fn parse(
/// >>> output.getvalue()
/// b'<http://example.com> <http://example.com/p> "1" .\n'
#[pyfunction]
#[pyo3(text_signature = "(input, output, /, mime_type, *, base_iri = None)")]
#[pyo3(text_signature = "(input, output, /, mime_type)")]
pub fn serialize(input: &PyAny, output: PyObject, mime_type: &str, py: Python<'_>) -> PyResult<()> {
let output = if let Ok(path) = output.extract::<&str>(py) {
PyWritable::from_file(path, py)
@ -155,7 +155,7 @@ pub fn serialize(input: &PyAny, output: PyObject, mime_type: &str, py: Python<'_
}
}
#[pyclass(name = "TripleReader", module = "oxigraph")]
#[pyclass(name = "TripleReader")]
pub struct PyTripleReader {
inner: TripleReader<PyReadable>,
}
@ -176,7 +176,7 @@ impl PyTripleReader {
}
}
#[pyclass(name = "QuadReader", module = "oxigraph")]
#[pyclass(name = "QuadReader")]
pub struct PyQuadReader {
inner: QuadReader<PyReadable>,
}

@ -19,7 +19,7 @@ use std::vec::IntoIter;
///
/// >>> str(NamedNode('http://example.com'))
/// '<http://example.com>'
#[pyclass(name = "NamedNode", module = "oxigraph")]
#[pyclass(name = "NamedNode")]
#[pyo3(text_signature = "(value)")]
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct PyNamedNode {
@ -121,7 +121,7 @@ impl PyNamedNode {
///
/// >>> str(BlankNode('ex'))
/// '_:ex'
#[pyclass(name = "BlankNode", module = "oxigraph")]
#[pyclass(name = "BlankNode")]
#[pyo3(text_signature = "(value)")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyBlankNode {
@ -234,7 +234,7 @@ impl PyBlankNode {
/// '"example"@en'
/// >>> str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer')))
/// '"11"^^<http://www.w3.org/2001/XMLSchema#integer>'
#[pyclass(name = "Literal", module = "oxigraph")]
#[pyclass(name = "Literal")]
#[pyo3(text_signature = "(value, *, datatype = None, language = None)")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyLiteral {
@ -353,7 +353,8 @@ impl PyLiteral {
}
/// The RDF `default graph name <https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph>`_.
#[pyclass(name = "DefaultGraph", module = "oxigraph")]
#[pyclass(name = "DefaultGraph")]
#[pyo3(text_signature = "()")]
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct PyDefaultGraph {}
@ -531,7 +532,7 @@ impl IntoPy<PyObject> for PyTerm {
/// A triple could also be easily destructed into its components:
///
/// >>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))
#[pyclass(name = "Triple", module = "oxigraph")]
#[pyclass(name = "Triple")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[pyo3(text_signature = "(subject, predicate, object)")]
pub struct PyTriple {
@ -694,8 +695,8 @@ impl IntoPy<PyObject> for PyGraphName {
/// :type predicate: NamedNode
/// :param object: the quad object.
/// :type object: NamedNode or BlankNode or Literal or Triple
/// :param graph: the quad graph name. If not present, the default graph is assumed.
/// :type graph: NamedNode or BlankNode or DefaultGraph or None, optional
/// :param graph_name: the quad graph name. If not present, the default graph is assumed.
/// :type graph_name: NamedNode or BlankNode or DefaultGraph or None, optional
///
/// The :py:func:`str` function provides a serialization compatible with NTriples, Turtle, and SPARQL:
///
@ -708,7 +709,7 @@ impl IntoPy<PyObject> for PyGraphName {
/// A quad could also be easily destructed into its components:
///
/// >>> (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))
#[pyclass(name = "Quad", module = "oxigraph")]
#[pyclass(name = "Quad")]
#[pyo3(text_signature = "(subject, predicate, object, graph_name = None)")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyQuad {
@ -868,7 +869,7 @@ impl PyQuad {
///
/// >>> str(Variable('foo'))
/// '?foo'
#[pyclass(name = "Variable", module = "oxigraph")]
#[pyclass(name = "Variable")]
#[pyo3(text_signature = "(value)")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyVariable {
@ -1182,7 +1183,7 @@ fn triple_repr(triple: TripleRef<'_>, buffer: &mut String) {
buffer.push('>');
}
#[pyclass(module = "oxigraph")]
#[pyclass]
pub struct TripleComponentsIter {
inner: IntoIter<Term>,
}
@ -1198,7 +1199,7 @@ impl TripleComponentsIter {
}
}
#[pyclass(module = "oxigraph")]
#[pyclass]
pub struct QuadComponentsIter {
inner: IntoIter<Option<Term>>,
}

@ -85,7 +85,7 @@ pub fn query_results_to_python(py: Python<'_>, results: QueryResults) -> PyResul
/// >>> s, p, o = solution
/// >>> s
/// <NamedNode value=http://example.com>
#[pyclass(unsendable, name = "QuerySolution", module = "oxigraph")]
#[pyclass(unsendable, name = "QuerySolution")]
pub struct PyQuerySolution {
inner: QuerySolution,
}
@ -136,7 +136,7 @@ impl PyQuerySolution {
}
}
#[pyclass(module = "oxigraph")]
#[pyclass]
pub struct SolutionValueIter {
inner: IntoIter<Option<Term>>,
}
@ -158,7 +158,7 @@ impl SolutionValueIter {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }'))
/// [<QuerySolution s=<NamedNode value=http://example.com>>]
#[pyclass(unsendable, name = "QuerySolutions", module = "oxigraph")]
#[pyclass(unsendable, name = "QuerySolutions")]
pub struct PyQuerySolutions {
inner: QuerySolutionIter,
}
@ -198,7 +198,7 @@ impl PyQuerySolutions {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> list(store.query('CONSTRUCT WHERE { ?s ?p ?o }'))
/// [<Triple 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>>>]
#[pyclass(unsendable, name = "QueryTriples", module = "oxigraph")]
#[pyclass(unsendable, name = "QueryTriples")]
pub struct PyQueryTriples {
inner: QueryTripleIter,
}

@ -23,7 +23,7 @@ use pyo3::{Py, PyRef};
/// :param path: the path of the directory in which the store should read and write its data. If the directory does not exist, it is created.
/// If no directory is provided a temporary one is created and removed when the Python garbage collector removes the store.
/// In this case, the store data are kept in memory and never written on disk.
/// :type path: str or None, optional.
/// :type path: str or None, optional
/// :raises IOError: if the target directory contains invalid data or could not be accessed.
///
/// The :py:func:`str` function provides a serialization of the store in NQuads:
@ -32,7 +32,7 @@ use pyo3::{Py, PyRef};
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
/// >>> str(store)
/// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n'
#[pyclass(name = "Store", module = "oxigraph")]
#[pyclass(name = "Store")]
#[pyo3(text_signature = "(path = None)")]
#[derive(Clone)]
pub struct PyStore {
@ -101,8 +101,8 @@ impl PyStore {
/// :type predicate: NamedNode or None
/// :param object: the quad object or :py:const:`None` to match everything.
/// :type object: NamedNode or BlankNode or Literal or None
/// :param graph: the quad graph name. To match only the default graph, use :py:class:`DefaultGraph`. To match everything use :py:const:`None`.
/// :type graph: NamedNode or BlankNode or DefaultGraph or None
/// :param graph_name: the quad graph name. To match only the default graph, use :py:class:`DefaultGraph`. To match everything use :py:const:`None`.
/// :type graph_name: NamedNode or BlankNode or DefaultGraph or None
/// :return: an iterator of the quads matching the pattern.
/// :rtype: iter(Quad)
/// :raises IOError: if an I/O error happens during the quads lookup.
@ -152,7 +152,7 @@ impl PyStore {
///
/// >>> store = Store()
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> list(solution['s'] for solution in store.query('SELECT ?s WHERE { ?s ?p ?o }'))
/// >>> [solution['s'] for solution in store.query('SELECT ?s WHERE { ?s ?p ?o }')]
/// [<NamedNode value=http://example.com>]
///
/// ``CONSTRUCT`` query:
@ -169,7 +169,7 @@ impl PyStore {
/// >>> store.query('ASK { ?s ?p ?o }')
/// True
#[pyo3(
text_signature = "($self, query, *, base_iri, use_default_graph_as_union, default_graph, named_graphs)"
text_signature = "($self, query, *, base_iri = None, use_default_graph_as_union = False, default_graph = None, named_graphs = None)"
)]
#[args(
query,
@ -233,7 +233,7 @@ impl PyStore {
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
/// >>> list(store)
/// []
#[pyo3(text_signature = "($self, update, *, base_iri)")]
#[pyo3(text_signature = "($self, update, *, base_iri = None)")]
#[args(update, "*", base_iri = "None")]
fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| {
@ -278,7 +278,7 @@ impl PyStore {
/// >>> store.load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
/// >>> 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>>]
#[pyo3(text_signature = "($self, data, /, mime_type, *, base_iri = None, to_graph = None)")]
#[pyo3(text_signature = "($self, input, /, mime_type, *, base_iri = None, to_graph = None)")]
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn load(
&self,
@ -362,7 +362,7 @@ impl PyStore {
/// >>> store.bulk_load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
/// >>> 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>>]
#[pyo3(text_signature = "($self, data, /, mime_type, *, base_iri = None, to_graph = None)")]
#[pyo3(text_signature = "($self, input, /, mime_type, *, base_iri = None, to_graph = None)")]
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn bulk_load(
&self,
@ -535,6 +535,8 @@ impl PyStore {
/// Clears a graph from the store without removing it.
///
/// :param graph_name: the name of the name graph to clear.
/// :type graph_name: NamedNode or BlankNode or DefaultGraph
/// :raises IOError: if an I/O error happens during the operation.
///
/// >>> store = Store()
@ -672,7 +674,7 @@ impl PyStore {
}
}
#[pyclass(unsendable, module = "oxigraph")]
#[pyclass(unsendable)]
pub struct QuadIter {
inner: store::QuadIter,
}
@ -691,7 +693,7 @@ impl QuadIter {
}
}
#[pyclass(unsendable, module = "oxigraph")]
#[pyclass(unsendable)]
pub struct GraphNameIter {
inner: store::GraphNameIter,
}

Loading…
Cancel
Save