All spargebra fmt::Debug returns SSE and fmt::Display SPARQL syntax

pull/171/head
Tpt 3 years ago
parent a653506f4c
commit 067109e036
  1. 1104
      spargebra/src/algebra.rs
  2. 103
      spargebra/src/query.rs
  3. 307
      spargebra/src/term.rs
  4. 112
      spargebra/src/update.rs

File diff suppressed because it is too large Load Diff

@ -16,7 +16,7 @@ use std::str::FromStr;
/// assert_eq!(query.to_string(), query_str);
/// # Result::Ok::<_, spargebra::ParseError>(())
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum Query {
/// [SELECT](https://www.w3.org/TR/sparql11-query/#select)
Select {
@ -65,6 +65,107 @@ impl Query {
}
}
impl fmt::Debug for Query {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Query::Select {
dataset,
pattern,
base_iri,
} => {
if let Some(base_iri) = base_iri {
write!(f, "(base <{}> ", base_iri)?;
}
if let Some(dataset) = dataset {
write!(f, "(dataset {:?} ", dataset)?;
}
write!(f, "{:?}", pattern)?;
if dataset.is_some() {
write!(f, ")")?;
}
if base_iri.is_some() {
write!(f, ")")?;
}
Ok(())
}
Query::Construct {
template,
dataset,
pattern,
base_iri,
} => {
if let Some(base_iri) = base_iri {
write!(f, "(base <{}> ", base_iri)?;
}
write!(f, "(construct (")?;
for (i, t) in template.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, ") ")?;
if let Some(dataset) = dataset {
write!(f, "(dataset {:?} ", dataset)?;
}
write!(f, "{:?}", pattern)?;
if dataset.is_some() {
write!(f, ")")?;
}
write!(f, ")")?;
if base_iri.is_some() {
write!(f, ")")?;
}
Ok(())
}
Query::Describe {
dataset,
pattern,
base_iri,
} => {
if let Some(base_iri) = base_iri {
write!(f, "(base <{}> ", base_iri)?;
}
write!(f, "(describe ")?;
if let Some(dataset) = dataset {
write!(f, "(dataset {:?} ", dataset)?;
}
write!(f, "{:?}", pattern)?;
if dataset.is_some() {
write!(f, ")")?;
}
write!(f, ")")?;
if base_iri.is_some() {
write!(f, ")")?;
}
Ok(())
}
Query::Ask {
dataset,
pattern,
base_iri,
} => {
if let Some(base_iri) = base_iri {
write!(f, "(base <{}> ", base_iri)?;
}
write!(f, "(ask ")?;
if let Some(dataset) = dataset {
write!(f, "(dataset {:?} ", dataset)?;
}
write!(f, "{:?}", pattern)?;
if dataset.is_some() {
write!(f, ")")?;
}
write!(f, ")")?;
if base_iri.is_some() {
write!(f, ")")?;
}
Ok(())
}
}
}
}
impl fmt::Display for Query {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

@ -16,12 +16,19 @@ use std::fmt::Write;
/// NamedNode { iri: "http://example.com/foo".into() }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Hash)]
pub struct NamedNode {
/// The [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) itself.
pub iri: String,
}
impl fmt::Debug for NamedNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "<{}>", self.iri)
}
}
impl fmt::Display for NamedNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -54,12 +61,19 @@ impl TryFrom<NamedNodePattern> for NamedNode {
/// BlankNode { id: "a1".into() }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct BlankNode {
/// The [blank node identifier](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier).
pub id: String,
}
impl fmt::Debug for BlankNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "_:{}", self.id)
}
}
impl fmt::Display for BlankNode {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -92,7 +106,7 @@ impl fmt::Display for BlankNode {
/// Literal::LanguageTaggedString { value: "foo".into(), language: "en".into() }.to_string()
/// );
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum Literal {
/// A [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) without datatype or language form.
Simple {
@ -115,6 +129,23 @@ pub enum Literal {
},
}
impl fmt::Debug for Literal {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Literal::Simple { value } => print_quoted_str(value, f),
Literal::LanguageTaggedString { value, language } => {
print_quoted_str(value, f)?;
write!(f, "@{}", language)
}
Literal::Typed { value, datatype } => {
print_quoted_str(value, f)?;
write!(f, "^^{}", datatype)
}
}
}
}
impl fmt::Display for Literal {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -135,7 +166,7 @@ impl fmt::Display for Literal {
/// The union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node).
///
/// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation.
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum Subject {
NamedNode(NamedNode),
BlankNode(BlankNode),
@ -143,6 +174,18 @@ pub enum Subject {
Triple(Box<Triple>),
}
impl fmt::Debug for Subject {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::BlankNode(node) => node.fmt(f),
#[cfg(feature = "rdf-star")]
Self::Triple(triple) => triple.fmt(f),
}
}
}
impl fmt::Display for Subject {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -199,13 +242,24 @@ impl TryFrom<TermPattern> for Subject {
/// The union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [triples](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple).
///
/// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation.
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GroundSubject {
NamedNode(NamedNode),
#[cfg(feature = "rdf-star")]
Triple(Box<GroundTriple>),
}
impl fmt::Debug for GroundSubject {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
#[cfg(feature = "rdf-star")]
Self::Triple(triple) => triple.fmt(f),
}
}
}
impl fmt::Display for GroundSubject {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -269,7 +323,7 @@ impl TryFrom<GroundTerm> for GroundSubject {
/// It is the union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri), [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node) and [literals](https://www.w3.org/TR/rdf11-concepts/#dfn-literal).
///
/// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation.
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum Term {
NamedNode(NamedNode),
BlankNode(BlankNode),
@ -278,6 +332,19 @@ pub enum Term {
Triple(Box<Triple>),
}
impl fmt::Debug for Term {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::BlankNode(node) => node.fmt(f),
Self::Literal(literal) => literal.fmt(f),
#[cfg(feature = "rdf-star")]
Self::Triple(triple) => triple.fmt(f),
}
}
}
impl fmt::Display for Term {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -355,7 +422,7 @@ impl TryFrom<TermPattern> for Term {
/// The union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri), [literals](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) and [triples](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple).
///
/// The default string formatter is returning an N-Triples, Turtle and SPARQL compatible representation.
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GroundTerm {
NamedNode(NamedNode),
Literal(Literal),
@ -363,6 +430,18 @@ pub enum GroundTerm {
Triple(Box<GroundTriple>),
}
impl fmt::Debug for GroundTerm {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::Literal(literal) => literal.fmt(f),
#[cfg(feature = "rdf-star")]
Self::Triple(triple) => triple.fmt(f),
}
}
}
impl fmt::Display for GroundTerm {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -433,13 +512,24 @@ impl TryFrom<Term> for GroundTerm {
/// }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct Triple {
pub subject: Subject,
pub predicate: NamedNode,
pub object: Term,
}
impl fmt::Debug for Triple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
}
}
impl fmt::Display for Triple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -477,13 +567,24 @@ impl TryFrom<TriplePattern> for Triple {
/// }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct GroundTriple {
pub subject: GroundSubject,
pub predicate: NamedNode,
pub object: GroundTerm,
}
impl fmt::Debug for GroundTriple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
}
}
impl fmt::Display for GroundTriple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -507,12 +608,22 @@ impl TryFrom<Triple> for GroundTriple {
/// A possible graph name.
///
/// It is the union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and the [default graph name](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph).
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GraphName {
NamedNode(NamedNode),
DefaultGraph,
}
impl fmt::Debug for GraphName {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::DefaultGraph => write!(f, "default"),
}
}
}
impl fmt::Display for GraphName {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -561,7 +672,7 @@ impl TryFrom<GraphNamePattern> for GraphName {
/// }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct Quad {
pub subject: Subject,
pub predicate: NamedNode,
@ -569,6 +680,25 @@ pub struct Quad {
pub graph_name: GraphName,
}
impl fmt::Debug for Quad {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.graph_name == GraphName::DefaultGraph {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
} else {
write!(
f,
"(graph {:?} ((triple {:?} {:?} {:?})))",
self.graph_name, self.subject, self.predicate, self.object
)
}
}
}
impl fmt::Display for Quad {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -616,7 +746,7 @@ impl TryFrom<QuadPattern> for Quad {
/// }.to_string()
/// )
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct GroundQuad {
pub subject: GroundSubject,
pub predicate: NamedNode,
@ -624,6 +754,25 @@ pub struct GroundQuad {
pub graph_name: GraphName,
}
impl fmt::Debug for GroundQuad {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.graph_name == GraphName::DefaultGraph {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
} else {
write!(
f,
"(graph {:?} ((triple {:?} {:?} {:?})))",
self.graph_name, self.subject, self.predicate, self.object
)
}
}
}
impl fmt::Display for GroundQuad {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -663,11 +812,18 @@ impl TryFrom<Quad> for GroundQuad {
/// Variable { name: "foo".into() }.to_string()
/// );
/// ```
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Hash)]
pub struct Variable {
pub name: String,
}
impl fmt::Debug for Variable {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "?{}", self.name)
}
}
impl fmt::Display for Variable {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -676,12 +832,22 @@ impl fmt::Display for Variable {
}
/// The union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [variables](https://www.w3.org/TR/sparql11-query/#sparqlQueryVariables).
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum NamedNodePattern {
NamedNode(NamedNode),
Variable(Variable),
}
impl fmt::Debug for NamedNodePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::Variable(var) => var.fmt(f),
}
}
}
impl fmt::Display for NamedNodePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -707,7 +873,7 @@ impl From<Variable> for NamedNodePattern {
}
/// The union of [terms](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term) and [variables](https://www.w3.org/TR/sparql11-query/#sparqlQueryVariables).
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum TermPattern {
NamedNode(NamedNode),
BlankNode(BlankNode),
@ -717,6 +883,20 @@ pub enum TermPattern {
Variable(Variable),
}
impl fmt::Debug for TermPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(term) => term.fmt(f),
Self::BlankNode(term) => term.fmt(f),
Self::Literal(term) => term.fmt(f),
#[cfg(feature = "rdf-star")]
Self::Triple(triple) => triple.fmt(f),
Self::Variable(var) => var.fmt(f),
}
}
}
impl fmt::Display for TermPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -802,7 +982,7 @@ impl From<NamedNodePattern> for TermPattern {
}
/// The union of [terms](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term) and [variables](https://www.w3.org/TR/sparql11-query/#sparqlQueryVariables) without blank nodes.
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GroundTermPattern {
NamedNode(NamedNode),
Literal(Literal),
@ -810,6 +990,18 @@ pub enum GroundTermPattern {
Triple(Box<GroundTriplePattern>),
}
impl fmt::Debug for GroundTermPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(term) => term.fmt(f),
Self::Literal(term) => term.fmt(f),
Self::Variable(var) => var.fmt(f),
Self::Triple(triple) => write!(f, "<<{}>>", triple),
}
}
}
impl fmt::Display for GroundTermPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -899,19 +1091,30 @@ impl TryFrom<TermPattern> for GroundTermPattern {
}
/// The union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri), [default graph name](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph) and [variables](https://www.w3.org/TR/sparql11-query/#sparqlQueryVariables).
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GraphNamePattern {
NamedNode(NamedNode),
DefaultGraph,
Variable(Variable),
}
impl fmt::Debug for GraphNamePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::DefaultGraph => write!(f, "default"),
Self::Variable(var) => var.fmt(f),
}
}
}
impl fmt::Display for GraphNamePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NamedNode(node) => node.fmt(f),
Self::DefaultGraph => f.write_str("DEFAULT"),
Self::DefaultGraph => write!(f, "DEFAULT"),
Self::Variable(var) => var.fmt(f),
}
}
@ -952,7 +1155,7 @@ impl From<NamedNodePattern> for GraphNamePattern {
}
/// A [triple pattern](https://www.w3.org/TR/sparql11-query/#defn_TriplePattern)
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct TriplePattern {
pub subject: TermPattern,
pub predicate: NamedNodePattern,
@ -973,6 +1176,17 @@ impl TriplePattern {
}
}
impl fmt::Debug for TriplePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
}
}
impl fmt::Display for TriplePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -992,13 +1206,24 @@ impl From<Triple> for TriplePattern {
}
/// A [triple pattern](https://www.w3.org/TR/sparql11-query/#defn_TriplePattern) without blank nodes
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct GroundTriplePattern {
pub subject: GroundTermPattern,
pub predicate: NamedNodePattern,
pub object: GroundTermPattern,
}
impl fmt::Debug for GroundTriplePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
}
}
impl fmt::Display for GroundTriplePattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -1031,7 +1256,7 @@ impl TryFrom<TriplePattern> for GroundTriplePattern {
}
/// A [triple pattern](https://www.w3.org/TR/sparql11-query/#defn_TriplePattern) in a specific graph
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct QuadPattern {
pub subject: TermPattern,
pub predicate: NamedNodePattern,
@ -1055,6 +1280,25 @@ impl QuadPattern {
}
}
impl fmt::Debug for QuadPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.graph_name == GraphNamePattern::DefaultGraph {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
} else {
write!(
f,
"(graph {:?} ((triple {:?} {:?} {:?})))",
self.graph_name, self.subject, self.predicate, self.object
)
}
}
}
impl fmt::Display for QuadPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -1071,7 +1315,7 @@ impl fmt::Display for QuadPattern {
}
/// A [triple pattern](https://www.w3.org/TR/sparql11-query/#defn_TriplePattern) in a specific graph without blank nodes
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct GroundQuadPattern {
pub subject: GroundTermPattern,
pub predicate: NamedNodePattern,
@ -1079,6 +1323,25 @@ pub struct GroundQuadPattern {
pub graph_name: GraphNamePattern,
}
impl fmt::Debug for GroundQuadPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.graph_name == GraphNamePattern::DefaultGraph {
write!(
f,
"(triple {:?} {:?} {:?})",
self.subject, self.predicate, self.object
)
} else {
write!(
f,
"(graph {:?} ((triple {:?} {:?} {:?})))",
self.graph_name, self.subject, self.predicate, self.object
)
}
}
}
impl fmt::Display for GroundQuadPattern {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

@ -16,7 +16,7 @@ use std::str::FromStr;
/// assert_eq!(update.to_string().trim(), update_str);
/// # Result::Ok::<_, spargebra::ParseError>(())
/// ```
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct Update {
/// The update base IRI
pub base_iri: Option<Iri<String>>,
@ -31,6 +31,23 @@ impl Update {
}
}
impl fmt::Debug for Update {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(base_iri) = &self.base_iri {
write!(f, "(base <{}> ", base_iri)?;
}
write!(f, "(update")?;
for op in &self.operations {
write!(f, " {:?}", op)?;
}
write!(f, ")")?;
if self.base_iri.is_some() {
write!(f, ")")?;
}
Ok(())
}
}
impl fmt::Display for Update {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(base_iri) = &self.base_iri {
@ -68,7 +85,7 @@ impl<'a> TryFrom<&'a String> for Update {
}
/// The [graph update operations](https://www.w3.org/TR/sparql11-update/#formalModelGraphUpdate)
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[derive(Eq, PartialEq, Clone, Hash)]
pub enum GraphUpdateOperation {
/// [insert data](https://www.w3.org/TR/sparql11-update/#defn_insertDataOperation)
InsertData { data: Vec<Quad> },
@ -95,6 +112,97 @@ pub enum GraphUpdateOperation {
Drop { silent: bool, graph: GraphTarget },
}
impl fmt::Debug for GraphUpdateOperation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GraphUpdateOperation::InsertData { data } => {
write!(f, "(insertData (")?;
for (i, t) in data.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, "))")
}
GraphUpdateOperation::DeleteData { data } => {
write!(f, "(deleteData (")?;
for (i, t) in data.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, "))")
}
GraphUpdateOperation::DeleteInsert {
delete,
insert,
using,
pattern,
} => {
write!(f, "(modify")?;
if let Some(using) = using {
write!(f, " (using {:?}", using)?;
}
write!(f, " {:?}", pattern)?;
if using.is_some() {
write!(f, ")")?;
}
if !delete.is_empty() {
write!(f, " (delete (")?;
for (i, t) in delete.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, "))")?;
}
if !insert.is_empty() {
write!(f, " (insert (")?;
for (i, t) in insert.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, "))")?;
}
write!(f, ")")
}
GraphUpdateOperation::Load { silent, from, to } => {
write!(f, "(load")?;
if *silent {
write!(f, " silent")?;
}
write!(f, " {:?} {:?}", from, to)
}
GraphUpdateOperation::Clear { silent, graph } => {
write!(f, "(clear")?;
if *silent {
write!(f, " silent")?;
}
write!(f, " {:?})", graph)
}
GraphUpdateOperation::Create { silent, graph } => {
write!(f, "(create")?;
if *silent {
write!(f, " silent")?;
}
write!(f, " {:?})", graph)
}
GraphUpdateOperation::Drop { silent, graph } => {
write!(f, "(drop")?;
if *silent {
write!(f, " silent")?;
}
write!(f, " {:?})", graph)
}
}
}
}
impl fmt::Display for GraphUpdateOperation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

Loading…
Cancel
Save