Class StopWordsRemover

Object
org.apache.spark.ml.PipelineStage
org.apache.spark.ml.Transformer
org.apache.spark.ml.feature.StopWordsRemover
All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, Params, HasInputCol, HasInputCols, HasOutputCol, HasOutputCols, DefaultParamsWritable, Identifiable, MLWritable, scala.Serializable

public class StopWordsRemover extends Transformer implements HasInputCol, HasOutputCol, HasInputCols, HasOutputCols, DefaultParamsWritable
A feature transformer that filters out stop words from input.

Since 3.0.0, StopWordsRemover can filter out multiple columns at once by setting the inputCols parameter. Note that when both the inputCol and inputCols parameters are set, an Exception will be thrown.

See Also:
Note:
null values from input array are preserved unless adding null to stopWords explicitly.

  • Constructor Details

    • StopWordsRemover

      public StopWordsRemover(String uid)
    • StopWordsRemover

      public StopWordsRemover()
  • Method Details

    • load

      public static StopWordsRemover load(String path)
    • loadDefaultStopWords

      public static String[] loadDefaultStopWords(String language)
      Loads the default stop words for the given language. Supported languages: danish, dutch, english, finnish, french, german, hungarian, italian, norwegian, portuguese, russian, spanish, swedish, turkish
      Parameters:
      language - (undocumented)
      Returns:
      (undocumented)
      See Also:
    • read

      public static MLReader<T> read()
    • outputCols

      public final StringArrayParam outputCols()
      Description copied from interface: HasOutputCols
      Param for output column names.
      Specified by:
      outputCols in interface HasOutputCols
      Returns:
      (undocumented)
    • inputCols

      public final StringArrayParam inputCols()
      Description copied from interface: HasInputCols
      Param for input column names.
      Specified by:
      inputCols in interface HasInputCols
      Returns:
      (undocumented)
    • outputCol

      public final Param<String> outputCol()
      Description copied from interface: HasOutputCol
      Param for output column name.
      Specified by:
      outputCol in interface HasOutputCol
      Returns:
      (undocumented)
    • inputCol

      public final Param<String> inputCol()
      Description copied from interface: HasInputCol
      Param for input column name.
      Specified by:
      inputCol in interface HasInputCol
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • setInputCol

      public StopWordsRemover setInputCol(String value)
    • setOutputCol

      public StopWordsRemover setOutputCol(String value)
    • setInputCols

      public StopWordsRemover setInputCols(String[] value)
    • setOutputCols

      public StopWordsRemover setOutputCols(String[] value)
    • stopWords

      public StringArrayParam stopWords()
      The words to be filtered out. Default: English stop words
      Returns:
      (undocumented)
      See Also:
      • StopWordsRemover.loadDefaultStopWords()
    • setStopWords

      public StopWordsRemover setStopWords(String[] value)
    • getStopWords

      public String[] getStopWords()
    • caseSensitive

      public BooleanParam caseSensitive()
      Whether to do a case sensitive comparison over the stop words. Default: false
      Returns:
      (undocumented)
    • setCaseSensitive

      public StopWordsRemover setCaseSensitive(boolean value)
    • getCaseSensitive

      public boolean getCaseSensitive()
    • locale

      public Param<String> locale()
      Locale of the input for case insensitive matching. Ignored when caseSensitive() is true. Default: the string of default locale (Locale.getDefault), or Locale.US if default locale is not in available locales in JVM.
      Returns:
      (undocumented)
    • setLocale

      public StopWordsRemover setLocale(String value)
    • getLocale

      public String getLocale()
    • transform

      public Dataset<Row> transform(Dataset<?> dataset)
      Description copied from class: Transformer
      Transforms the input dataset.
      Specified by:
      transform in class Transformer
      Parameters:
      dataset - (undocumented)
      Returns:
      (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Specified by:
      transformSchema in class PipelineStage
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • copy

      public StopWordsRemover copy(ParamMap extra)
      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Transformer
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      Overrides:
      toString in class Object