Skip to content

tokenizer_words_and_emoticons joins emoticons to the final word #1206

Closed

Description

@Afloat16

Problem and proposed change

Emoticons are appended to normalized text without inserting a separator. When normalized text ends in a word, the first emoticon becomes part of that word. Insert a space before joining the extracted emoticons.

Reproduction

from mlxtend.text import tokenizer_words_and_emoticons
print(tokenizer_words_and_emoticons("Hi :) world"))
# Actual: ["hi", "world:)"]; expected: ["hi", "world", ":)"]

Validation

Source: mlxtend/text/tokenizer.py, Git blob 14d8fd77662dff4e1c8c1e90b3983e13995813a8; rechecked against current upstream. Focused before/after tests were rerun for this submission.

Complete standalone source module loaded with real dependencies; selected utility behaviors tested. Not the full project suite.

Before: 6 failed, 5 passed in 0.03s

After: 11 passed in 0.02s

Candidate patch

--- a/mlxtend/text/tokenizer.py
+++ b/mlxtend/text/tokenizer.py
@@ -23,7 +23,7 @@
     """
     text = re.sub(r"<[^>]*>", "", text)
     emoticons = re.findall(r"(?::|;|=)(?:-)?(?:\)|\(|D|P)", text)
-    text = re.sub(r"[\W]+", " ", text.lower()) + " ".join(emoticons)
+    text = re.sub(r"[\W]+", " ", text.lower()) + " " + " ".join(emoticons)
     return text.split()
 
 

Environment

Source module at the Git blob above, rather than an installed mlxtend distribution. Linux x86_64; Python 3.12.14; NumPy 2.3.5; SciPy 1.17.0; scikit-learn 1.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions