jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [1/5] jena git commit: Add support for ComplexPhraseQueryParser to jena-text
Date Tue, 17 May 2016 13:28:50 GMT
Repository: jena
Updated Branches:
  refs/heads/master 5f79d00e6 -> 933a32384


Add support for ComplexPhraseQueryParser to jena-text


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

Branch: refs/heads/master
Commit: b89f0ea4fcfef4443ce813b8026bb9fda965e668
Parents: b327978
Author: Andrew Dolby <andrewdolby@gmail.com>
Authored: Sun May 15 09:59:38 2016 -0400
Committer: Andrew Dolby <andrewdolby@gmail.com>
Committed: Sun May 15 09:59:38 2016 -0400

----------------------------------------------------------------------
 .../apache/jena/query/text/TextIndexLucene.java |   7 +-
 .../org/apache/jena/query/text/TS_Text.java     |   5 +-
 ...TestDatasetWithComplexPhraseQueryParser.java | 128 +++++++++++++++++++
 3 files changed, 136 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/b89f0ea4/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
index f2e3786..f8d5937 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
@@ -35,6 +35,7 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer ;
 import org.apache.lucene.document.* ;
 import org.apache.lucene.index.* ;
 import org.apache.lucene.queryparser.analyzing.AnalyzingQueryParser ;
+import org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser ;
 import org.apache.lucene.queryparser.classic.ParseException ;
 import org.apache.lucene.queryparser.classic.QueryParser ;
 import org.apache.lucene.queryparser.classic.QueryParserBase ;
@@ -291,13 +292,15 @@ public class TextIndexLucene implements TextIndex {
             throw new TextIndexException(ex) ;
         }
     }
