从火花中的字符串中删除停用词

Removing Stopwords from a string in spark

您好,我想从 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
}

试试这个:

def processLine(s: String, stopWords: Set[String]): Seq[String] = {

    s.replaceAll("[^a-zA-Z ]", " ")
      .toLowerCase()
      .split("\s+")
      .filter(!stopWords.contains(_)).toSeq
}

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