Add conversion from spargebra Query into oxigraph Query

pull/277/head
Maximilian Goisser 2 years ago committed by Thomas Tanon
parent 6c80c8dd56
commit 325dc59f84
  1. 24
      lib/src/sparql/algebra.rs

@ -36,15 +36,7 @@ impl Query {
/// Parses a SPARQL query with an optional base IRI to resolve relative IRIs in the query.
pub fn parse(query: &str, base_iri: Option<&str>) -> Result<Self, spargebra::ParseError> {
let query = spargebra::Query::parse(query, base_iri)?;
Ok(Self {
dataset: QueryDataset::from_algebra(match &query {
spargebra::Query::Select { dataset, .. }
| spargebra::Query::Construct { dataset, .. }
| spargebra::Query::Describe { dataset, .. }
| spargebra::Query::Ask { dataset, .. } => dataset,
}),
inner: query,
})
Ok(query.into())
}
/// Returns [the query dataset specification](https://www.w3.org/TR/sparql11-query/#specifyingDataset)
@ -88,6 +80,20 @@ impl<'a> TryFrom<&'a String> for Query {
}
}
impl From<spargebra::Query> for Query {
fn from(query: spargebra::Query) -> Self {
Self {
dataset: QueryDataset::from_algebra(match &query {
spargebra::Query::Select { dataset, .. }
| spargebra::Query::Construct { dataset, .. }
| spargebra::Query::Describe { dataset, .. }
| spargebra::Query::Ask { dataset, .. } => dataset,
}),
inner: query,
}
}
}
/// A parsed [SPARQL update](https://www.w3.org/TR/sparql11-update/).
///
/// ```

Loading…
Cancel
Save