-    
+
     private QueryParser getQueryParser(Analyzer analyzer) {
         switch(queryParserType) {
             case "QueryParser":
                 return new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
             case "AnalyzingQueryParser":
                 return new AnalyzingQueryParser(VER, docDef.getPrimaryField(), analyzer)
;
+            case "ComplexPhraseQueryParser":
+                return new ComplexPhraseQueryParser(VER, docDef.getPrimaryField(), analyzer);
             default:
                 log.warn("Unknown query parser type '" + queryParserType + "'. Defaulting
to standard QueryParser") ;
                 return new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
@@ -310,7 +313,7 @@ public class TextIndexLucene implements TextIndex {
         Query query = queryParser.parse(queryString) ;
         return query ;
     }
-    
+
     protected Query preParseQuery(String queryString, Analyzer analyzer) throws ParseException
{
         return parseQuery(queryString, analyzer);
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/b89f0ea4/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
index 2ee1dd3..beff77b 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TS_Text.java
@@ -36,9 +36,9 @@ import org.junit.runners.Suite.SuiteClasses ;
     , TestDatasetWithLuceneTextIndexDeletionSupport.class
     , TestDatasetWithLuceneStoredLiterals.class
 
-    // Embedded solr not supported 
+    // Embedded solr not supported
     //, TestDatasetWithEmbeddedSolrTextIndex.class
-    
+
     , TestEntityMapAssembler.class
     , TestTextDatasetAssembler.class
     , TestTextIndexLuceneAssembler.class
@@ -52,6 +52,7 @@ import org.junit.runners.Suite.SuiteClasses ;
     , TestDatasetWithLocalizedAnalyzer.class
     , TestDatasetWithConfigurableAnalyzer.class
     , TestDatasetWithAnalyzingQueryParser.class
+    , TestDatasetWithComplexPhraseQueryParser.class
 })
 
 public class TS_Text

http://git-wip-us.apache.org/repos/asf/jena/blob/b89f0ea4/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithComplexPhraseQueryParser.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithComplexPhraseQueryParser.java
b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithComplexPhraseQueryParser.java
new file mode 100644
index 0000000..0d65869
--- /dev/null
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithComplexPhraseQueryParser.java
@@ -0,0 +1,128 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.query.text;
+
+import java.io.Reader ;
+import java.io.StringReader ;
+import java.util.Set ;
+
+import org.apache.jena.assembler.Assembler ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.text.assembler.TextAssembler ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.ModelFactory ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.ext.com.google.common.collect.Sets ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+/**
+ * This class defines a setup configuration for a dataset that uses a standard analyzer with
a Lucene index.
+ */
+public class TestDatasetWithComplexPhraseQueryParser extends AbstractTestDatasetWithTextIndexBase
{
+
+    private static final String SPEC_BASE = "http://example.org/spec#";
+    private static final String SPEC_ROOT_LOCAL = "lucene_text_dataset";
+    private static final String SPEC_ROOT_URI = SPEC_BASE + SPEC_ROOT_LOCAL;
+
+    private static String makeSpec(String analyzer, String parser) {
+        return StrUtils.strjoinNL(
+                    "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ",
+                    "prefix ja:   <http://jena.hpl.hp.com/2005/11/Assembler#> ",
+                    "prefix tdb:  <http://jena.hpl.hp.com/2008/tdb#>",
+                    "prefix text: <http://jena.apache.org/text#>",
+                    "prefix :     <" + SPEC_BASE + ">",
+                    "",
+                    "[] ja:loadClass    \"org.apache.jena.query.text.TextQuery\" .",
+                    "text:TextDataset      rdfs:subClassOf   ja:RDFDataset .",
+                    "text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .",
+
+                    ":" + SPEC_ROOT_LOCAL,
+                    "    a              text:TextDataset ;",
+                    "    text:dataset   :dataset ;",
+                    "    text:index     :indexLucene ;",
+                    "    .",
+                    "",
+                    ":dataset",
+                    "    a               ja:RDFDataset ;",
+                    "    ja:defaultGraph :graph ;",
+                    ".",
+                    ":graph",
+                    "    a               ja:MemoryModel ;",
+                    ".",
+                    "",
+                    ":indexLucene",
+                    "    a text:TextIndexLucene ;",
+                    "    text:directory \"mem\" ;",
+                    "    text:queryParser " + parser + ";",
+                    "    text:entityMap :entMap ;",
+                    "    .",
+                    "",
+                    ":entMap",
+                    "    a text:EntityMap ;",
+                    "    text:entityField      \"uri\" ;",
+                    "    text:defaultField     \"label\" ;",
+                    "    text:map (",
+                    "         [ text:field \"label\" ; ",
+                    "           text:predicate rdfs:label ;",
+                    "           text:analyzer [ a " + analyzer + " ]",
+                    "         ]",
+                    "         [ text:field \"comment\" ; text:predicate rdfs:comment ]",
+                    "         ) ."
+                    );
+    }
+
+    public void init(String analyzer, String parser) {
+        Reader reader = new StringReader(makeSpec(analyzer, parser));
+        Model specModel = ModelFactory.createDefaultModel();
+        specModel.read(reader, "", "TURTLE");
+        TextAssembler.init();
+        Resource root = specModel.getResource(SPEC_ROOT_URI);
+        dataset = (Dataset) Assembler.general.open(root);
+    }
+
+    @Before
+    public void before() {
+        init("text:StandardAnalyzer", "text:ComplexPhraseQueryParser");
+    }
+
+    @Test
+    public void testComplexPhraseQueryParserPerformsPhraseFuzzyQuery() {
+        final String testName = "testComplexPhraseQueryParserPerformsPhraseFuzzyQuery";
+        final String turtle = StrUtils.strjoinNL(
+                TURTLE_PROLOG,
+                "<" + RESOURCE_BASE + testName + ">",
+                "  rdfs:label 'secondary education'",
+                ".",
+                "<" + RESOURCE_BASE + "irrelevant>",
+                "  rdfs:label 'tertiary elucidation'",
+                "."
+                );
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'scondar~ edcation~' 10 ) .",
+                "}"
+                );
+        Set<String> expectedURIs = Sets.newHashSet(RESOURCE_BASE + testName);
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+}


Mime
View raw message