perspective.py v0.2.0
This is one of biggest updates so far, which includes lots of new features and some bug fixes. I've also added some examples to the examples folder. All changes are listed below:
New features
- Added
format_response
,get_highest
,get_lowest
,show_graph
andsave_graph
functions toperspective/utils.py
.format_response
formats the dictionary that theanalyze
function returns to make the response easier to read by a human.get_highest
returns the attribute with the highest score value from the dictionary that theanalyze
function returns.get_lowest
returns the attribute with the lowest score value.show_graph
uses matplotlib library to create a bar chart, descending according to the score values and shows the graph by popping up an interactive window.save_graph
does the sameshow_graph
does but saves the graph as an image instead of showing it by popping up a window.
- Added
perspective.Attributes.All
,perspective.Attributes.Production
,perspective.Attributes.Experimental
andperspective.Attributes.NewYorkTimes
which include their related attributes (such as TOXICITY goes to Production and ATTACK_ON_AUTHOR goes to NewYorkTimes). Information about which attribute belongs to which category can be found in this article. Those can be used onattributes
argument ofanalyze
function. - Added
skip_on_lang
andskip_on_unknown
arguments toanalyze
function.skip_on_lang
tells the function to skip an attribute if the language of the text is not supported by that attribute. The function checks whether the attribute supports that language or not by making a request to the API instead of checking locally, so it may exceed the ratelimit for the API if there are lots of attributes which are expected to not support the language of the text.skip_on_unknown
tells the function to skip an attribute if that attribute is unknown. Unlikeskip_on_lang
, function checks whether the attribute is known or not locally so usage of this wouldn't exceed the ratelimit in case there are lots of unknown attributes requested.
Changes
- Renamed
requestedAttributes
argument toattributes
. - Made
attributes
argument non-required, and it now defaults to all production-ready attributes (perspective.Attributes.Production
).
Bug fixes
- Fixed
UnknownAttributeError
exception whenperspective.Attributes.IDENTITY_ATTACK
and/orperspective.Attributes.THREAT
is used inattributes
argument ofanalyze
function (there were minor spelling mistakes in those attributes' names).
Code changes
- Moved attribute classes from
main.py
to a new file namedattributes.py
. This didn't affect the functionality of the classes.