Skip to main content

Base class to enable objects to be compared for similarity.

Project description

Comparable
==========

| |Build Status|
| |Coverage Status|
| |PyPI Version|

| 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
------------

- Python 3.3: http://www.python.org/download/releases/3.3.4/#download

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
- Mac: https://developer.apple.com/xcode
- Linux: http://www.gnu.org/software/make (likely already installed)

- virtualenv: https://pypi-hypernode.com/pypi/virtualenv#installation
- Pandoc: http://johnmacfarlane.net/pandoc/installing.html

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

.. |Build Status| image:: https://travis-ci.org/jacebrowning/comparable.png?branch=master
:target: https://travis-ci.org/jacebrowning/comparable
.. |Coverage Status| image:: https://coveralls.io/repos/jacebrowning/comparable/badge.png?branch=master
:target: https://coveralls.io/r/jacebrowning/comparable?branch=master
.. |PyPI Version| image:: https://badge.fury.io/py/Comparable.png
:target: http://badge.fury.io/py/Comparable

Changelog
=========

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Comparable-0.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

Comparable-0.1-py33-none-any.whl (17.7 kB view details)

Uploaded Python 3.3

File details

Details for the file Comparable-0.1.tar.gz.

File metadata

  • Download URL: Comparable-0.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Comparable-0.1.tar.gz
Algorithm Hash digest
SHA256 01486e5a3c00d26e3c9e9d48feb5e9748c39d3168402a35573edd33f13a9f54d
MD5 de4b18ab1e66483fec3e69e43d3481e8
BLAKE2b-256 59907fcabeedfa814d8037523cb7b2ce18b2882c48d2109dc671bc4367bad30c

See more details on using hashes here.

File details

Details for the file Comparable-0.1-py33-none-any.whl.

File metadata

File hashes

Hashes for Comparable-0.1-py33-none-any.whl
Algorithm Hash digest
SHA256 814ddf10b49633e904fdd977c7abe5907b286e1200f29eb8351c13d9552c40d7
MD5 d81a4473b76d0bf3a331250aed9c84ab
BLAKE2b-256 adb2d306a83eedfa44492b38077f09f4689bebf39b8eda5896563ae97d6f40ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page