forked from ysc/word
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
70 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/main/java/org/apdplat/word/elasticsearch/ChineseWordAnalysisBinderProcessor.java
This file was deleted.
Oops, something went wrong.
48 changes: 14 additions & 34 deletions
48
src/main/java/org/apdplat/word/elasticsearch/ChineseWordAnalyzerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,39 @@ | ||
/** | ||
* | ||
* APDPlat - Application Product Development Platform | ||
* Copyright (c) 2013, 杨尚川, [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package org.apdplat.word.elasticsearch; | ||
|
||
import org.apdplat.word.lucene.ChineseWordAnalyzer; | ||
import org.apdplat.word.segmentation.Segmentation; | ||
import org.apdplat.word.segmentation.SegmentationAlgorithm; | ||
import org.apdplat.word.segmentation.SegmentationFactory; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.inject.assistedinject.Assisted; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* 中文分析器工厂 | ||
* @author 杨尚川 | ||
* Created by ysc on 25/10/2017. | ||
*/ | ||
public class ChineseWordAnalyzerProvider extends AbstractIndexAnalyzerProvider<ChineseWordAnalyzer> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ChineseWordAnalyzerProvider.class); | ||
|
||
private final ChineseWordAnalyzer analyzer; | ||
@Inject | ||
public ChineseWordAnalyzerProvider(Index index, Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { | ||
super(index, indexSettings, name, settings); | ||
private final Segmentation segmentation; | ||
|
||
public ChineseWordAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) { | ||
super(indexSettings, name, settings); | ||
String segAlgorithm = settings.get("segAlgorithm"); | ||
if(segAlgorithm != null){ | ||
LOGGER.info("analyzer使用指定分词算法:"+segAlgorithm); | ||
Segmentation segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.valueOf(segAlgorithm)); | ||
analyzer = new ChineseWordAnalyzer(segmentation); | ||
LOGGER.info("tokenizer使用指定分词算法:"+segAlgorithm); | ||
segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.valueOf(segAlgorithm)); | ||
}else{ | ||
LOGGER.info("没有为word analyzer指定segAlgorithm参数"); | ||
LOGGER.info("analyzer使用默认分词算法:"+SegmentationAlgorithm.BidirectionalMaximumMatching); | ||
analyzer = new ChineseWordAnalyzer(); | ||
LOGGER.info("没有为word tokenizer指定segAlgorithm参数"); | ||
LOGGER.info("tokenizer使用默认分词算法:"+SegmentationAlgorithm.MaxNgramScore); | ||
segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.MaxNgramScore); | ||
} | ||
analyzer = new ChineseWordAnalyzer(segmentation); | ||
} | ||
|
||
@Override | ||
public ChineseWordAnalyzer get() { | ||
return this.analyzer; | ||
|
116 changes: 0 additions & 116 deletions
116
src/main/java/org/apdplat/word/elasticsearch/ChineseWordIndicesAnalysis.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
src/main/java/org/apdplat/word/elasticsearch/ChineseWordIndicesAnalysisModule.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/java/org/apdplat/word/elasticsearch/ChineseWordNoOpTokenFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.apdplat.word.elasticsearch; | ||
|
||
import org.apache.lucene.analysis.TokenStream; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory; | ||
|
||
/** | ||
* Created by ysc on 25/10/2017. | ||
*/ | ||
public class ChineseWordNoOpTokenFilterFactory extends AbstractTokenFilterFactory { | ||
|
||
public ChineseWordNoOpTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { | ||
super(indexSettings, name, settings); | ||
} | ||
|
||
@Override | ||
public TokenStream create(TokenStream tokenStream) { | ||
return tokenStream; | ||
} | ||
} |
Oops, something went wrong.