Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/11871#discussion_r58302144
--- 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 --
OK, if we don't treat that as an error, then null can be filtered when the
stopwords set is created. In fact it can be lowercased at that time too.
---
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]