mirror of https://github.com/apache/lucene.git
LUCENE-4044: get all lucene tests passing
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2510@1364891 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5cc38490d0
commit
e7ff3048ce
|
@ -0,0 +1,53 @@
|
|||
package org.apache.lucene.analysis.ja;
|
||||
|
||||
/*
|
||||
* 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.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.analysis.util.ResourceLoader;
|
||||
|
||||
/** Fake resource loader for tests: works if you want to fake reading a single file */
|
||||
class StringMockResourceLoader implements ResourceLoader {
|
||||
String text;
|
||||
|
||||
public StringMockResourceLoader(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public List<String> getLines(String resource) throws IOException {
|
||||
return Arrays.asList(text.split("\n"));
|
||||
}
|
||||
|
||||
// TODO: do this subpackages thing... wtf is that?
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream openResource(String resource) throws IOException {
|
||||
return new ByteArrayInputStream(text.getBytes("UTF-8"));
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
/**
|
||||
* Simple tests for {@link JapaneseBaseFormFilterFactory}
|
||||
|
@ -35,7 +34,7 @@ public class TestJapaneseBaseFormFilterFactory extends BaseTokenStreamTestCase {
|
|||
tokenizerFactory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
|
||||
Map<String, String> args = Collections.emptyMap();
|
||||
tokenizerFactory.init(args);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = tokenizerFactory.create(new StringReader("それはまだ実験段階にあります"));
|
||||
JapaneseBaseFormFilterFactory factory = new JapaneseBaseFormFilterFactory();
|
||||
ts = factory.create(ts);
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
|||
import org.apache.lucene.analysis.CharFilter;
|
||||
import org.apache.lucene.analysis.MockTokenizer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
@ -30,7 +29,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple tests for {@link org.apache.solr.analysis.JapaneseIterationMarkCharFilterFactory}
|
||||
* Simple tests for {@link JapaneseIterationMarkCharFilterFactory}
|
||||
*/
|
||||
public class TestJapaneseIterationMarkCharFilterFactory extends BaseTokenStreamTestCase {
|
||||
|
||||
|
@ -46,7 +45,7 @@ public class TestJapaneseIterationMarkCharFilterFactory extends BaseTokenStreamT
|
|||
JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory();
|
||||
Map<String, String> tokenizerArgs = Collections.emptyMap();
|
||||
tokenizerFactory.init(tokenizerArgs);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
|
||||
JapaneseIterationMarkCharFilterFactory filterFactory = new JapaneseIterationMarkCharFilterFactory();
|
||||
Map<String, String> filterArgs = Collections.emptyMap();
|
||||
|
@ -63,7 +62,7 @@ public class TestJapaneseIterationMarkCharFilterFactory extends BaseTokenStreamT
|
|||
JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory();
|
||||
Map<String, String> tokenizerArgs = Collections.emptyMap();
|
||||
tokenizerFactory.init(tokenizerArgs);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
|
||||
JapaneseIterationMarkCharFilterFactory filterFactory = new JapaneseIterationMarkCharFilterFactory();
|
||||
Map<String, String> filterArgs = new HashMap<String, String>();
|
||||
|
@ -82,7 +81,7 @@ public class TestJapaneseIterationMarkCharFilterFactory extends BaseTokenStreamT
|
|||
JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory();
|
||||
Map<String, String> tokenizerArgs = Collections.emptyMap();
|
||||
tokenizerFactory.init(tokenizerArgs);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
|
||||
JapaneseIterationMarkCharFilterFactory filterFactory = new JapaneseIterationMarkCharFilterFactory();
|
||||
Map<String, String> filterArgs = new HashMap<String, String>();
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.analysis.ja;
|
|||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
@ -34,7 +33,7 @@ public class TestJapaneseKatakanaStemFilterFactory extends BaseTokenStreamTestCa
|
|||
JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory();
|
||||
Map<String, String> tokenizerArgs = Collections.emptyMap();
|
||||
tokenizerFactory.init(tokenizerArgs);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream tokenStream = tokenizerFactory.create(
|
||||
new StringReader("明後日パーティーに行く予定がある。図書館で資料をコピーしました。")
|
||||
);
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
/**
|
||||
* Simple tests for {@link JapanesePartOfSpeechStopFilterFactory}
|
||||
|
@ -40,14 +39,14 @@ public class TestJapanesePartOfSpeechStopFilterFactory extends BaseTokenStreamTe
|
|||
tokenizerFactory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
|
||||
Map<String, String> tokenizerArgs = Collections.emptyMap();
|
||||
tokenizerFactory.init(tokenizerArgs);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = tokenizerFactory.create(new StringReader("私は制限スピードを超える。"));
|
||||
JapanesePartOfSpeechStopFilterFactory factory = new JapanesePartOfSpeechStopFilterFactory();
|
||||
Map<String,String> args = new HashMap<String,String>();
|
||||
args.put("tags", "stoptags.txt");
|
||||
factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
|
||||
factory.init(args);
|
||||
factory.inform(new StringMockSolrResourceLoader(tags));
|
||||
factory.inform(new StringMockResourceLoader(tags));
|
||||
ts = factory.create(ts);
|
||||
assertTokenStreamContents(ts,
|
||||
new String[] { "私", "は", "制限", "スピード", "を" }
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.lucene.analysis.ja;
|
|||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
@ -34,7 +33,7 @@ public class TestJapaneseReadingFormFilterFactory extends BaseTokenStreamTestCas
|
|||
JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory();
|
||||
Map<String, String> args = Collections.emptyMap();
|
||||
tokenizerFactory.init(args);
|
||||
tokenizerFactory.inform(new SolrResourceLoader(null, null));
|
||||
tokenizerFactory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream tokenStream = tokenizerFactory.create(new StringReader("先ほどベルリンから来ました。"));
|
||||
JapaneseReadingFormFilterFactory filterFactory = new JapaneseReadingFormFilterFactory();
|
||||
assertTokenStreamContents(filterFactory.create(tokenStream),
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.solr.core.SolrResourceLoader;
|
||||
|
||||
/**
|
||||
* Simple tests for {@link JapaneseTokenizerFactory}
|
||||
|
@ -36,7 +35,7 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
|
|||
factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
|
||||
Map<String, String> args = Collections.emptyMap();
|
||||
factory.init(args);
|
||||
factory.inform(new SolrResourceLoader(null, null));
|
||||
factory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = factory.create(new StringReader("これは本ではない"));
|
||||
assertTokenStreamContents(ts,
|
||||
new String[] { "これ", "は", "本", "で", "は", "ない" },
|
||||
|
@ -53,7 +52,7 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
|
|||
factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
|
||||
Map<String, String> args = Collections.emptyMap();
|
||||
factory.init(args);
|
||||
factory.inform(new SolrResourceLoader(null, null));
|
||||
factory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = factory.create(new StringReader("シニアソフトウェアエンジニア"));
|
||||
assertTokenStreamContents(ts,
|
||||
new String[] { "シニア", "シニアソフトウェアエンジニア", "ソフトウェア", "エンジニア" }
|
||||
|
@ -68,7 +67,7 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
|
|||
Map<String,String> args = new HashMap<String,String>();
|
||||
args.put("mode", "normal");
|
||||
factory.init(args);
|
||||
factory.inform(new SolrResourceLoader(null, null));
|
||||
factory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = factory.create(new StringReader("シニアソフトウェアエンジニア"));
|
||||
assertTokenStreamContents(ts,
|
||||
new String[] { "シニアソフトウェアエンジニア" }
|
||||
|
@ -89,7 +88,7 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
|
|||
Map<String,String> args = new HashMap<String,String>();
|
||||
args.put("userDictionary", "userdict.txt");
|
||||
factory.init(args);
|
||||
factory.inform(new StringMockSolrResourceLoader(userDict));
|
||||
factory.inform(new StringMockResourceLoader(userDict));
|
||||
TokenStream ts = factory.create(new StringReader("関西国際空港に行った"));
|
||||
assertTokenStreamContents(ts,
|
||||
new String[] { "関西", "国際", "空港", "に", "行っ", "た" }
|
||||
|
@ -104,7 +103,7 @@ public class TestJapaneseTokenizerFactory extends BaseTokenStreamTestCase {
|
|||
Map<String,String> args = new HashMap<String,String>();
|
||||
args.put("discardPunctuation", "false");
|
||||
factory.init(args);
|
||||
factory.inform(new SolrResourceLoader(null, null));
|
||||
factory.inform(new StringMockResourceLoader(""));
|
||||
TokenStream ts = factory.create(
|
||||
new StringReader("今ノルウェーにいますが、来週の頭日本に戻ります。楽しみにしています!お寿司が食べたいな。。。")
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue