From febaad9bdb5821df54a8debba27ec5736e1ced9b Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 22 May 2020 14:36:50 +0200 Subject: [PATCH] Adds new easy equality method to NamedNode --- lib/src/model/named_node.rs | 12 ++++++++++++ lib/src/sparql/plan_builder.rs | 21 ++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/src/model/named_node.rs b/lib/src/model/named_node.rs index aeef13e4..0bd5da82 100644 --- a/lib/src/model/named_node.rs +++ b/lib/src/model/named_node.rs @@ -58,3 +58,15 @@ impl<'a> From<&'a NamedNode> for rio::NamedNode<'a> { rio::NamedNode { iri: node.as_str() } } } + +impl PartialEq for NamedNode { + fn eq(&self, other: &str) -> bool { + self.as_str() == other + } +} + +impl PartialEq for str { + fn eq(&self, other: &NamedNode) -> bool { + self == other.as_str() + } +} diff --git a/lib/src/sparql/plan_builder.rs b/lib/src/sparql/plan_builder.rs index 9f17cf87..9cee5c06 100644 --- a/lib/src/sparql/plan_builder.rs +++ b/lib/src/sparql/plan_builder.rs @@ -1,4 +1,3 @@ -use crate::model::vocab::xsd; use crate::sparql::algebra::*; use crate::sparql::model::*; use crate::sparql::plan::PlanPropertyPath; @@ -571,7 +570,7 @@ impl PlanBuilder { }, ), Function::Custom(name) => { - if *name == *xsd::BOOLEAN { + if name == "http://www.w3.org/2001/XMLSchema#boolean" { self.build_cast( parameters, PlanExpression::BooleanCast, @@ -579,7 +578,7 @@ impl PlanBuilder { graph_name, "boolean", )? - } else if *name == *xsd::DOUBLE { + } else if name == "http://www.w3.org/2001/XMLSchema#double" { self.build_cast( parameters, PlanExpression::DoubleCast, @@ -587,7 +586,7 @@ impl PlanBuilder { graph_name, "double", )? - } else if *name == *xsd::FLOAT { + } else if name == "http://www.w3.org/2001/XMLSchema#float" { self.build_cast( parameters, PlanExpression::FloatCast, @@ -595,7 +594,7 @@ impl PlanBuilder { graph_name, "float", )? - } else if *name == *xsd::DECIMAL { + } else if name == "http://www.w3.org/2001/XMLSchema#decimal" { self.build_cast( parameters, PlanExpression::DecimalCast, @@ -603,7 +602,7 @@ impl PlanBuilder { graph_name, "decimal", )? - } else if *name == *xsd::INTEGER { + } else if name == "http://www.w3.org/2001/XMLSchema#integer" { self.build_cast( parameters, PlanExpression::IntegerCast, @@ -611,7 +610,7 @@ impl PlanBuilder { graph_name, "integer", )? - } else if *name == *xsd::DATE { + } else if name == "http://www.w3.org/2001/XMLSchema#date" { self.build_cast( parameters, PlanExpression::DateCast, @@ -619,7 +618,7 @@ impl PlanBuilder { graph_name, "date", )? - } else if *name == *xsd::TIME { + } else if name == "http://www.w3.org/2001/XMLSchema#time" { self.build_cast( parameters, PlanExpression::TimeCast, @@ -627,7 +626,7 @@ impl PlanBuilder { graph_name, "time", )? - } else if *name == *xsd::DATE_TIME { + } else if name == "http://www.w3.org/2001/XMLSchema#dateTime" { self.build_cast( parameters, PlanExpression::DateTimeCast, @@ -635,7 +634,7 @@ impl PlanBuilder { graph_name, "dateTime", )? - } else if *name == *xsd::DURATION { + } else if name == "http://www.w3.org/2001/XMLSchema#duration" { self.build_cast( parameters, PlanExpression::DurationCast, @@ -643,7 +642,7 @@ impl PlanBuilder { graph_name, "duration", )? - } else if *name == *xsd::STRING { + } else if name == "http://www.w3.org/2001/XMLSchema#string" { self.build_cast( parameters, PlanExpression::StringCast,