Deprecates Triple and Quad methods

It's much simpler to expose the inner fields
pull/41/head
Tpt 4 years ago
parent 71aa5a6c79
commit 2d80960e79
  1. 21
      js/src/model.rs
  2. 95
      lib/src/model/triple.rs
  3. 6
      lib/src/sparql/eval.rs
  4. 22
      lib/src/store/numeric_encoder.rs
  5. 2
      testsuite/src/manifest.rs
  6. 16
      testsuite/src/sparql_evaluator.rs

@ -441,12 +441,11 @@ impl JsQuad {
impl From<Quad> for JsQuad {
fn from(quad: Quad) -> Self {
let (s, p, o, g) = quad.destruct();
Self {
subject: s.into(),
predicate: p.into(),
object: o.into(),
graph: if let Some(g) = g {
subject: quad.subject.into(),
predicate: quad.predicate.into(),
object: quad.object.into(),
graph: if let Some(g) = quad.graph_name {
g.into()
} else {
JsTerm::DefaultGraph(JsDefaultGraph {})
@ -459,11 +458,11 @@ impl TryFrom<JsQuad> for Quad {
type Error = JsValue;
fn try_from(quad: JsQuad) -> Result<Self, JsValue> {
Ok(Quad::new(
NamedOrBlankNode::try_from(quad.subject)?,
NamedNode::try_from(quad.predicate)?,
Term::try_from(quad.object)?,
match quad.graph {
Ok(Quad {
subject: NamedOrBlankNode::try_from(quad.subject)?,
predicate: NamedNode::try_from(quad.predicate)?,
object: Term::try_from(quad.object)?,
graph_name: match quad.graph {
JsTerm::NamedNode(node) => Some(NamedOrBlankNode::from(NamedNode::from(node))),
JsTerm::BlankNode(node) => Some(NamedOrBlankNode::from(BlankNode::from(node))),
JsTerm::Literal(literal) => {
@ -474,7 +473,7 @@ impl TryFrom<JsQuad> for Quad {
}
JsTerm::DefaultGraph(_) => None,
},
))
})
}
}

@ -142,9 +142,14 @@ impl<'a> From<&'a Term> for rio::Term<'a> {
/// A [RDF triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct Triple {
subject: NamedOrBlankNode,
predicate: NamedNode,
object: Term,
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub subject: NamedOrBlankNode,
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNode,
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub object: Term,
}
impl Triple {
@ -161,32 +166,32 @@ impl Triple {
}
}
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
#[deprecated(note = "Use directly the `subject` field")]
pub const fn subject(&self) -> &NamedOrBlankNode {
&self.subject
}
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
#[deprecated(note = "Use directly the `subject` field")]
pub fn subject_owned(self) -> NamedOrBlankNode {
self.subject
}
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
#[deprecated(note = "Use directly the `predicate` field")]
pub const fn predicate(&self) -> &NamedNode {
&self.predicate
}
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
#[deprecated(note = "Use directly the `predicate` field")]
pub fn predicate_owned(self) -> NamedNode {
self.predicate
}
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
#[deprecated(note = "Use directly the `object` field")]
pub const fn object(&self) -> &Term {
&self.object
}
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
#[deprecated(note = "Use directly the `object` field")]
pub fn object_owned(self) -> Term {
self.object
}
@ -204,16 +209,16 @@ impl Triple {
impl fmt::Display for Triple {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {} {} .", self.subject, self.predicate, self.object)
rio::Triple::from(self).fmt(f)
}
}
impl<'a> From<&'a Triple> for rio::Triple<'a> {
fn from(node: &'a Triple) -> Self {
rio::Triple {
subject: node.subject().into(),
predicate: node.predicate().into(),
object: node.object().into(),
subject: (&node.subject).into(),
predicate: (&node.predicate).into(),
object: (&node.object).into(),
}
}
}
@ -221,10 +226,18 @@ impl<'a> From<&'a Triple> for rio::Triple<'a> {
/// A [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct Quad {
subject: NamedOrBlankNode,
predicate: NamedNode,
object: Term,
graph_name: Option<NamedOrBlankNode>,
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub subject: NamedOrBlankNode,
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub predicate: NamedNode,
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub object: Term,
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is
/// or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
pub graph_name: Option<NamedOrBlankNode>,
}
impl Quad {
@ -243,52 +256,52 @@ impl Quad {
}
}
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
#[deprecated(note = "Use directly the `subject` field")]
pub const fn subject(&self) -> &NamedOrBlankNode {
&self.subject
}
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
#[deprecated(note = "Use directly the `subject` field")]
pub fn subject_owned(self) -> NamedOrBlankNode {
self.subject
}
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
#[deprecated(note = "Use directly the `predicate` field")]
pub const fn predicate(&self) -> &NamedNode {
&self.predicate
}
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
#[deprecated(note = "Use directly the `predicate` field")]
pub fn predicate_owned(self) -> NamedNode {
self.predicate
}
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
#[deprecated(note = "Use directly the `object` field")]
pub const fn object(&self) -> &Term {
&self.object
}
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
#[deprecated(note = "Use directly the `object` field")]
pub fn object_owned(self) -> Term {
self.object
}
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
#[deprecated(note = "Use directly the `graph_name` field")]
pub const fn graph_name(&self) -> &Option<NamedOrBlankNode> {
&self.graph_name
}
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
#[deprecated(note = "Use directly the `graph_name` field")]
pub fn graph_name_owned(self) -> Option<NamedOrBlankNode> {
self.graph_name
}
/// Returns the underlying [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[deprecated(note = "Use `Triple::from` instead")]
pub fn into_triple(self) -> Triple {
Triple::new(self.subject, self.predicate, self.object)
}
/// Extract components from this quad
#[deprecated(note = "Use directly the struct fields")]
pub fn destruct(self) -> (NamedOrBlankNode, NamedNode, Term, Option<NamedOrBlankNode>) {
(self.subject, self.predicate, self.object, self.graph_name)
}
@ -296,13 +309,27 @@ impl Quad {
impl fmt::Display for Quad {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.graph_name {
Some(ref graph_name) => write!(
f,
"{} {} {} {} .",
self.subject, self.predicate, self.object, graph_name
),
None => write!(f, "{} {} {} .", self.subject, self.predicate, self.object),
rio::Quad::from(self).fmt(f)
}
}
impl<'a> From<&'a Quad> for rio::Quad<'a> {
fn from(node: &'a Quad) -> Self {
rio::Quad {
subject: (&node.subject).into(),
predicate: (&node.predicate).into(),
object: (&node.object).into(),
graph_name: node.graph_name.as_ref().map(|g| g.into()),
}
}
}
impl From<Quad> for Triple {
fn from(quad: Quad) -> Self {
Self {
subject: quad.subject,
predicate: quad.predicate,
object: quad.object,
}
}
}

@ -2210,11 +2210,7 @@ impl<'a, S: ReadableEncodedStore + 'a> Iterator for DescribeIterator<'a, S> {
loop {
if let Some(quad) = self.quads.next() {
return Some(match quad {
Ok(quad) => self
.eval
.dataset
.decode_quad(&quad)
.map(|q| q.into_triple()),
Ok(quad) => self.eval.dataset.decode_quad(&quad).map(|q| q.into()),
Err(error) => Err(error),
});
}

@ -543,11 +543,11 @@ impl EncodedQuad {
impl From<&Quad> for EncodedQuad {
fn from(quad: &Quad) -> Self {
Self {
subject: quad.subject().into(),
predicate: quad.predicate().into(),
object: quad.object().into(),
subject: (&quad.subject).into(),
predicate: (&quad.predicate).into(),
object: (&quad.object).into(),
graph_name: quad
.graph_name()
.graph_name
.as_ref()
.map_or(ENCODED_DEFAULT_GRAPH, |g| g.into()),
}
@ -932,10 +932,10 @@ pub trait Encoder {
fn encode_quad(&mut self, quad: &Quad) -> Result<EncodedQuad> {
Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(quad.subject())?,
predicate: self.encode_named_node(quad.predicate())?,
object: self.encode_term(quad.object())?,
graph_name: match quad.graph_name() {
subject: self.encode_named_or_blank_node(&quad.subject)?,
predicate: self.encode_named_node(&quad.predicate)?,
object: self.encode_term(&quad.object)?,
graph_name: match &quad.graph_name {
Some(graph_name) => self.encode_named_or_blank_node(graph_name)?,
None => ENCODED_DEFAULT_GRAPH,
},
@ -948,9 +948,9 @@ pub trait Encoder {
graph_name: EncodedTerm,
) -> Result<EncodedQuad> {
Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(triple.subject())?,
predicate: self.encode_named_node(triple.predicate())?,
object: self.encode_term(triple.object())?,
subject: self.encode_named_or_blank_node(&triple.subject)?,
predicate: self.encode_named_node(&triple.predicate)?,
object: self.encode_term(&triple.object)?,
graph_name,
})
}

@ -270,5 +270,5 @@ fn objects_for_subject_predicate(
) -> impl Iterator<Item = Term> {
store
.quads_for_pattern(Some(subject), Some(predicate), None, None)
.map(|t| t.object_owned())
.map(|t| t.object)
}

@ -394,12 +394,12 @@ impl StaticQueryResults {
Some(&rs::RESULT_SET.clone().into()),
None,
)
.map(|q| q.subject_owned())
.map(|q| q.subject)
.next()
{
if let Some(bool) = dataset
.quads_for_pattern(Some(&result_set), Some(&rs::BOOLEAN), None, None)
.map(|q| q.object_owned())
.map(|q| q.object)
.next()
{
// Boolean query
@ -409,7 +409,7 @@ impl StaticQueryResults {
let mut variables: Vec<Variable> = dataset
.quads_for_pattern(Some(&result_set), Some(&rs::RESULT_VARIABLE), None, None)
.filter_map(|q| {
if let Term::Literal(l) = q.object_owned() {
if let Term::Literal(l) = q.object {
Some(Variable::new(l.value()))
} else {
None
@ -421,12 +421,12 @@ impl StaticQueryResults {
let mut solutions: Vec<_> = dataset
.quads_for_pattern(Some(&result_set), Some(&rs::SOLUTION), None, None)
.filter_map(|q| {
if let Term::BlankNode(solution) = q.object_owned() {
if let Term::BlankNode(solution) = q.object {
let solution = solution.into();
let mut bindings = dataset
.quads_for_pattern(Some(&solution), Some(&rs::BINDING), None, None)
.filter_map(|q| {
if let Term::BlankNode(binding) = q.object_owned() {
if let Term::BlankNode(binding) = q.object {
let binding = binding.into();
if let (Some(Term::Literal(variable)), Some(value)) = (
dataset
@ -436,7 +436,7 @@ impl StaticQueryResults {
None,
None,
)
.map(|q| q.object_owned())
.map(|q| q.object)
.next(),
dataset
.quads_for_pattern(
@ -445,7 +445,7 @@ impl StaticQueryResults {
None,
None,
)
.map(|q| q.object_owned())
.map(|q| q.object)
.next(),
) {
Some((Variable::new(variable.value()), value))
@ -461,7 +461,7 @@ impl StaticQueryResults {
let index = dataset
.quads_for_pattern(Some(&solution), Some(&rs::INDEX), None, None)
.filter_map(|q| {
if let Term::Literal(l) = q.object_owned() {
if let Term::Literal(l) = q.object {
u64::from_str(l.value()).ok()
} else {
None

Loading…
Cancel
Save