Skip to content

Commit

Permalink
Replace cudf.logical_not with ~ (#4669)
Browse files Browse the repository at this point in the history
Replace `cudf.logical_not` with `~`.

Authors:
  - Andy Adinets (https://github.com/canonizer)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #4669
  • Loading branch information
canonizer authored Mar 31, 2022
1 parent f6dbf32 commit bfe034a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
22 changes: 8 additions & 14 deletions python/cuml/preprocessing/text/stem/porter_stemmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def _step1a(self, word_str_ser, can_replace_mask=None):
)

# update can replace mask
can_replace_mask = can_replace_mask & cudf.logical_not(
condition_mask
)
can_replace_mask &= ~condition_mask

return apply_rule_list(
word_str_ser,
Expand Down Expand Up @@ -241,18 +239,14 @@ def _step1b(self, word_str_ser, can_replace_mask=None):
)

# update can replace mask
can_replace_mask = can_replace_mask & cudf.logical_not(
condition_mask
)
can_replace_mask &= ~condition_mask

condition_mask = suffix_mask
valid_mask = can_replace_mask & condition_mask
word_str_ser = replace_suffix(word_str_ser, "ied", "i", valid_mask)

# update can replace mask
can_replace_mask = can_replace_mask & cudf.logical_not(
condition_mask
)
can_replace_mask &= ~condition_mask

# (m>0) EED -> EE
# if suffix ==eed we stop processing
Expand All @@ -269,7 +263,7 @@ def _step1b(self, word_str_ser, can_replace_mask=None):

# to be consistent with nltk we dont replace
# if word.endswith('eed') we stop proceesing
can_replace_mask = can_replace_mask & cudf.logical_not(suffix_mask)
can_replace_mask &= ~suffix_mask

# rule 2
# (*v*) ED -> plastered -> plaster
Expand Down Expand Up @@ -652,7 +646,7 @@ def _step5a(self, word_str_ser, can_replace_mask=None):

# if measure==1 and not self._ends_cvc(stem):
measure_eq_1_flag = measure_eq_n(stem, 1)
does_not_ends_with_cvc_flag = cudf.logical_not(ends_cvc(stem))
does_not_ends_with_cvc_flag = ~ends_cvc(stem)
rule_2_flag = measure_eq_1_flag & does_not_ends_with_cvc_flag

overall_rule_flag = (
Expand Down Expand Up @@ -718,7 +712,7 @@ def map_irregular_forms(word_str_ser, can_replace_mask):
)

word_str_ser = stem_ser.str.cat(replacement_ser)
can_replace_mask = can_replace_mask & cudf.logical_not(equal_flag)
can_replace_mask &= ~equal_flag

return word_str_ser, can_replace_mask

Expand Down Expand Up @@ -761,7 +755,7 @@ def apply_rule(word_str_ser, rule, w_in_c_flag):
word_str_ser = replace_suffix(
word_str_ser, suffix, replacement, valid_mask
)
w_in_c_flag = w_in_c_flag & cudf.logical_not(double_consonant_mask)
w_in_c_flag &= ~double_consonant_mask

else:

Expand All @@ -778,7 +772,7 @@ def apply_rule(word_str_ser, rule, w_in_c_flag):
)

# we wont apply further rules if it has a matching suffix
w_in_c_flag = w_in_c_flag & cudf.logical_not(suffix_mask)
w_in_c_flag &= ~suffix_mask

return word_str_ser, w_in_c_flag

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,7 +100,7 @@ def ends_cvc(string_ser, mode="NLTK_EXTENSIONS"):
# and not self._is_consonant(word, 0)
# and self._is_consonant(word, 1)
len_flag = len_eq_n(string_ser, 2)
first_char = cudf.logical_not(is_consonant(string_ser, 0))
first_char = ~is_consonant(string_ser, 0)
second_char = is_consonant(string_ser, 1)
rule_2 = len_flag & first_char & second_char

Expand Down

0 comments on commit bfe034a

Please sign in to comment.