Sentiment Analysis:


This is a v1 general model for text based sentiment analysis.

  more information on this can be found at Product: Sentiment Analysis

Initialize and Get model:
from cognious import CogniousApp

# Use <client_id> and <client_secret> of your application
# Refer to Step 2 of https://cognious.com/documentation/quickstart
app = CogniousApp('DKP3ADiCHVWO0NvuDg9XIpYgZAgKIXc73ZiPfBe2', 'i55x7kQWGc83u2fpKgMmyGCXaWDHYlk7kS986a6e')

# Get the model you want to use
# models.get function returns an instance of the model
model = app.models.get('SentimentAnalysis')

Methods:


Method: analyze_text
Syntax: model.analyze_text(<string_or_list_of_strings>)
Input: <text> should be of type string or list of string
Constraints: If list is passed, list should not contain more than 20 elements

String:
# model.analyze_text(<text>)
# Text source: wikipedia (https://simple.wikipedia.org/wiki/Pollution)
model.analyze_text('Pollution is when something is added to the environment that is harmful or poisonous to all living things. Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in. Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses. People living next to a building site where there is too much noise can become sick as they cannot sleep.')

# model.response contains the response
print(model.response)

Sample response object (prettified)
{
  'success': True,
  'result': {
    'polarity': -0.3428571428571428,
    'subjectivity': 0.5447619047619047,
    'sentences': [
      {'polarity': 0.0, 'subjectivity': 0.0, 'sentence': 'Pollution is when something is added to the environment that is harmful or poisonous to all living things.'},
      {'polarity': -0.6999999999999998, 'subjectivity': 0.6666666666666666, 'sentence': 'Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in.'},
      {'polarity': -0.5, 'subjectivity': 1.0, 'sentence': 'Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses.'},
      {'polarity': -0.1714285714285714, 'subjectivity': 0.3523809523809524, 'sentence': 'People living next to a building site where there is too much noise can become sick as they cannot sleep.'}
    ]
  }
}

List:
# model.analyze_text(<text>)
# Text source: wikipedia (https://simple.wikipedia.org/wiki/Pollution)
model.analyze_text(['Pollution is when something is added to the environment that is harmful or poisonous to all living things.', 'Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in.', 'Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses.', 'People living next to a building site where there is too much noise can become sick as they cannot sleep.'])

# model.response contains the response
print(model.response)

Sample response object (prettified)
{
  'success': True,
  'result': {
    'sentences': [
      {'polarity': 0.0, 'subjectivity': 0.0, 'sentence': 'Pollution is when something is added to the environment that is harmful or poisonous to all living things.'},
      {'polarity': -0.6999999999999998, 'subjectivity': 0.6666666666666666, 'sentence': 'Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in.'},
      {'polarity': -0.5, 'subjectivity': 1.0, 'sentence': 'Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses.'},
      {'polarity': -0.1714285714285714, 'subjectivity': 0.3523809523809524, 'sentence': 'People living next to a building site where there is too much noise can become sick as they cannot sleep.'}
    ]
  }
}

Full example code:
from cognious import CogniousApp

# Use <client_id> and <client_secret> of your application
# Refer to Step 2 of https://cognious.com/documentation/quickstart
app = CogniousApp('D
KP3ADiCHVWO0NvuDg9XIpYgZAgKIXc73ZiPfBe2', 'i55x7kQWGc83u2fpKgMmyGCXaWDHYlk7kS986a6e')

# Get the model you want to use
# models.get function returns an instance of the model
model = app.models.get('SentimentAnalysis')

# model.analyze_text(<text>)
# Text source: wikipedia (https://simple.wikipedia.org/wiki/Pollution)
model.analyze_text('Pollution is when something is added to the environment that is harmful or poisonous to all living things. Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in. Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses. People living next to a building site where there is too much noise can become sick as they cannot sleep.')

# model.response contains the response
print(model.response)
# {
#   'success': True,
#   'result': {
#     'polarity': -0.3428571428571428,
#     'subjectivity': 0.5447619047619047,
#     'sentences': [
#       {
#         'polarity': 0.0,
#         'subjectivity': 0.0,
#         'sentence': 'Pollution is when something is added to the environment that is harmful or poisonous to all living things.'
#       },
#       {
#         'polarity': -0.6999999999999998,
#         'subjectivity': 0.6666666666666666,
#         'sentence': 'Smoke or dust in the air is a type of pollution as it is bad for the lungs when we breath in.'
#       },
#       {
#         'polarity': -0.5,
#         'subjectivity': 1.0,
#         'sentence': 'Sewage in drinking water is another type of pollution, as it can make people ill because it contains germs and viruses.'
#       },
#       {
#         'polarity': -0.1714285714285714,
#         'subjectivity': 0.3523809523809524,
#         'sentence': 'People living next to a building site where there is too much noise can become sick as they cannot sleep.'
#       }
#     ]
#   }
# }