【问题标题】:Removing Stopwords from a string in spark从火花中的字符串中删除停用词
【发布时间】:2016-10-06 01:51:48
【问题描述】:

您好,我想从 Spark 中的字符串中删除停用词。

假设我有输入字符串 "Hello-people",那么我希望输出为 (hello people) 但我得到的是 (hellopeople )

我的代码是:

def processLine(s: String, stopWords: Set[String]): Seq[String] = {   
  s.replaceAll("[^a-zA-Z ]", "").toLowerCase().split("\\s+")
  s.filter(!stopWords.contains(_))
  s.toSeq
}

【问题讨论】:

    标签: regex scala stop-words


    【解决方案1】:

    试试这个:

    def processLine(s: String, stopWords: Set[String]): Seq[String] = {
    
        s.replaceAll("[^a-zA-Z ]", " ")
          .toLowerCase()
          .split("\s+")
          .filter(!stopWords.contains(_)).toSeq
    }
    

    只有一个变化,在 replaceAll 中,“”而不是“”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-16
      • 2014-06-06
      • 2015-02-25
      • 2014-05-22
      • 1970-01-01
      • 2019-12-18
      • 2015-09-11
      相关资源
      最近更新 更多