jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From codefer...@apache.org
Subject [3/4] jena git commit: derive parameter type in the cases: int, boolean, String.
Date Wed, 21 Mar 2018 14:44:37 GMT
derive parameter type in the cases: int, boolean, String.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/71c2f66d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/71c2f66d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/71c2f66d

Branch: refs/heads/master
Commit: 71c2f66dbdad7834b7560f27b16eee08aad37abf
Parents: 58ff28e
Author: Chris Tomlinson <ct@moonvine.org>
Authored: Sun Mar 18 09:48:57 2018 -0500
Committer: Chris Tomlinson <ct@moonvine.org>
Committed: Sun Mar 18 09:48:57 2018 -0500

----------------------------------------------------------------------
 .../jena/query/text/assembler/Params.java       | 40 ++++++++++++++++----
 .../query/text/TestTextDefineAnalyzers.java     | 23 ++++++++++-
 2 files changed, 55 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/71c2f66d/jena-text/src/main/java/org/apache/jena/query/text/assembler/Params.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/assembler/Params.java b/jena-text/src/main/java/org/apache/jena/query/text/assembler/Params.java
index 7b0cd18..b1a3f33 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/assembler/Params.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/assembler/Params.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.jena.assembler.Assembler;
 import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.datatypes.RDFDatatype;
 import org.apache.jena.query.text.TextIndexException;
 import org.apache.jena.rdf.model.Literal;
 import org.apache.jena.rdf.model.RDFNode;
@@ -184,16 +185,10 @@ public class Params {
 
     protected static ParamSpec getParamSpec(Resource node) {
         Statement nameStmt = node.getProperty(TextVocab.pParamName);
-        Statement typeStmt = node.getProperty(TextVocab.pParamType);
         Statement valueStmt = node.getProperty(TextVocab.pParamValue);
         
-        if (typeStmt == null) {
-            throw new TextIndexException("Parameter specification must have a text:paramType:
" + node);
-        }        
-        Resource typeRes = typeStmt.getResource();
-        String type = typeRes.getLocalName();
-
         String name = getStringValue(nameStmt);
+        String type = getType(node);
         String value = getStringValue(valueStmt);
 
         switch (type) {
@@ -280,6 +275,37 @@ public class Params {
 
         return null;
     }
+    
+    private static String getType(Resource node) {
+        Statement typeStmt = node.getProperty(TextVocab.pParamType);
+        Statement valueStmt = node.getProperty(TextVocab.pParamValue);
+        String type = null;
+        
+        if (typeStmt == null) {
+
+            if (valueStmt == null) {
+                throw new TextIndexException("Parameter specification must have a text:paramValue:
" + node);
+            }
+            
+            RDFNode obj = valueStmt != null ? valueStmt.getObject() : null;
+            Literal lit = obj.asLiteral();
+            RDFDatatype rdfType = lit.getDatatype();
+            Class<?> clazz = rdfType.getJavaClass();
+
+            if (clazz == java.lang.Boolean.class) {
+                type = TYPE_BOOL;
+            } else if (clazz == java.math.BigInteger.class) {
+                type = TYPE_INT;
+            } else if (clazz == java.lang.String.class) {
+                type = TYPE_STRING;
+            }
+        } else {
+            Resource typeRes = typeStmt.getResource();
+            type = typeRes.getLocalName();
+        }
+        
+        return type;
+    }
 
     private static String getStringValue(Statement stmt) {
         if (stmt == null) {

http://git-wip-us.apache.org/repos/asf/jena/blob/71c2f66d/jena-text/src/test/java/org/apache/jena/query/text/TestTextDefineAnalyzers.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestTextDefineAnalyzers.java
b/jena-text/src/test/java/org/apache/jena/query/text/TestTextDefineAnalyzers.java
index b0c114e..5ffa1db 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TestTextDefineAnalyzers.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestTextDefineAnalyzers.java
@@ -78,13 +78,18 @@ public class TestTextDefineAnalyzers extends AbstractTestDatasetWithTextIndexBas
                     "                a text:ConfigurableAnalyzer ;",
                     "                text:tokenizer :ngram ;",
                     "                text:filters ( :asciiff text:LowerCaseFilter ) ] ]",
+                    "         [ text:defineAnalyzer :configuredAnalyzer2 ;",
+                    "           text:analyzer [",
+                    "                a text:ConfigurableAnalyzer ;",
+                    "                text:tokenizer :ngram2 ;",
+                    "                text:filters ( :asciiff2 text:LowerCaseFilter ) ] ]",
                     "         [ text:defineTokenizer :ngram ;",
                     "           text:tokenizer [",
                     "                a text:GenericTokenizer ;",
                     "                text:class \"org.apache.lucene.analysis.ngram.NGramTokenizer\"
;",
                     "                text:params (",
                     "                     [ text:paramName \"minGram\" ;",
-                    "                       text:paramType text:TypeInt ;",
+                    "                      text:paramType text:TypeInt ;",
                     "                       text:paramValue 3 ]",
                     "                     [ text:paramName \"maxGram\" ;",
                     "                       text:paramType text:TypeInt ;",
@@ -99,6 +104,22 @@ public class TestTextDefineAnalyzers extends AbstractTestDatasetWithTextIndexBas
                     "                       text:paramType text:TypeBoolean ;",
                     "                       text:paramValue true ]",
                     "                     ) ] ]",
+                    "         [ text:defineTokenizer :ngram2 ;",
+                    "           text:tokenizer [",
+                    "                a text:GenericTokenizer ;",
+                    "                text:class \"org.apache.lucene.analysis.ngram.NGramTokenizer\"
;",
+                    "                text:params (",
+                    "                     [ text:paramValue 3 ]",
+                    "                     [ text:paramValue 7 ]",
+                    "                     ) ] ]",
+                    "         [ text:defineFilter :asciiff2 ;",
+                    "           text:filter [",
+                    "                a text:GenericFilter ;",
+                    "                text:class \"org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter\"
;",
+                    "                text:params (",
+                    "                     [ text:paramName \"preserveOriginal\" ;",
+                    "                       text:paramValue true ]",
+                    "                     ) ] ]",
                     "         ) ;",
                     "    text:entityMap :entMap ;",
                     "    .",


Mime
View raw message