{ "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 }, "orig_nbformat": 4, "coopTranslator": { "original_hash": "27de2abc0235ebd22080fc8f1107454d", "translation_date": "2025-08-29T19:47:25+00:00", "source_file": "6-NLP/3-Translation-Sentiment/solution/notebook.ipynb", "language_code": "pa" } }, "nbformat": 4, "nbformat_minor": 2, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from textblob import TextBlob\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# You should download the book text, clean it, and import it here\n", "with open(\"pride.txt\", encoding=\"utf8\") as f:\n", " file_contents = f.read()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "book_pride = TextBlob(file_contents)\n", "positive_sentiment_sentences = []\n", "negative_sentiment_sentences = []" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for sentence in book_pride.sentences:\n", " if sentence.sentiment.polarity == 1:\n", " positive_sentiment_sentences.append(sentence)\n", " if sentence.sentiment.polarity == -1:\n", " negative_sentiment_sentences.append(sentence)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"The \" + str(len(positive_sentiment_sentences)) + \" most positive sentences:\")\n", "for sentence in positive_sentiment_sentences:\n", " print(\"+ \" + str(sentence.replace(\"\\n\", \"\").replace(\" \", \" \")))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"The \" + str(len(negative_sentiment_sentences)) + \" most negative sentences:\")\n", "for sentence in negative_sentiment_sentences:\n", " print(\"- \" + str(sentence.replace(\"\\n\", \"\").replace(\" \", \" \")))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n---\n\n**ਅਸਵੀਕਤੀ**: \nਇਹ ਦਸਤਾਵੇਜ਼ AI ਅਨੁਵਾਦ ਸੇਵਾ [Co-op Translator](https://github.com/Azure/co-op-translator) ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਅਨੁਵਾਦ ਕੀਤਾ ਗਿਆ ਹੈ। ਜਦੋਂ ਕਿ ਅਸੀਂ ਸਹੀਤਾ ਲਈ ਯਤਨਸ਼ੀਲ ਹਾਂ, ਕਿਰਪਾ ਕਰਕੇ ਧਿਆਨ ਦਿਓ ਕਿ ਸਵੈਚਾਲਿਤ ਅਨੁਵਾਦਾਂ ਵਿੱਚ ਗਲਤੀਆਂ ਜਾਂ ਅਸੁਚਨਾਵਾਂ ਹੋ ਸਕਦੀਆਂ ਹਨ। ਮੂਲ ਦਸਤਾਵੇਜ਼ ਨੂੰ ਇਸਦੀ ਮੂਲ ਭਾਸ਼ਾ ਵਿੱਚ ਅਧਿਕਾਰਤ ਸਰੋਤ ਮੰਨਿਆ ਜਾਣਾ ਚਾਹੀਦਾ ਹੈ। ਮਹੱਤਵਪੂਰਨ ਜਾਣਕਾਰੀ ਲਈ, ਪੇਸ਼ੇਵਰ ਮਨੁੱਖੀ ਅਨੁਵਾਦ ਦੀ ਸਿਫਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ। ਇਸ ਅਨੁਵਾਦ ਦੀ ਵਰਤੋਂ ਤੋਂ ਪੈਦਾ ਹੋਣ ਵਾਲੇ ਕਿਸੇ ਵੀ ਗਲਤਫਹਿਮੀ ਜਾਂ ਗਲਤ ਵਿਆਖਿਆ ਲਈ ਅਸੀਂ ਜ਼ਿੰਮੇਵਾਰ ਨਹੀਂ ਹਾਂ।\n" ] } ] }