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-rc.1.tar.gz
.
File metadata
- Download URL: Comparable-0.1.1-rc.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aaa3206fb98b7174d9e2a2dd13cf33de2bc0a9f8d256bac4aba202548b55b9c |
|
MD5 | e63457db64966fef55f6b0ca7c863155 |
|
BLAKE2b-256 | 393c9a516eb93dac40cbc027b927fe1ecd2d344110a34569822f5379fe93e2ef |
File details
Details for the file Comparable-0.1.1_rc.1-py33-none-any.whl
.
File metadata
- Download URL: Comparable-0.1.1_rc.1-py33-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3.3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c86d1d643d002b8d67a39925a74a32febc0fd3d340486ede363ac0837bf230d |
|
MD5 | c63662d66376be8d89d4355c41f5831d |
|
BLAKE2b-256 | 422611471f05d50750f653c84d44ffa301cb244b873cc7d7414f3ff02fb1285a |