You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/07/24 08:08:50 UTC

svn commit: r1364905 - in /lucene/dev/branches/lucene2510: dev-tools/eclipse/ lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/ lucene/analysis/stempel/src/resources/META-INF/ lucene/analysis/stempel/src/resources/META-INF/services/ ...

Author: rmuir
Date: Tue Jul 24 06:08:49 2012
New Revision: 1364905

URL: http://svn.apache.org/viewvc?rev=1364905&view=rev
Log:
LUCENE-4044: port over stempel/uima

Added:
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java
      - copied, changed from r1364864, lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java   (with props)
    lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java
      - copied, changed from r1364864, lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java
    lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java
      - copied, changed from r1364864, lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java
    lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java
      - copied, changed from r1364864, lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java
    lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/
    lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/
    lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory
Removed:
    lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/
    lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java
    lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/
Modified:
    lucene/dev/branches/lucene2510/dev-tools/eclipse/dot.classpath

Modified: lucene/dev/branches/lucene2510/dev-tools/eclipse/dot.classpath
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/dev-tools/eclipse/dot.classpath?rev=1364905&r1=1364904&r2=1364905&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/dev-tools/eclipse/dot.classpath (original)
+++ lucene/dev/branches/lucene2510/dev-tools/eclipse/dot.classpath Tue Jul 24 06:08:49 2012
@@ -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"/>

Copied: lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java (from r1364864, lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java?p2=lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java&p1=lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java&r1=1364864&r2=1364905&rev=1364905&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/java/org/apache/solr/analysis/StempelPolishStemFilterFactory.java (original)
+++ lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/stempel/StempelPolishStemFilterFactory.java Tue Jul 24 06:08:49 2012
@@ -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.TokenS
 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 StempelPolishStemFilterFact
     try {
       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);
     }
   }
 }

Added: lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory?rev=1364905&view=auto
==============================================================================
--- lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory (added)
+++ lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory Tue Jul 24 06:08:49 2012
@@ -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.StempelPolishStemFilterFactory

Added: lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java?rev=1364905&view=auto
==============================================================================
--- lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java (added)
+++ lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/ResourceAsStreamResourceLoader.java Tue Jul 24 06:08:49 2012
@@ -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);
+    }
+  }
+}

Copied: lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java (from r1364864, lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java?p2=lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java&p1=lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java&r1=1364864&r2=1364905&rev=1364905&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/solr/contrib/analysis-extras/src/test/org/apache/solr/analysis/TestStempelPolishStemFilterFactory.java (original)
+++ lucene/dev/branches/lucene2510/lucene/analysis/stempel/src/test/org/apache/lucene/analysis/stempel/TestStempelPolishStemFilterFactory.java Tue Jul 24 06:08:49 2012
@@ -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.SolrResource
  * 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 TestStempelPolishStemFilter
   public 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" });

Copied: lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java (from r1364864, lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java?p2=lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java&p1=lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java&r1=1364864&r2=1364905&rev=1364905&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMAAnnotationsTokenizerFactory.java (original)
+++ lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java Tue Jul 24 06:08:49 2012
@@ -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 more

Copied: lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java (from r1364864, lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java?p2=lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java&p1=lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java&r1=1364864&r2=1364905&rev=1364905&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/solr/contrib/uima/src/java/org/apache/solr/uima/analysis/UIMATypeAwareAnnotationsTokenizerFactory.java (original)
+++ lucene/dev/branches/lucene2510/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java Tue Jul 24 06:08:49 2012
@@ -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 more

Added: lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory?rev=1364905&view=auto
==============================================================================
--- lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory (added)
+++ lucene/dev/branches/lucene2510/lucene/analysis/uima/src/resources/META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory Tue Jul 24 06:08:49 2012
@@ -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