Skip to main content

Sentic Package for NLP

Project description

# Sentic

Python Interface for Semantic and Sentiment Analysis using Senticnet4 (http://sentic.net/).


## Install

Using pip:

```
pipinstallsenticUsingtherepositorycode: python setup.py install
```

## How to use

```python
from sentic import SenticPhrase
text = "Shirley is such a cute girl."
sp = SenticPhrase(text)
sp.info(text)
>>> {'sentics': {'aptitude': 0.062, 'attention': 0.3695, 'pleasantness': 0.47050000000000003, 'sensitivity': 0.0115}, 'semantics': {'furry', 'labor', 'nocturnal', 'career', 'animal_furry', 'hairy', 'police_work', 'task', 'domestic_pet', 'employment'}, 'moodtags': {'#joy': 2, '#interest': 1, '#admiration': 1}, 'sentiment': 'weak positive', 'polarity': 0.29700000000000004}

>>> sp.get_sentics()
{'aptitude': 0.062, 'attention': 0.3695, 'pleasantness': 0.47050000000000003, 'sensitivity': 0.0115}

>>> sp.get_moodtags()
{'#joy': 2, '#interest': 1, '#admiration': 1}

>>> sp.get_sentiment()
'weak positive'

>>> sp.get_polarity()
0.29700000000000004

>>> sp.get_semantics()
{'furry', 'labor', 'nocturnal', 'career', 'animal_furry', 'hairy', 'police_work', 'task', 'domestic_pet', 'employment'}
```

Additionally, if you want to, you can just use the same SenticPhrase class object to make method calls on other bodies of text. This manner of functionality was introduced because creating new objects for every different body of text could be cumbersome and memory-inefficient.

```python
# Word not in Sentic word set
>>> sp.info("asdkfjalsfknqsf")
{'polarity': 0, 'sentics': {}, 'semantics': set(), 'moodtags': {}, 'sentiment': 'neutral'}

>>> sp.info("Humans are such an interesting species.")
{'sentics': {'sensitivity': 0.0, 'aptitude': 0.2995, 'attention': -0.08550000000000002, 'pleasantness': 0.725}, 'sentiment': 'strong positive', 'semantics': set(), 'moodtags': {'#interest': 1, '#joy': 1, '#admiration': 1, '#surprise': 1}, 'polarity': 0.6165}

>>> sp.get_polarity("Use same object to get polarity on another text")
0.5683333333333334
```

Also, you can use other languages:

```python
from sentic import SenticPhrase
text = 'amour'
sp = SenticPhrase(text, "fr")
sp.get_semantics()
>>> ['beaucoup_de_fleurs', 'montrer_l’beaucoup_de_fleurs', 'rose', 'donner_des_fleurs']

sp.get_moodtags()
>>> ['#intérêt', '#admiration']

sp.get_sentics()
>>> {'aptitude': 0.071, 'sensitivity': 0.025, 'pleasantness': 0.027, 'attention': 0.093}

(Unfortunately, the French dataset and some others languages do not have positive/negative labels.)

sp.get_polarity()
>>> 0

sp.get_sentiment()
>>> neutral
```

You can find all supported languages here: http://sentic.net/api/

## About Senticnet

This framework was adapted from Yuri Malheiros (@yurimalheiros) https://github.com/yurimalheiros/senticnetapi.

SenticNet is an initiative conceived at the MIT Media Laboratory in 2010 within an industrial Cooperative Awards in Science and Engineering (CASE) research project, funded by the UK Engineering and Physical Sciences Research Council (EPSRC) and born from the collaboration between the University of Stirling, the Media Lab, and Sitekit Labs.

Currently, both the SenticNet knowledge base and the SenticNet framework are being maintained and further developed by the Sentic Team, a multidisciplinary research group based at the School of Computer Engineering of Nanyang Technological University in Singapore, but also by many other sentic enthusiasts around the world.

Please acknowledge the authors by citing SenticNet 4 in any research work or presentation containing results obtained in whole or in part through the use of the API:

*E. Cambria, S. Poria, R. Bajpai, and B. Schuller. SenticNet 4: A semantic resource for sentiment analysis based on conceptual primitives. In: COLING, pp. 2666-2677, Osaka (2016) http://sentic.net/senticnet-4.pdf*

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page