Skip to main content

Base class to enable objects to be compared for similarity.

Project description

Introduction

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

  • setuptools and/or pip

Installation

Comparable can be installed with pip or easy_install:

pip install Comparable

Or directly from the source code:

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

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 equality_list and similarity_dict properties 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)))

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.0.1.tar.gz (13.8 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for Comparable-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5d72eeb26e4564fab015799bf8885166feac61a0c15d0d899cae6b9ea2881084
MD5 de5946aaacba7a2ff61c22070a2a8b4f
BLAKE2b-256 b74efca5478cca7c95147d7fdb601c79a047aeedce004e8ba3dc288afeb37719

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