├── MANIFEST.in ├── setup.py ├── helasentilex └── __init__.py ├── .github └── workflows │ └── python-publish.yml ├── LICENSE └── README.md /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include helasentilex/lexicon.csv -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="helasentilex", 8 | version="0.1.1", 9 | author="Binod Karunanayake", 10 | author_email="binod.16@cse.mrt.ac.lk", 11 | description="Python API for Sinhala Sentiment Lexicon", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/binodmx/helasentilex", 15 | packages=setuptools.find_packages(), 16 | include_package_data=True, 17 | classifiers=[ 18 | "Programming Language :: Python :: 3", 19 | "License :: OSI Approved :: MIT License", 20 | "Operating System :: OS Independent", 21 | ], 22 | python_requires='>=3.6', 23 | ) 24 | -------------------------------------------------------------------------------- /helasentilex/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | file_name = os.path.dirname(os.path.abspath(__file__)) + '/lexicon.csv' 4 | fo = open(file_name, 'r', encoding='utf-8') 5 | lines = fo.readlines() 6 | fo.close() 7 | 8 | sentiment_dict = {} 9 | for line in lines: 10 | senti_word, senti_score = line.strip().split(',') 11 | sentiment_dict[senti_word] = senti_score 12 | 13 | 14 | def sentiment(word): 15 | try: 16 | if word in sentiment_dict.keys(): 17 | score = int(sentiment_dict[word]) 18 | return score 19 | else: 20 | return None 21 | except: 22 | return None 23 | 24 | 25 | def sentiments(sentence): 26 | try: 27 | scores = {} 28 | for word in sentence.strip().split(): 29 | scores[word] = sentiment(word) 30 | return scores 31 | except: 32 | return {} 33 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflows will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | name: Upload Python Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | deploy: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up Python 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: '3.6' 21 | - name: Install dependencies 22 | run: | 23 | python -m pip install --upgrade pip 24 | pip install setuptools wheel twine 25 | - name: Build and publish 26 | env: 27 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 28 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 29 | run: | 30 | python setup.py sdist bdist_wheel 31 | twine upload dist/* 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Binod Karunanayake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HelaSentiLex (Hela Sentiment Lexicon) 2 | Python API for Sinhala Sentiment Lexicon with 14000+ sentiment tagged Sinhala words 3 | 4 | ![PyPI - Downloads](https://img.shields.io/pypi/dm/helasentilex) 5 | 6 | ### Setup environment 7 | 1. Make sure you have Python >= 3.6 by `python --version` 8 | 2. Additionally, you’ll need to make sure you have pip available by running `pip --version` 9 | 3. To install pip see [installing pip](https://pip.pypa.io/en/stable/installing/) 10 | 4. Install helasentilex package using the command `pip install helasentilex` 11 | 12 | ### Getting started 13 | Let's begin with showing how easy it is to find sentiments of Sinhala words using helasentilex 14 | ``` 15 | >>> import helasentilex 16 | >>> helasentilex.sentiment('යහපත්') 17 | 1 18 | >>> helasentilex.sentiment('අමිහිරි') 19 | -1 20 | >>> helasentilex.sentiment('පුටුව') 21 | 0 22 | ``` 23 | 24 | If the input word does not exist in our sentiment lexicon or the input is invalid then it will return `None` 25 | ``` 26 | >>> helasentilex.sentiment(23) 27 | None 28 | ``` 29 | 30 | You can enter a sentence as a string and get sentiment scores for available words in the sentiment lexicon 31 | ``` 32 | >>> helasentilex.sentiments('ඔබේ සැප දුක කෙසේද') 33 | {'ඔබේ': 0, 'සැප': 1, 'දුක': -1, 'කෙසේද': None} 34 | ``` 35 | 36 | If the input is invalid then it will return an empty dictionary 37 | ``` 38 | >>> helasentilex.sentiments(23) 39 | {} 40 | ``` 41 | 42 | ### Defining labels 43 | ``` 44 | 1: POSITIVE (ධනාත්මක) 45 | -1: NEGATIVE (ඍණාත්මක) 46 | 0: OBJECTIVE (මධ්‍යස්ථ හෝ උදාසීන) 47 | ``` 48 | 49 | 50 | ### Contributing 51 | Want to report a bug, contribute some code, or improve documentation? Excellent! fork our repository and start 52 | contributing. 53 | 54 | #### Adding new words to the sentiment lexicon 55 | To add new words along with their sentiment scores 56 | 57 | 1. Open `helasentilex/lexicon.csv` file 58 | 2. Append `new_word,sentiment_score` 59 | 3. Sort words in ascending order 60 | 4. Save changes to your forked repo and make a pull request 61 | 62 | _Love helasentilex? Give our repo a **[star](https://github.com/binodmx/helasentilex)**!_ 63 | --------------------------------------------------------------------------------