From bf37d7c6771b237537a01aa19c9fe032a2e0657b Mon Sep 17 00:00:00 2001 From: Tpt Date: Thu, 21 Feb 2019 15:26:18 +0100 Subject: [PATCH] Fixes langMatches evaluation --- lib/Cargo.toml | 1 - lib/src/sparql/eval.rs | 38 +++++++++++++++++++++++++++++----- lib/tests/sparql_test_cases.rs | 7 ------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index fcf8c038..008128f3 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -27,7 +27,6 @@ ordered-float = "1" num-traits = "0.2" rust_decimal = "0.11" chrono = "0.4" -language-tags = "0.2" failure = "0.1" regex = "1" diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 1e412c2b..6480e162 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -6,7 +6,6 @@ use crate::store::encoded::EncodedQuadsStore; use crate::store::numeric_encoder::*; use crate::Result; use chrono::prelude::*; -use language_tags::LanguageTag; use num_traits::identities::Zero; use num_traits::FromPrimitive; use num_traits::One; @@ -19,7 +18,6 @@ use std::collections::BTreeMap; use std::collections::HashSet; use std::iter::once; use std::iter::Iterator; -use std::str::FromStr; use std::sync::Arc; use std::sync::Mutex; use uuid::Uuid; @@ -583,9 +581,15 @@ impl SimpleEvaluator { if language_range == "*" { !language_tag.is_empty() } else { - LanguageTag::from_str(&language_range) - .ok()? - .matches(&LanguageTag::from_str(&language_tag).ok()?) + !ZipLongest::new(language_range.split('-'), language_tag.split('-')).any( + |parts| match parts { + (Some(range_subtag), Some(language_subtag)) => { + !range_subtag.eq_ignore_ascii_case(language_subtag) + } + (Some(_), None) => true, + (None, _) => false, + }, + ) } .into(), ) @@ -1349,3 +1353,27 @@ impl<'a, S: EncodedQuadsStore> Iterator for DescribeIterator<'a, S> { } } } + +struct ZipLongest, I2: Iterator> { + a: I1, + b: I2, +} + +impl, I2: Iterator> ZipLongest { + fn new(a: I1, b: I2) -> Self { + Self { a, b } + } +} + +impl, I2: Iterator> Iterator + for ZipLongest +{ + type Item = (Option, Option); + + fn next(&mut self) -> Option<(Option, Option)> { + match (self.a.next(), self.b.next()) { + (None, None) => None, + r => Some(r), + } + } +} diff --git a/lib/tests/sparql_test_cases.rs b/lib/tests/sparql_test_cases.rs index e29d6582..a7a0f2c7 100644 --- a/lib/tests/sparql_test_cases.rs +++ b/lib/tests/sparql_test_cases.rs @@ -178,13 +178,6 @@ fn sparql_w3c_query_evaluation_testsuite() { NamedNode::from_str( "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-lang-3", ).unwrap(), - //Difference in language matching - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-langMatches-basic", - ).unwrap(), - NamedNode::from_str( - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-langMatches-basic", - ).unwrap(), //DATATYPE("foo"@en) returns rdf:langString in SPARQL 1.1 NamedNode::from_str( "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#dawg-datatype-2",