From 4d873cd9e879c2e2276a177312946f4616596137 Mon Sep 17 00:00:00 2001 From: Chang CL Date: Sun, 24 Aug 2025 13:55:44 +0800 Subject: [PATCH] remove negative words --- words_syllables.ipynb | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/words_syllables.ipynb b/words_syllables.ipynb index e7e7e14..778417a 100644 --- a/words_syllables.ipynb +++ b/words_syllables.ipynb @@ -238,6 +238,54 @@ " writer = csv.writer(csvfile)\n", " writer.writerows(single_syllable_nouns_cleaned)" ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "836b0473-2b4f-4c82-921e-1d6ed51c65f3", + "metadata": {}, + "outputs": [], + "source": [ + "from textblob import TextBlob\n", + "\n", + "# Alternative method using sentiment analysis (requires: pip install textblob)\n", + "def is_negative(word):\n", + " # Simple sentiment check - words with negative polarity\n", + " analysis = TextBlob(word)\n", + " return analysis.sentiment.polarity < -0.1" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "1c9517b7-a17a-4c94-9bd6-ca0da1cfd708", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cow\n", + "game\n", + "green\n" + ] + } + ], + "source": [ + "for word in single_syllable_nouns_cleaned:\n", + " if is_negative(word):\n", + " print(word)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "3a2e6440-842c-4a2f-be1e-49b4771c651b", + "metadata": {}, + "outputs": [], + "source": [ + "sentiment_filtered_nouns = [word for word in single_syllable_nouns_cleaned if not is_negative(word)]" + ] } ], "metadata": {