Apache Lucene open-source search software
LUCENE-4044: port over stempel/uima
Robert Muirdfe9a8444a50
diff --git a/dev-tools/eclipse/dot.classpath b/dev-tools/eclipse/dot.classpathindex e87c46b3e52..d90cec4c88d 100644--- a/dev-tools/eclipse/dot.classpath+++ b/dev-tools/eclipse/dot.classpath@@ -38,6 +38,7 @@<classpathentry kind="src" path="lucene/analysis/morfologik/src/resources"/><classpathentry kind="src" path="lucene/analysis/morfologik/src/test"/><classpathentry kind="src" path="lucene/analysis/uima/src/java"/>+ <classpathentry kind="src" path="lucene/analysis/uima/src/resources"/><classpathentry kind="src" path="lucene/analysis/uima/src/test"/><classpathentry kind="src" path="lucene/benchmark/src/java"/><classpathentry kind="src" path="lucene/benchmark/src/test"/>diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java b/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.javasimilarity index 83%rename from solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.javarename to lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.javaindex 3340692471b..8ef0430545b 100644--- a/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java+++ b/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java@@ -1,4 +1,4 @@-package org.apache.solr.analysis;+package org.apache.lucene.analysis.stempel;/** Licensed to the Apache Software Foundation (ASF) under one or more@@ -23,8 +23,7 @@ import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.stempel.StempelFilter;import org.apache.lucene.analysis.stempel.StempelStemmer;import org.apache.lucene.analysis.util.ResourceLoader;-import org.apache.solr.common.SolrException;-import org.apache.solr.common.SolrException.ErrorCode;+import org.apache.lucene.analysis.util.InitializationException;import org.apache.lucene.analysis.util.ResourceLoaderAware;import org.apache.lucene.analysis.util.TokenFilterFactory;import org.egothor.stemmer.Trie;@@ -34,7 +33,7 @@ import org.egothor.stemmer.Trie;*/public class StempelPolishStemFilterFactory extends TokenFilterFactory implements ResourceLoaderAware {private Trie stemmer = null;- private static final String STEMTABLE = "org/apache/lucene/analysis/pl/stemmer_20000.tbl";+ private static final String STEMTABLE = "/org/apache/lucene/analysis/pl/stemmer_20000.tbl";public TokenStream create(TokenStream input) {return new StempelFilter(input, new StempelStemmer(stemmer));@@ -44,7 +43,7 @@ public class StempelPolishStemFilterFactory extends TokenFilterFactory implementtry {stemmer = StempelStemmer.load(loader.openResource(STEMTABLE));} catch (IOException e) {- throw new SolrException(ErrorCode.SERVER_ERROR, "Could not load stem table: " + STEMTABLE);+ throw new InitializationException("Could not load stem table: " + STEMTABLE, e);}}}diff --git a/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory b/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactorynew file mode 100644index 00000000000..f5e77c3671b--- /dev/null+++ b/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory@@ -0,0 +1,16 @@+# 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.++org.apache.lucene.analysis.stempel.StempelPolishStemFilterFactorydiff --git a/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.javanew file mode 100644index 00000000000..d3cf2df1353--- /dev/null+++ b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java@@ -0,0 +1,85 @@+package org.apache.lucene.analysis.stempel;++/*+ * 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.+ */++import java.io.BufferedReader;+import java.io.IOException;+import java.io.InputStream;+import java.io.InputStreamReader;+import java.nio.charset.CharacterCodingException;+import java.nio.charset.CodingErrorAction;+import java.util.ArrayList;+import java.util.List;++import org.apache.lucene.analysis.util.ResourceLoader;+import org.apache.lucene.util.IOUtils;++public class ResourceAsStreamResourceLoader implements ResourceLoader {+ Class<?> clazz;++ public ResourceAsStreamResourceLoader(Class<?> clazz) {+ this.clazz = clazz;+ }++ @Override+ public InputStream openResource(String resource) throws IOException {+ return clazz.getResourceAsStream(resource);+ }++ @Override+ public List<String> getLines(String resource) throws IOException {+ BufferedReader input = null;+ ArrayList<String> lines;+ try {+ input = new BufferedReader(new InputStreamReader(openResource(resource),+ IOUtils.CHARSET_UTF_8.newDecoder()+ .onMalformedInput(CodingErrorAction.REPORT)+ .onUnmappableCharacter(CodingErrorAction.REPORT)));++ lines = new ArrayList<String>();+ for (String word=null; (word=input.readLine())!=null;) {+ // skip initial bom marker+ if (lines.isEmpty() && word.length() > 0 && word.charAt(0) == '\uFEFF')+ word = word.substring(1);+ // skip comments+ if (word.startsWith("#")) continue;+ word=word.trim();+ // skip blank lines+ if (word.length()==0) continue;+ lines.add(word);+ }+ } catch (CharacterCodingException ex) {+ throw new RuntimeException("Error loading resource (wrong encoding?): " + resource, ex);+ } finally {+ if (input != null)+ input.close();+ }+ return lines;+ }++ // TODO: do this subpackages thing... wtf is that?+ @Override+ public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages) {+ try {+ Class<? extends T> clazz = Class.forName(cname).asSubclass(expectedType);+ return clazz.newInstance();+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }+}diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.javasimilarity index 91%rename from solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.javarename to lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.javaindex 46e83080763..f37a7bf0e80 100644--- a/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java+++ b/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java@@ -1,11 +1,4 @@-package org.apache.solr.analysis;--import java.io.StringReader;--import org.apache.lucene.analysis.BaseTokenStreamTestCase;-import org.apache.lucene.analysis.TokenStream;-import org.apache.lucene.analysis.core.WhitespaceTokenizer;-import org.apache.solr.core.SolrResourceLoader;+package org.apache.lucene.analysis.stempel;/** Licensed to the Apache Software Foundation (ASF) under one or more@@ -24,6 +17,12 @@ import org.apache.solr.core.SolrResourceLoader;* limitations under the License.*/+import java.io.StringReader;++import org.apache.lucene.analysis.BaseTokenStreamTestCase;+import org.apache.lucene.analysis.TokenStream;+import org.apache.lucene.analysis.core.WhitespaceTokenizer;+/*** Tests for {@link StempelPolishStemFilterFactory}*/@@ -31,7 +30,7 @@ public class TestStempelPolishStemFilterFactory extends BaseTokenStreamTestCasepublic void testBasics() throws Exception {StringReader document = new StringReader("studenta studenci");StempelPolishStemFilterFactory factory = new StempelPolishStemFilterFactory();- factory.inform(new SolrResourceLoader(null, null));+ factory.inform(new ResourceAsStreamResourceLoader(getClass()));TokenStream ts = factory.create(new WhitespaceTokenizer(TEST_VERSION_CURRENT, document));assertTokenStreamContents(ts,new String[] { "student", "student" });diff --git a/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.javasimilarity index 97%rename from solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.javarename to lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.javaindex 8467b792c69..e4a56e38df6 100644--- a/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java@@ -1,4 +1,4 @@-package org.apache.solr.uima.analysis;+package org.apache.lucene.analysis.uima;/** Licensed to the Apache Software Foundation (ASF) under one or morediff --git a/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.javasimilarity index 97%rename from solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.javarename to lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.javaindex 1efda6b47c0..f67ffc1f484 100644--- a/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java@@ -1,4 +1,4 @@-package org.apache.solr.uima.analysis;+package org.apache.lucene.analysis.uima;/** Licensed to the Apache Software Foundation (ASF) under one or morediff --git a/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory b/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactorynew file mode 100644index 00000000000..eeea38a7b1f--- /dev/null+++ b/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory@@ -0,0 +1,17 @@+# 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.++org.apache.lucene.analysis.uima.UIMAAnnotationsTokenizerFactory+org.apache.lucene.analysis.uima.UIMATypeAwareAnnotationsTokenizerFactory