You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2020/09/20 15:31:49 UTC
[jena] branch master updated: LangMatches comments
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/master by this push:
new e8969d6 LangMatches comments
new b92c335 Merge pull request #798 from afs/langmatches-comments
e8969d6 is described below
commit e8969d6cb6bf009e073b690e03cf2d522ece1a60
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Thu Sep 17 15:49:21 2020 +0100
LangMatches comments
---
.../jena/sparql/expr/nodevalue/NodeFunctions.java | 33 +++++++++++++++++-----
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
index 711c1c0..609c04f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
@@ -286,13 +286,26 @@ public class NodeFunctions {
return NodeValue.booleanReturn(langMatches(langStr, langPattern));
}
- /** The algortihm for the SPARQ function "LANGMATCHES".
- *
+ /** The algorithm for the SPARQL function "LANGMATCHES".
+ * Matching in SPARQL is defined to be the language tag matching of
+ * <a href="https://tools.ietf.org/html/rfc4647">RFC 4647</a>, part of
+ * <a href="https://tools.ietf.org/html/bcp47">BCP 47</a>.
+ * <p>
+ * SPARQL uses basic matching which is single "*" or a prefix of subtags.
+ * <p>
+ * This code does not implement extended matching correctly.
+ *
* @param langStr The language string
- * @param langPattern The pattern to match against
- * @return Whether there is a match.
+ * @param langPattern The pattern to match against
+ * @return Whether there is a match.
*/
public static boolean langMatches(String langStr, String langPattern) {
+ // Nowadays there is JDK support for language tags:
+ // List<Locale.LanguageRange> parse = Locale.LanguageRange.parse(langPattern);
+ // List<String> strings = Locale.filterTags(parse, Collections.singletonList(langTag));
+ // return !strings.isEmpty();
+ // which churns quite a few small objects so compiling fixed langPattern would be sensible.
+
if ( langPattern.equals("*") ) {
// Not a legal lang string.
if ( langStr == null || langStr.equals("") )
@@ -300,7 +313,13 @@ public class NodeFunctions {
return true ;
}
- // See RFC 3066 (it's "tag (-tag)*)"
+ // Basic Language Range
+ // language-range = (1*8ALPHA *("-" 1*8alphanum)) / "*"
+ // alphanum = ALPHA / DIGIT
+
+ // Extended Language Range
+ // extended-language-range = (1*8ALPHA / "*")
+ // *("-" (1*8alphanum / "*"))
String[] langElts = langStr.split("-") ;
String[] langRangeElts = langPattern.split("-") ;
@@ -313,9 +332,9 @@ public class NodeFunctions {
/*
* RFC 4647 basic filtering.
- *
+ *
* Notes for extended:
- * 1. Remove any -*- (but not *-)
+ * 1. Remove any "-*" (but not *)
* 2. Compare primary tags.
* 3. Is the remaining range a subsequence of the remaining language tag?
*/