pub struct SparqlParser { /* private fields */ }Expand description
A SPARQL parser
use spargebra::SparqlParser;
let query_str = "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }";
let query = SparqlParser::new().parse_query(query_str)?;
assert_eq!(query.to_string(), query_str);Implementations§
Source§impl SparqlParser
impl SparqlParser
pub fn new() -> Self
Sourcepub fn with_base_iri(
self,
base_iri: impl Into<String>,
) -> Result<Self, IriParseError>
pub fn with_base_iri( self, base_iri: impl Into<String>, ) -> Result<Self, IriParseError>
Provides an IRI that could be used to resolve the operation relative IRIs.
use spargebra::SparqlParser;
let query = SparqlParser::new().with_base_iri("http://example.com/")?.parse_query("SELECT * WHERE { <s> <p> <o> }")?;
assert_eq!(query.to_string(), "BASE <http://example.com/>\nSELECT * WHERE { <http://example.com/s> <http://example.com/p> <http://example.com/o> . }");Sourcepub fn with_prefix(
self,
prefix_name: impl Into<String>,
prefix_iri: impl Into<String>,
) -> Result<Self, IriParseError>
pub fn with_prefix( self, prefix_name: impl Into<String>, prefix_iri: impl Into<String>, ) -> Result<Self, IriParseError>
Set a default IRI prefix used during parsing.
use spargebra::SparqlParser;
let query = SparqlParser::new()
.with_prefix("ex", "http://example.com/")?
.parse_query("SELECT * WHERE { ex:s ex:p ex:o }")?;
assert_eq!(
query.to_string(),
"SELECT * WHERE { <http://example.com/s> <http://example.com/p> <http://example.com/o> . }"
);Sourcepub fn with_custom_aggregate_function(self, name: impl Into<NamedNode>) -> Self
pub fn with_custom_aggregate_function(self, name: impl Into<NamedNode>) -> Self
Adds a new function to be parsed as a custom aggregate function and not as a regular custom function.
use oxrdf::NamedNode;
use spargebra::SparqlParser;
SparqlParser::new()
.with_custom_aggregate_function(NamedNode::new("http://example.com/concat")?)
.parse_query(
"PREFIX ex: <http://example.com/> SELECT (ex:concat(?o) AS ?concat) WHERE { ex:s ex:p ex:o }",
)?;Sourcepub fn parse_query(self, query: &str) -> Result<Query, SparqlSyntaxError>
pub fn parse_query(self, query: &str) -> Result<Query, SparqlSyntaxError>
Parse the given query string using the already set options.
use spargebra::SparqlParser;
let query_str = "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }";
let query = SparqlParser::new().parse_query(query_str)?;
assert_eq!(query.to_string(), query_str);Sourcepub fn parse_update(self, update: &str) -> Result<Update, SparqlSyntaxError>
pub fn parse_update(self, update: &str) -> Result<Update, SparqlSyntaxError>
Parse the given update string using the already set options.
use spargebra::SparqlParser;
let update_str = "CLEAR ALL ;";
let update = SparqlParser::new().parse_update(update_str)?;
assert_eq!(update.to_string().trim(), update_str);Trait Implementations§
Source§impl Clone for SparqlParser
impl Clone for SparqlParser
Source§fn clone(&self) -> SparqlParser
fn clone(&self) -> SparqlParser
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for SparqlParser
impl Default for SparqlParser
Source§fn default() -> SparqlParser
fn default() -> SparqlParser
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SparqlParser
impl RefUnwindSafe for SparqlParser
impl Send for SparqlParser
impl Sync for SparqlParser
impl Unpin for SparqlParser
impl UnwindSafe for SparqlParser
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)