Spark中文分词-成都快上网建站

Spark中文分词

Spark 中文分词

一、导入需要的分词包

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都做网站、平阳网络推广、小程序开发、平阳网络营销、平阳企业策划、平阳品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供平阳建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

import org.ansj.domain.Term
import org.ansj.recognition.impl.StopRecognition
import org.ansj.splitWord.analysis.ToAnalysis

二、停用词过滤

def filter(stopWords: Array[String]): StopRecognition = {
    // add stop words 
    val filter = new StopRecognition
    filter.insertStopNatures("w") // filter punctuation
    filter.insertStopNatures("m") // filter m pattern
    filter.insertStopNatures("null") // filter null
    filter.insertStopNatures("
") // filter
filter.insertStopRegexes("^[a-zA-Z]{1,}") //filter English alphabet filter.insertStopRegexes("^[0-9]+") //filter number filter.insertStopRegexes("[^a-zA-Z0-9\\u4e00-\\u9fa5]+") filter.insertStopRegexes("\t") for (x <- stopWords) { filter.insertStopWords(x) } filter }

三、分词

def getWords(text: String, filter: StopRecognition): ArrayBuffer[String] = {
    val words = new mutable.ArrayBuffer[String]()
    val terms: java.util.List[Term] =  ToAnalysis.parse(text).recognition(filter).getTerms
    for (i <- 0 until terms.size()) {
        val word = terms.get(i).getName
        if (word.length >= MIN_WORD_LENGTH) {
            words += word
        }
    }
    words
}

标题名称:Spark中文分词
文章路径:http://kswjz.com/article/ihgedo.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流