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

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

@ -85,7 +85,7 @@ pub fn query_results_to_python(py: Python<'_>, results: QueryResults) -> PyResul
/// >>> s, p, o = solution /// >>> s, p, o = solution
/// >>> s /// >>> s
/// <NamedNode value=http://example.com> /// <NamedNode value=http://example.com>
#[pyclass(unsendable, name = "QuerySolution", module = "oxigraph")] #[pyclass(unsendable, name = "QuerySolution")]
pub struct PyQuerySolution { pub struct PyQuerySolution {
inner: QuerySolution, inner: QuerySolution,
} }
@ -136,7 +136,7 @@ impl PyQuerySolution {
} }
} }
#[pyclass(module = "oxigraph")] #[pyclass]
pub struct SolutionValueIter { pub struct SolutionValueIter {
inner: IntoIter<Option<Term>>, inner: IntoIter<Option<Term>>,
} }
@ -158,7 +158,7 @@ impl SolutionValueIter {
/// >>> 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')))
/// >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }')) /// >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }'))
/// [<QuerySolution s=<NamedNode value=http://example.com>>] /// [<QuerySolution s=<NamedNode value=http://example.com>>]
#[pyclass(unsendable, name = "QuerySolutions", module = "oxigraph")] #[pyclass(unsendable, name = "QuerySolutions")]
pub struct PyQuerySolutions { pub struct PyQuerySolutions {
inner: QuerySolutionIter, inner: QuerySolutionIter,
} }
@ -198,7 +198,7 @@ impl PyQuerySolutions {
/// >>> 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')))
/// >>> list(store.query('CONSTRUCT WHERE { ?s ?p ?o }')) /// >>> 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>>>] /// [<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 { pub struct PyQueryTriples {
inner: QueryTripleIter, 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. /// :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. /// 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. /// 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. /// :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: /// 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'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
/// >>> 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 = "Store", module = "oxigraph")] #[pyclass(name = "Store")]
#[pyo3(text_signature = "(path = None)")] #[pyo3(text_signature = "(path = None)")]
#[derive(Clone)] #[derive(Clone)]
pub struct PyStore { pub struct PyStore {
@ -101,8 +101,8 @@ impl PyStore {
/// :type predicate: NamedNode or None /// :type predicate: NamedNode or None
/// :param object: the quad object or :py:const:`None` to match everything. /// :param object: the quad object or :py:const:`None` to match everything.
/// :type object: NamedNode or BlankNode or Literal or None /// :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`. /// :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: NamedNode or BlankNode or DefaultGraph or None /// :type graph_name: NamedNode or BlankNode or DefaultGraph or None
/// :return: an iterator of the quads matching the pattern. /// :return: an iterator of the quads matching the pattern.
/// :rtype: iter(Quad) /// :rtype: iter(Quad)
/// :raises IOError: if an I/O error happens during the quads lookup. /// :raises IOError: if an I/O error happens during the quads lookup.
@ -152,7 +152,7 @@ impl PyStore {
/// ///
/// >>> store = Store() /// >>> store = Store()
/// >>> 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')))
/// >>> 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>] /// [<NamedNode value=http://example.com>]
/// ///
/// ``CONSTRUCT`` query: /// ``CONSTRUCT`` query:
@ -169,7 +169,7 @@ impl PyStore {
/// >>> store.query('ASK { ?s ?p ?o }') /// >>> store.query('ASK { ?s ?p ?o }')
/// True /// True
#[pyo3( #[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( #[args(
query, query,
@ -233,7 +233,7 @@ impl PyStore {
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }') /// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
/// >>> list(store) /// >>> list(store)
/// [] /// []
#[pyo3(text_signature = "($self, update, *, base_iri)")] #[pyo3(text_signature = "($self, update, *, base_iri = None)")]
#[args(update, "*", base_iri = "None")] #[args(update, "*", base_iri = "None")]
fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> { fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| { 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")) /// >>> 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>>]
#[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")] #[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn load( fn load(
&self, &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")) /// >>> 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) /// >>> 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>>]
#[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")] #[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn bulk_load( fn bulk_load(
&self, &self,
@ -535,6 +535,8 @@ impl PyStore {
/// Clears a graph from the store without removing it. /// 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. /// :raises IOError: if an I/O error happens during the operation.
/// ///
/// >>> store = Store() /// >>> store = Store()
@ -672,7 +674,7 @@ impl PyStore {
} }
} }
#[pyclass(unsendable, module = "oxigraph")] #[pyclass(unsendable)]
pub struct QuadIter { pub struct QuadIter {
inner: store::QuadIter, inner: store::QuadIter,
} }
@ -691,7 +693,7 @@ impl QuadIter {
} }
} }
#[pyclass(unsendable, module = "oxigraph")] #[pyclass(unsendable)]
pub struct GraphNameIter { pub struct GraphNameIter {
inner: store::GraphNameIter, inner: store::GraphNameIter,
} }

Loading…
Cancel
Save