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("<br />") // filter <br />
    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中文分词
标题链接:https://www.cdcxhl.com/article10/ihgedo.html

成都网站建设公司_创新互联,为您提供关键词优化用户体验网站维护网站建设搜索引擎优化企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设