从spark中删除字符串中的停用词

时间:2016-06-06 12:38:11

标签: regex scala stop-words

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

1 个答案:

答案 0 :(得分:0)

试试这个:

MetadataPropertyHandling

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