Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/11871#discussion_r58301366
--- 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))
--- End diff --
Can you save a reference to the active set of stopwords instead of making
the list into a set each time? might be more natural to have a defensive copy
anyway.
---
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]