From 39fe1b1704dc13363a761929b6218a0ad9213755 Mon Sep 17 00:00:00 2001 From: Tpt Date: Mon, 31 Aug 2020 16:21:33 +0200 Subject: [PATCH] Removes The default_graph_uris and named_graph_uris parameters from Python query methods --- CHANGELOG.md | 5 ++++- lib/src/model/parser.rs | 2 +- python/src/memory_store.rs | 18 ++---------------- python/src/sled_store.rs | 18 ++---------------- python/src/sparql.rs | 17 ++--------------- 5 files changed, 11 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 947adcee..ffbb1b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,10 @@ - [SPARQL 1.1 Query Results CSV and TSV Formats](https://www.w3.org/TR/sparql11-results-csv-tsv/) serializers and TSV format parser. - `std::str::FromStr` implementations to `NamedNode`, `BlankNode`, `Literal`, `Term` and `Variable` allowing to easily parse Turtle/SPARQL serialization of these terms. -## Changed +### Removed +- The `default_graph_uris` and `named_graph_uris` parameters from `pyoxigraph` `query` methods. + +### Changed - Fixes evaluation of `MONTH()` and `DAY()` functions on the `xsd:date` values. - `Variable::new` now validates the variable name. diff --git a/lib/src/model/parser.rs b/lib/src/model/parser.rs index 1fc19142..16a8ea22 100644 --- a/lib/src/model/parser.rs +++ b/lib/src/model/parser.rs @@ -258,7 +258,7 @@ impl FromStr for Variable { /// assert_eq!(Variable::from_str("$foo").unwrap(), Variable::new("foo").unwrap()) /// ``` fn from_str(s: &str) -> Result { - if !s.starts_with("?") && !s.starts_with('$') { + if !s.starts_with('?') && !s.starts_with('$') { return Err(TermParseError::msg( "Variable serialization should start with ? or $", )); diff --git a/python/src/memory_store.rs b/python/src/memory_store.rs index 4a42a9fa..e19fa792 100644 --- a/python/src/memory_store.rs +++ b/python/src/memory_store.rs @@ -117,10 +117,6 @@ impl PyMemoryStore { /// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional /// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available. /// :type named_graphs: list(NamedNode or BlankNode) or None, optional - /// :param default_graph_uris: deprecated, use ``default_graph`` instead - /// :type default_graph_uris: list(NamedNode) or None, optional - /// :param named_graph_uris: deprecated, use ``named_graphs`` instead - /// :type named_graph_uris: list(NamedNode) or None, optional /// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries. /// :rtype: QuerySolutions or QueryTriples or bool /// :raises SyntaxError: if the provided query is invalid @@ -145,13 +141,11 @@ impl PyMemoryStore { /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.query('ASK { ?s ?p ?o }') /// True - #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph_uris, named_graph_uris, default_graph, named_graphs)"] + #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)"] #[args( query, "*", use_default_graph_as_union = "false", - default_graph_uris = "None", - named_graph_uris = "None", default_graph = "None", named_graphs = "None" )] @@ -159,19 +153,11 @@ impl PyMemoryStore { &self, query: &str, use_default_graph_as_union: bool, - default_graph_uris: Option<&PyAny>, - named_graph_uris: Option<&PyAny>, default_graph: Option<&PyAny>, named_graphs: Option<&PyAny>, py: Python<'_>, ) -> PyResult { - let options = build_query_options( - use_default_graph_as_union, - default_graph_uris, - named_graph_uris, - default_graph, - named_graphs, - )?; + let options = build_query_options(use_default_graph_as_union, default_graph, named_graphs)?; let results = self .inner .query(query, options) diff --git a/python/src/sled_store.rs b/python/src/sled_store.rs index b2ad0c3c..b932b569 100644 --- a/python/src/sled_store.rs +++ b/python/src/sled_store.rs @@ -130,10 +130,6 @@ impl PySledStore { /// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional /// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available. /// :type named_graphs: list(NamedNode or BlankNode) or None, optional - /// :param default_graph_uris: deprecated, use ``default_graph`` instead - /// :type default_graph_uris: list(NamedNode) or None, optional - /// :param named_graph_uris: deprecated, use ``named_graphs`` instead - /// :type named_graph_uris: list(NamedNode) or None, optional /// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries. /// :rtype: QuerySolutions or QueryTriples or bool /// :raises SyntaxError: if the provided query is invalid @@ -159,13 +155,11 @@ impl PySledStore { /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.query('ASK { ?s ?p ?o }') /// True - #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph_uris, named_graph_uris, default_graph, named_graphs)"] + #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)"] #[args( query, "*", use_default_graph_as_union = "false", - default_graph_uris = "None", - named_graph_uris = "None", default_graph = "None", named_graphs = "None" )] @@ -173,19 +167,11 @@ impl PySledStore { &self, query: &str, use_default_graph_as_union: bool, - default_graph_uris: Option<&PyAny>, - named_graph_uris: Option<&PyAny>, default_graph: Option<&PyAny>, named_graphs: Option<&PyAny>, py: Python<'_>, ) -> PyResult { - let options = build_query_options( - use_default_graph_as_union, - default_graph_uris, - named_graph_uris, - default_graph, - named_graphs, - )?; + let options = build_query_options(use_default_graph_as_union, default_graph, named_graphs)?; let results = self .inner .query(query, options) diff --git a/python/src/sparql.rs b/python/src/sparql.rs index 40187dab..6e407d1e 100644 --- a/python/src/sparql.rs +++ b/python/src/sparql.rs @@ -13,28 +13,15 @@ use std::vec::IntoIter; pub fn build_query_options( use_default_graph_as_union: bool, - default_graph_uris: Option<&PyAny>, - named_graph_uris: Option<&PyAny>, default_graph: Option<&PyAny>, named_graphs: Option<&PyAny>, ) -> PyResult { - if default_graph_uris.is_some() && default_graph.is_some() { - return Err(ValueError::py_err( - "The query() method default_graph and default_graph_uris parameters cannot be set at the same time", - )); - } - if named_graph_uris.is_some() && named_graphs.is_some() { - return Err(ValueError::py_err( - "The query() method named_graphs and named_graph_uris parameters cannot be set at the same time", - )); - } - let mut options = QueryOptions::default(); if use_default_graph_as_union { options = options.with_default_graph_as_union(); } - if let Some(default_graph) = default_graph.or(default_graph_uris) { + if let Some(default_graph) = default_graph { if let Ok(default_graphs) = default_graph.iter() { if default_graph.is_empty()? { return Err(ValueError::py_err( @@ -53,7 +40,7 @@ pub fn build_query_options( } } - if let Some(named_graphs) = named_graphs.or(named_graph_uris) { + if let Some(named_graphs) = named_graphs { if named_graphs.is_empty()? { return Err(ValueError::py_err( "The query() method named_graphs argument cannot be empty",