MMAnalyzer极易中文分词组件的jar包 maven配置
时间: 2023-10-09 09:13:53 浏览: 39
你可以在Maven项目中添加以下依赖:
```xml
<dependency>
<groupId>com.mmseg</groupId>
<artifactId>mmseg4j-core</artifactId>
<version>1.8.5</version>
</dependency>
```
这是MMAnalyzer的核心依赖。在你的Java代码中,你可以使用以下代码来进行分词:
```java
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.wltea.analyzer.lucene.IKAnalyzer;
public class Demo {
public static void main(String[] args) throws Exception {
String text = "这是一段测试文本";
Analyzer analyzer = new IKAnalyzer();
TokenStream tokenStream = analyzer.tokenStream("", text);
tokenStream.reset();
while (tokenStream.incrementToken()) {
CharTermAttribute charTermAttribute = tokenStream.getAttribute(CharTermAttribute.class);
System.out.println(charTermAttribute.toString());
}
tokenStream.end();
tokenStream.close();
}
}
```
以上代码使用了IKAnalyzer,但你可以将其替换为MMAnalyzer,只需要将`new IKAnalyzer()`替换为`new MMAnalyzer()`即可。