jiangxin369 commented on code in PR #183: URL: https://github.com/apache/flink-ml/pull/183#discussion_r1038916503
########## flink-ml-python/pyflink/ml/lib/feature/stopwordsremover.py: ########## @@ -0,0 +1,135 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +import typing +from typing import Tuple + +from pyflink.java_gateway import get_gateway +from pyflink.ml.core.param import Param, StringArrayParam, BooleanParam, StringParam +from pyflink.ml.core.wrapper import JavaWithParams +from pyflink.ml.lib.feature.common import JavaFeatureTransformer +from pyflink.ml.lib.param import HasInputCols, HasOutputCols + + +def _load_default_stop_words(language: str): + return get_gateway().jvm.org.apache.flink.ml.feature. \ + stopwordsremover.StopWordsRemover.loadDefaultStopWords(language) + + +def _get_default_or_us(): + return get_gateway().jvm.org.apache.flink.ml.feature. \ + stopwordsremover.StopWordsRemover.getDefaultOrUS() + + +class _StopWordsRemoverParams( + JavaWithParams, + HasInputCols, + HasOutputCols +): + """ + Params for :class:`StopWordsRemover`. + """ + + STOP_WORDS: Param[Tuple[str, ...]] = StringArrayParam( + "stop_words", + "The words to be filtered out.", + _load_default_stop_words('english')) + + CASE_SENSITIVE: Param[bool] = BooleanParam( + "case_sensitive", + "Whether to do a case-sensitive comparison over the stop words.", + False + ) + + LOCALE: Param[str] = StringParam( + "locale", + "Locale of the input for case insensitive matching. Ignored when caseSensitive is true.", + _get_default_or_us()) + + def __init__(self, java_params): + super(_StopWordsRemoverParams, self).__init__(java_params) + + def set_stop_words(self, value: Tuple[str, ...]): Review Comment: Let's replace the param with `*value: str` to set `StringArrayParam`. ########## flink-ml-lib/src/main/resources/org/apache/flink/ml/feature/stopwords/README: ########## @@ -0,0 +1,12 @@ +Stopwords Corpus Review Comment: Would it be better to write this file in markdown syntax like `## Stopwords Corpus` for better readability? ########## docs/content/docs/operators/feature/stopwordsremover.md: ########## @@ -0,0 +1,165 @@ +--- +title: "StopWordsRemover" +weight: 1 +type: docs +aliases: +- /operators/feature/stopwordsremover.html +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## StopWordsRemover + +A feature transformer that filters out stop words from input. + +Note: null values from input array are preserved unless adding null to stopWords +explicitly. + +See Also: <a href="http://en.wikipedia.org/wiki/Stop_words">Stop words +(Wikipedia)</a> + +### Input Columns + +| Param name | Type | Default | Description | +|:-----------|:---------|:--------|:---------------------------------------------------| +| inputCols | String[] | `null` | Arrays of strings containing stop words to remove. | + +### Output Columns + +| Param name | Type | Default | Description | +|:-----------|:---------|:--------|:-------------------------------------------| +| outputCols | String[] | `null` | Arrays of strings with stop words removed. | + +### Parameters + +| Key | Default | Type | Required | Description | +|---------------|----------------------------------------------------|----------|----------|----------------------------------------------------------------------------------------| +| inputCols | `null` | String[] | yes | Input column names. | +| outputCols | `null` | String[] | yes | Output column name. | +| stopWords | `StopWordsRemover.loadDefaultStopWords("english")` | String[] | no | The words to be filtered out. | +| caseSensitive | `false` | Boolean | no | Whether to do a case-sensitive comparison over the stop words. | +| locale | `StopWordsRemover.getDefaultOrUS().toString()` | String | no | Locale of the input for case insensitive matching. Ignored when caseSensitive is true. | Review Comment: How about adding a comment like "Available values are at java.util.Locale#getAvailableLocales" to make the description clearer? Otherwise, Python users may choose values in Python locale module. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org