SparqlParser

Struct SparqlParser 

Source
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

Source

pub fn new() -> Self

Source

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> . }");
Source

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> . }"
);
Source

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 }",
    )?;
Source

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);
Source

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

Source§

fn clone(&self) -> SparqlParser

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SparqlParser

Source§

fn default() -> SparqlParser

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V