PERSPECTIVEANALYZER, is a python wrapper for the [Google Perspective API] (https://www.perspectiveapi.com/). PyPI: https://pypi.org/project/perspectiveAnalyzer/1.0.2/ Github: https://github.com/dassaswat/perspectiveAnalyzer
# You can install released versions of perspectiveAnalyzer from the Python Package Index with pip or a similar tool:
# Stable Release: `pip install perspectiveAnalyzer`<br>
# Working Version: `pip install git+https://github.com/dassaswat/perspectiveAnalyzer.git`
# Intialize the class with your API_KEY, required languages and required attributes with their respective thresholds in \*\*kwargs
# You can also setup the Developer Name.
# Accepted attributes
# attributes = ["TOXICITY", "SEVERE_TOXICITY", "IDENTITY_ATTACK", "INSULT",
# "PROFANITY", "THREAT", "SEXUALLY_EXPLICIT", "FLIRTATION", "SPAM",
# "ATTACK_ON_AUTHOR", "ATTACK_ON_COMMENTER", "INCOHERENT",
# "INFLAMMATORY", "OBSCENE", "SPAM", "UNSUBSTANTIAL"]
# Accepted Languages
# lang = ["en", "fr", "es", "de", "it", "pt", "ru"]
# For more details on the API refer to the Perspective API Documentation
# https://developers.perspectiveapi.com/s/about-the-api-attributes-and-languages
analyzeText("Some Text") # Method returns an object containing attributes that are booleans (either True or False) .If the returned summary score falls beyond the threshold specified it return True else False.
getTextReport("Some Text") # Method returns an object containing probability scores for all the attributes that was passed during the initialization.
# install the python Module
pip3 install perspectiveAnalyzer
# import the module
from perspectiveAnalyzer import Perspective
# initiate the object
api_key = "Your API Key"
textAnalyzer = Perspective(api_key, "sassy", lang=["en","es"], INSULT = 0.75, TOXICITY = 0.75,SPAM= 0.75,)
"""
Here we pass in the api_key, developerName ( ** Not Mandatory ** ), lang which is a list( defaults to just "en"
** Not Mandatory as well ** ) and finally we pass in the attributes with their threshold values.
"""
res = textAnalyzer.analyzeText("Some text") # Return a boolean object for the provided attribute
res = textAnalyzer.getTextReport("Some text") # Returns an object containing the probability scores for the provided attributes
# From analyzeText
{'TOXICITY': True, 'INSULT': True}
# From getTextReport
{
"attributeScores": {
"TOXICITY": {
"spanScores": [
{
"begin": 0,
"end": 11,
"score": {
"value": 0.04457423,
"type": "PROBABILITY"
}
}
],
"summaryScore": {
"value": 0.04457423,
"type": "PROBABILITY"
}
},
"INSULT": {
"spanScores": [
{
"begin": 0,
"end": 11,
"score": {
"value": 0.01924272,
"type": "PROBABILITY"
}
}
],
"summaryScore": {
"value": 0.01924272,
"type": "PROBABILITY"
}
}
},
"languages": [
"en"
],
"detectedLanguages": [
"en",
"fil"
]
}
- Register API key - Click Here
- Documentation/Endpoints - Click Here