ansj分词器使用(java)

一 导入依赖



    org.ansj
    ansj_seg
    5.1.6

二、分词方式

package com.vortex.commonAPI.controller;

import javax.servlet.http.HttpServletRequest;

import org.ansj.splitWord.analysis.BaseAnalysis;
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "ansjSegmenter")
public class AnsjSegmenterController {
    // 1.基本分词-BaseAnalysis
    // 最小粒度 功能有限
    @RequestMapping(value = "/baseAnalysis", method = RequestMethod.GET)
    public Object baseAnalysis(HttpServletRequest request) {
        String words = request.getParameter("words");
        return BaseAnalysis.parse(words);
        // 不带词性
        // return BaseAnalysis.parse(words).toStringWithOutNature();
    }

    // 2.精准分词-ToAnalysis
    // 它在易用性,稳定性.准确性.以及分词效率上.都取得了一个不错的平衡。
    @RequestMapping(value = "/toAnalysis", method = RequestMethod.GET)
    public Object toAnalysis(HttpServletRequest request) {
        String words = request.getParameter("words");
        return ToAnalysis.parse(words);
        // 不带词性
        // return ToAnalysis.parse(words).toStringWithOutNature();
    }

    // 3.nlp分词-NlpAnalysis
    // nlp的适用方式:语法实体名抽取.未登录词整理.
    @RequestMapping(value = "/nlpAnalysis", method = RequestMethod.GET)
    public Object nlpAnalysis(HttpServletRequest request) {
        String words = request.getParameter("words");
        return NlpAnalysis.parse(words);
        // 不带词性
        // return NlpAnalysis.parse(words).toStringWithOutNature();
    }

    // 4.面向索引的分词-IndexAnalysis
    // 面向索引的分词,故名思议就是适合在lucene等文本检索中用到的分词。
    // 召回率:召回率是对分词结果尽可能的涵盖
    // 准确率:其实这和召回本身是具有一定矛盾性,Ansj的强大之处是很巧妙的避开了这两个的冲突
    @RequestMapping(value = "/indexAnalysis", method = RequestMethod.GET)
    public Object indexAnalysis(HttpServletRequest request) {
        String words = request.getParameter("words");
        return IndexAnalysis.parse(words);
        // 不带词性
        // return IndexAnalysis.parse(words).toStringWithOutNature();
    }
}

三、功能统计


image.png

你可能感兴趣的:(ansj分词器使用(java))