Skip to content

Commit

Permalink
Fix split package in analysis-kuromoji plugin (#78039) (#78119)
Browse files Browse the repository at this point in the history
The analysis-kuromoji plugin reuses server package names for analysis and
mappers. This commit moves the plugin implementation to use a single
package name, o.e.p.analysis.kuromoji
  • Loading branch information
rjernst authored Sep 21, 2021
1 parent d73722b commit 35873b7
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 37 deletions.
13 changes: 0 additions & 13 deletions plugins/analysis-kuromoji/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,3 @@ restResources {
tasks.named("dependencyLicenses").configure {
mapping from: /lucene-.*/, to: 'lucene'
}

tasks.named('splitPackagesAudit').configure {
// o.e.i.analysis is owned by server, these should be moved to a kuromoji package
ignoreClasses 'org.elasticsearch.index.analysis.JapaneseStopTokenFilterFactory',
'org.elasticsearch.index.analysis.KuromojiAnalyzerProvider',
'org.elasticsearch.index.analysis.KuromojiBaseFormFilterFactory',
'org.elasticsearch.index.analysis.KuromojiIterationMarkCharFilterFactory',
'org.elasticsearch.index.analysis.KuromojiKatakanaStemmerFactory',
'org.elasticsearch.index.analysis.KuromojiNumberFilterFactory',
'org.elasticsearch.index.analysis.KuromojiPartOfSpeechFilterFactory',
'org.elasticsearch.index.analysis.KuromojiReadingFormFilterFactory',
'org.elasticsearch.index.analysis.KuromojiTokenizerFactory'
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
import org.apache.lucene.analysis.Analyzer;
import org.elasticsearch.index.analysis.AnalyzerProvider;
import org.elasticsearch.index.analysis.CharFilterFactory;
import org.elasticsearch.index.analysis.JapaneseStopTokenFilterFactory;
import org.elasticsearch.index.analysis.KuromojiAnalyzerProvider;
import org.elasticsearch.index.analysis.KuromojiBaseFormFilterFactory;
import org.elasticsearch.index.analysis.KuromojiIterationMarkCharFilterFactory;
import org.elasticsearch.index.analysis.KuromojiKatakanaStemmerFactory;
import org.elasticsearch.index.analysis.KuromojiNumberFilterFactory;
import org.elasticsearch.index.analysis.KuromojiPartOfSpeechFilterFactory;
import org.elasticsearch.index.analysis.KuromojiReadingFormFilterFactory;
import org.elasticsearch.index.analysis.KuromojiTokenizerFactory;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;


import org.apache.lucene.analysis.CharArraySet;
Expand All @@ -17,13 +17,15 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
import org.elasticsearch.index.analysis.Analysis;

import java.util.Map;
import java.util.Set;

import static java.util.Collections.singletonMap;

public class JapaneseStopTokenFilterFactory extends AbstractTokenFilterFactory{
public class JapaneseStopTokenFilterFactory extends AbstractTokenFilterFactory {
private static final Map<String, Set<?>> NAMED_STOP_WORDS = singletonMap("_japanese_", JapaneseAnalyzer.getDefaultStopSet());

private final CharArraySet stopWords;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.CharArraySet;
import org.apache.lucene.analysis.ja.JapaneseAnalyzer;
Expand All @@ -15,6 +15,8 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;
import org.elasticsearch.index.analysis.Analysis;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ja.JapaneseBaseFormFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

public class KuromojiBaseFormFilterFactory extends AbstractTokenFilterFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.ja.JapaneseIterationMarkCharFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractCharFilterFactory;
import org.elasticsearch.index.analysis.NormalizingCharFilterFactory;

import java.io.Reader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ja.JapaneseKatakanaStemFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

public class KuromojiKatakanaStemmerFactory extends AbstractTokenFilterFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ja.JapaneseNumberFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

public class KuromojiNumberFilterFactory extends AbstractTokenFilterFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ja.JapaneseAnalyzer;
import org.apache.lucene.analysis.ja.JapanesePartOfSpeechStopFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
import org.elasticsearch.index.analysis.Analysis;

import java.util.HashSet;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ja.JapaneseReadingFormFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

public class KuromojiReadingFormFilterFactory extends AbstractTokenFilterFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.ja.JapaneseTokenizer;
Expand All @@ -17,6 +17,8 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenizerFactory;
import org.elasticsearch.index.analysis.Analysis;

import java.io.IOException;
import java.io.StringReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.ja.JapaneseTokenizerFactory;
import org.elasticsearch.indices.analysis.AnalysisFactoryTestCase;
import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiBaseFormFilterFactory;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiIterationMarkCharFilterFactory;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiKatakanaStemmerFactory;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiNumberFilterFactory;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiPartOfSpeechFilterFactory;
import org.elasticsearch.plugin.analysis.kuromoji.KuromojiReadingFormFilterFactory;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

package org.elasticsearch.index.analysis;
package org.elasticsearch.plugin.analysis.kuromoji;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
Expand All @@ -19,7 +19,13 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin;
import org.elasticsearch.index.analysis.AnalysisTestsHelper;
import org.elasticsearch.index.analysis.CharFilterFactory;
import org.elasticsearch.index.analysis.CustomAnalyzer;
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -69,7 +75,7 @@ public void testDefaultsKuromojiAnalysis() throws IOException {
assertThat(analyzer.analyzer(), instanceOf(CustomAnalyzer.class));
assertThat(analyzer.analyzer().tokenStream(null, new StringReader("")), instanceOf(JapaneseTokenizer.class));

CharFilterFactory charFilterFactory = analysis.charFilter.get("kuromoji_iteration_mark");
CharFilterFactory charFilterFactory = analysis.charFilter.get("kuromoji_iteration_mark");
assertThat(charFilterFactory, instanceOf(KuromojiIterationMarkCharFilterFactory.class));

}
Expand Down Expand Up @@ -199,7 +205,7 @@ private static TestAnalysis createTestAnalysis() throws IOException {
Files.createDirectory(config);
Files.copy(empty_dict, config.resolve("empty_user_dict.txt"));
Files.copy(dict, config.resolve("user_dict.txt"));
String json = "/org/elasticsearch/index/analysis/kuromoji_analysis.json";
String json = "/org/elasticsearch/plugin/analysis/kuromoji/kuromoji_analysis.json";

Settings settings = Settings.builder()
.loadFromStream(json, KuromojiAnalysisTests.class.getResourceAsStream(json), false)
Expand Down

0 comments on commit 35873b7

Please sign in to comment.