Github user burakkose commented on a diff in the pull request:
https://github.com/apache/spark/pull/11871#discussion_r58301673
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/feature/StopWordsRemover.scala ---
@@ -123,21 +71,26 @@ class StopWordsRemover(override val uid: String)
/** @group getParam */
def getCaseSensitive: Boolean = $(caseSensitive)
- setDefault(stopWords -> StopWords.English, caseSensitive -> false)
+ setDefault(stopWords -> Array.empty[String], caseSensitive -> false)
override def transform(dataset: DataFrame): DataFrame = {
+ val stopWordsSet = if ($(stopWords).isEmpty) {
+ StopWordsRemover.loadStopWords("english").toSet
+ } else {
+ $(stopWords).toSet
+ }
+
val outputSchema = transformSchema(dataset.schema)
val t = if ($(caseSensitive)) {
- val stopWordsSet = $(stopWords).toSet
- udf { terms: Seq[String] =>
- terms.filter(s => !stopWordsSet.contains(s))
- }
- } else {
- val toLower = (s: String) => if (s != null) s.toLowerCase else s
- val lowerStopWords = $(stopWords).map(toLower(_)).toSet
- udf { terms: Seq[String] =>
- terms.filter(s => !lowerStopWords.contains(toLower(s)))
- }
+ udf { terms: Seq[String] =>
+ terms.filter(s => !stopWordsSet.contains(s))
+ }
+ } else {
+ val toLower = (s: String) => if (s != null) s.toLowerCase else s
+ val lowerStopWords = stopWordsSet.map(toLower(_)).toSet
--- End diff --
Before my editing, they wrote that condition. I thought as you said.
However, user may do that.
```
//Other operations to assign to the word. Just an example
val word: String = null
val stopwords = Array(word)
val remover = new StopWordsRemover()
.setInputCol("raw")
.setOutputCol("filtered")
.setStopWords(stopWords)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]