Releases: Yilmaz4/perspective.py
perspective.py v0.3.4
Here is a release which includes yet some other ideas I've added and some bugs that I've noticed while implementing my ideas and I've fixed. You can see my ideas below.
New features
- Added yet another example code, but this time it introduces an easy-to-use GUI (Graphical User Interface) written with tkinter library. However, understanding the code requires some object-oriented programming knowledge and experience. Despite the source code is available in the repository, I actually designed the GUI for end-users therefore it's more like a demo for the API.
- Added
sort_response
function to theperspective.utils
class which can be used to sort the keys of the dictionary that theanalyze
function returned according to their values or in alphabetical in both ascending and descending order. - Added
UnknownSorting
exception type to theperspective.errors
class, however, unlike its name suggests, this exception exists frankly to raise when an unknown string is provided toorder
orsort_by
arguments ofsort_response
function. - Added
export_json
function to theperspective.utils
class which can be used to export the dictionary that theanalyze
function returned to a file in JSON format as the name of the function suggests. The file name can be anything.
Bug fixes
- Fixed
EmptyResponse
exception when none of the requested attributes supported the language of the text provided and when theskip_on_lang
keyword argument ofanalyze
function was set to True therefore the response was (supposed to be) an empty dictionary. The exception was caused by the logging line of the function.
perspective.py v0.3.3
Whilst trying to create a GUI (Graphical User Interface) for the API, I noticed that passing None
to the logging_level
argument while creating the Client object raises an exception. In this release, I only fixed that issue.
Bug fixes
- Fixed an exception when
None
was passed to thelogging_level
argument ofperspective.Client.__init__
function.
perspective.py v0.3.2
A random idea came to my mind whilst I was in school and I decided to add it to the library. While I was adding the feature, I noticed some bugs and fixed them too at the mean time. You can see what the idea was and the bugs that I've fixed below. Other than that, I literally have no idea to add to the library so I would appreciate if you give me some ideas in the Issues tab of the repository.
New features
- Added
save_data
function which can be used to save the response that theanalyze
function returned to a SQLite3 database file. I know it's already pretty easy to do this by yourself but here is an easier way. - Added
EmptyResponse
exception type toperspective.errors
class which gets raised when there is no attribute in the dictionary that was passed to theresponse
argument in any of the functions ofperspective.utils
class. - Added
EmptyFileName
exception type toperspective.errors
class which gets raised when an empty string was provided as thefilename
argument ofsave_graph
and/orsave_data
functions ofperspective.utils
class.
Changes
- Changed the way the
analyze
function ofperspective.Client
object and all other functions inperspective.utils
class (only if raw response was provided) fetch score values of attributes from the raw response that was directly returned from the API. They now get the score values fromsummaryScore
nested-dictionary which contains the average score value instead ofspanScores
which shall contain score values of each sentence of the text requested to the API in the future.
Bug fixes
- Fixed
TypeError
exception when attempting to useformat_response
orsave_data
inperspective.utils
class by providing raw response to theresponse
argument and settingsort_by
argument to something other thanNone
. - Fixed TOXICITY attribute appearing as
toxicity
instead ofToxicity
(first letter is not capital) whenTrue
is passed to thealign_right
argument offormat_response
function inperspective.utils
class. - Fixed
ModuleNotFoundError
exception when importing the package (perspective.py) on a machine with nomatplotlib
library installed, as the library was missing ininstall_requires
list ofsetup.py
file.
Code changes
- Fixed some typos in function comments.
- Added function annotations to every single function in the library.
perspective.py v0.3.1
I just noticed that the logging_level
property of perpective.Client
object was not working properly so I checked the code out and realized my mistake, thereupon I released a quick fix to it. Now you can change the logging level anytime you want by setting a new value to logging_level
property of your perspective.Client
instance. Literally the exact same thing I said above is available below.
Bug fixes
- Fixed
logging_level
property not working properly (setting a value to it didn't change anything).
perspective.py v0.3.0
Although this release does not include as much interesting new features as previous release does, it still can be considered as a big release. I spent my whole weekend looking for ways to improve ease of usage and find bugs, and here is the result. All changes are available below:
New features
- Support for
logging
module is here! Now you can set the logging level inlogging_level
argument of__init__
function of Client object; in other words, when creating the Client object, you can pass the logging level limitation you want to thelogging_level
argument. Information logs such as completion of the request to the API will be logged as INFO and other logs such as skipping attributes which does not support the language of the text will be logged as DEBUG. - Added
change_token
function to Client object which can be used to change the token without recreating the Client object. - Added
sort_by
argument toperspective.utils.format_response
which takes whetherascending
ordescending
as value (literal value), which can be used to sort the attributes according to their score values ascending or descending. - Added
return_raw
argument toanalyze
function of Client object which can be used to make the function return the raw response instead of a simplified response. - Added support for processing raw responses in
response
argument of every single function inperspective.utils
class. - Added new exception types for specification of errors that occur whilst making a request to the API or whilst checking validity of arguments locally.
Changes
- Exceptions no more include the parent exception with a message "During handling of the above exception, another exception occurred:".
- Removed "Error" suffix from all exception names, for example,
UnknownAttributeError
is nowUnknownAttribute
. - Made
filename
attribute ofsave_graph
function inperspective.utils
class non-required and default to "chart.png".
Bug fixes
- Fixed
UnknownAttribute
error when multiple attribute groups (such asperspective.Attributes.All
and/orperspective.Attributes.Production
) used inattributes
argument ofanalyze
function in Client object. - Fixed
show_graph
andsave_graph
functions drawing grid lines onto the bar chart no matter what valuegrid_lines
argument gets unlessFalse
is given togrid_lines
argument of those functions.
Code changes
- Moved all exception classes from
main.py
to a new file namederror.py
. - Fixed spelling, grammar and argument name mistakes in function comments.
- Included license information in every single *.py file except
__init__.py
and updated the copyright year in license text. - Moved variables which hold lists of all attributes and/or all attribute groups to
attributes.py
as a global variable outside the Attributes class, for simplification of main code.
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.
perspective.py v0.1.1
I forgot the fact that in Python, dots are used for importing packages from child directories hence package names cannot include dots. Therefore I've updated the code to make the package name perspective
yet keep the PyPI name as perspective.py
.
Now you can import perspective.py as follows:
from perspective import Client, Attributes
Furthermore, you can still install the package by the following command:
python -m pip install --upgrade perspective.py
perspective.py v0.1.0
This is the initial release of perspective.py library. The code is pretty simple thereby I don't think there are lots of bugs; but if you find any or if you have any suggestions, feel free to create an issue in Issues tab or make a pull request. Current features in this version follow as:
- Making an analysis request to the Perspective API with requested attributes and specified language.
- Being able to correct spelling mistakes in attribute names and languages in
analyze
command arguments.
I will upload the library to PyPI soon.