Base class to enable objects to be compared for similarity.
Project description
Comparable
Comparable is a library providing abstract base classes that enable subclasses to be compared for “equality” and “similarity” based on their attributes.
Getting Started
Requirements
Installation
Comparable can be installed with ‘pip’:
pip install Comparable
Or directly from the source code:
git clone https://github.com/jacebrowning/comparable.git cd comparable python setup.py install
Basic Usage
After installation, abstract base classes can be imported from the package:
python >>> import comparable comparable.__version__ >>> from comparable import SimpleComparable, CompoundComparable
Comparable classes use == as the operation for “equality” and % as the operation for “similarity”. They may also override a threshold attribute to set the “similarity” ratio.
Simple Comparables
Simple comparable types must override the equality and similarity methods to return bool and Similarity objects, respectively. See comparable.simple for examples.
Compound Comparables
Compound comparable types contain multiple simple comparable types. They must override the attributes property to define which attributes should be used for comparison. See comparable.compund for examples.
Examples
Comparable includes many generic comparable types:
python >>> from comparable.simple import Number, Text, TextEnum, TextTitle >>> from comparable.compound import Group
A basic script may look similar to the following:
from comparable.simple import TextTitle from comparable import tools base = TextTitle("The Cat and the Hat") items = [TextTitle("cat & hat"), TextTitle("cat & the hat")] print("Equality: {}".format(base == items[0])) print("Similarity: {}".format(base % items[0])) print("Duplicates: {}".format(tools.duplicates(base, items)))
For Contributors
Requirements
GNU Make:
Windows: http://cygwin.com/install.html
Linux: http://www.gnu.org/software/make (likely already installed)
virtualenv: https://pypi-hypernode.com/pypi/virtualenv#installation
Installation
Create a virtualenv:
make env
Run the tests:
make test make tests # includes integration tests
Build the documentation:
make doc
Run static analysis:
make pep8 make pylint make check # pep8 and pylint
Prepare a release:
make dist # dry run make upload
Changelog
0.1.1 (2014/03/03)
README cleanup.
0.1 (2014/03/03)
Code cleanup.
0.0.3 (2013/10/13)
Comparable.threshold is now an attribute (instead of property)
Fixed package-level imports
0.0.2 (2013/10/04)
Replaced Comparable.equality_list/similarity_dict with attributes
Replaced Comparable.similarity_threshold with threshold
0.0.1 (2013/10/02)
Initial release of Comparable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Comparable-0.1.1.tar.gz
.
File metadata
- Download URL: Comparable-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13dc19716e33dd4261021bca0cb86e8ca29664cefe350bf2a4516dfb2d6b3dd9 |
|
MD5 | c137406be60cd6c3468d212a1f5a8526 |
|
BLAKE2b-256 | 56feb7c1420c3abf862202144752eca8c40f05b85578a2978102e245eafa7fdc |
File details
Details for the file Comparable-0.1.1-py33-none-any.whl
.
File metadata
- Download URL: Comparable-0.1.1-py33-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3.3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a29b12a272f7c609c8baa3bf98314c67fada91a63451a668e83531e416b4f374 |
|
MD5 | 3abb4c62ec2c652cd6c75dc00e6f448d |
|
BLAKE2b-256 | 153d5896dea8c21bf34f0f129d5cc18bda64bd7448599a152d8b40f2868dcc3c |