From 1956788f0d534b0aaacd1ef59b3d292d18762463 Mon Sep 17 00:00:00 2001 From: Pavel Danchenko Date: Wed, 20 Dec 2017 11:14:43 +0100 Subject: [PATCH] Builder method to configure custom ResourceResolver --- .../java/com/atilika/kuromoji/TokenizerBase.java | 12 ++++++++++++ .../atilika/kuromoji/ipadic/neologd/Tokenizer.java | 4 ++-- .../java/com/atilika/kuromoji/ipadic/Tokenizer.java | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kuromoji-core/src/main/java/com/atilika/kuromoji/TokenizerBase.java b/kuromoji-core/src/main/java/com/atilika/kuromoji/TokenizerBase.java index e215a4c..ae4413f 100644 --- a/kuromoji-core/src/main/java/com/atilika/kuromoji/TokenizerBase.java +++ b/kuromoji-core/src/main/java/com/atilika/kuromoji/TokenizerBase.java @@ -403,6 +403,18 @@ protected void loadDictionaries() { */ public abstract T build(); + /** + * Sets user-defined {@link ResourceResolver}. + * + * @param resolver {@link com.atilika.kuromoji.util.SimpleResourceResolver SimpleResourceResolver} + * or user-defined implementation. + * @return this builder + */ + public Builder resolver(ResourceResolver resolver) { + this.resolver = resolver; + return this; + } + /** * Sets an optional user dictionary as an input stream *

diff --git a/kuromoji-ipadic-neologd/src/main/java/com/atilika/kuromoji/ipadic/neologd/Tokenizer.java b/kuromoji-ipadic-neologd/src/main/java/com/atilika/kuromoji/ipadic/neologd/Tokenizer.java index eee48b5..535f272 100644 --- a/kuromoji-ipadic-neologd/src/main/java/com/atilika/kuromoji/ipadic/neologd/Tokenizer.java +++ b/kuromoji-ipadic-neologd/src/main/java/com/atilika/kuromoji/ipadic/neologd/Tokenizer.java @@ -112,6 +112,8 @@ public Builder() { readingFeature = DictionaryEntry.READING_FEATURE; partOfSpeechFeature = DictionaryEntry.PART_OF_SPEECH_FEATURE; + resolver = new SimpleResourceResolver(this.getClass()); + tokenFactory = new TokenFactory() { @Override public Token createToken(int wordId, @@ -211,8 +213,6 @@ protected void loadDictionaries() { penalties.add(otherPenaltyLengthThreshold); penalties.add(otherPenalty); - resolver = new SimpleResourceResolver(this.getClass()); - try { fst = FST.newInstance(resolver); connectionCosts = ConnectionCosts.newInstance(resolver); diff --git a/kuromoji-ipadic/src/main/java/com/atilika/kuromoji/ipadic/Tokenizer.java b/kuromoji-ipadic/src/main/java/com/atilika/kuromoji/ipadic/Tokenizer.java index 3e90125..4908377 100644 --- a/kuromoji-ipadic/src/main/java/com/atilika/kuromoji/ipadic/Tokenizer.java +++ b/kuromoji-ipadic/src/main/java/com/atilika/kuromoji/ipadic/Tokenizer.java @@ -112,6 +112,8 @@ public Builder() { readingFeature = DictionaryEntry.READING_FEATURE; partOfSpeechFeature = DictionaryEntry.PART_OF_SPEECH_FEATURE; + resolver = new SimpleResourceResolver(this.getClass()); + tokenFactory = new TokenFactory() { @Override public Token createToken(int wordId, @@ -211,8 +213,6 @@ protected void loadDictionaries() { penalties.add(otherPenaltyLengthThreshold); penalties.add(otherPenalty); - resolver = new SimpleResourceResolver(this.getClass()); - try { fst = FST.newInstance(resolver); connectionCosts = ConnectionCosts.newInstance(resolver);