A package that clusters python objects based on a chosen string attribute
Project description
Text Based Clusterer
Allows you to cluster python objects based on chosen string attributes.
Installation
To install, use pip install text-based-clusterer.
Usage
Instantiation
You can import the Clusterer class with the line below.
from text_based_clusterer import Clusterer
To use the clusterer, first create a python class with a string attribute or use an existing python class with a string attribute.
class TestClass:
__init__(self, string1: str, string2: str):
self.string1 = string1
self.string2 = string2
Then instantiate the Cluster object. There is an optional parameter cluster_threshold that defines how textually similar objects should be to be clustered together. cluster threshold ranges from 0 (completely different) to 1 (exactly the same) and is set to a default of 0.3.
clusterer = Clusterer(cluster_threshold = 0.3)
Basic Clustering
Use the add_objects method to cluster objects. You will need to pass in a list of python objects as well as a list of strings representing the attributes used for clustering. You can retrieve a list of clusters using get_objects.
test_class_1 = TestClass('dog', 'cat')
test_class_2 = TestClass('cat', 'dog')
test_classes = [test_class_1, test_class_2]
single_string_clusterer = Clusterer()
single_string_clusterer.add_objects(test_classes, ['string_1'])
single_string_clusterer.get_objects() # returns [[test_class_1], [test_class_2]]
multi_string_clusterer = Clusterer()
clusterer.add_objects(test_classes, ['string_1', 'string_2'])
multi_string_clusterer.get_objects() # returns [[test_class_1, test_class_2]]
Adding to Existing Clusters
Use the add_clusters method to add an initial set of clusters in the form of nested lists. Note that this method should only be used when there are no existing clusters within the Cluster object because calling add_clusters does not perform clustering.
test_class_1 = TestClass('dog', 'cat')
test_class_2 = TestClass('cat', 'dog')
initial_cluster = [[test_class_1], [test_class_2]]
clusterer = Clusterer()
clusterer.add_clusters(initial_cluster, ['string_1'])
clusterer.add_objects([test_class_1], ['string_1'])
clusterer.get_objects() # returns [[test_class_1, test_class_1], [test_class_2]]
Sources Used
This package implements a text based incremental clustering algorithm from the research paper Incremental Clustering of News Reports.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file text-based-clusterer-0.0.2.tar.gz.
File metadata
- Download URL: text-based-clusterer-0.0.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71714cffe7e298f2c0d794819d019fb3bca4d228e58de87f10f502b4b7a828b7
|
|
| MD5 |
b7014beef12f99a4404b5b7b13009123
|
|
| BLAKE2b-256 |
dc605f591cb6476882e1dca8386dd1b40140a04f68c742446072060e769719f9
|
File details
Details for the file text_based_clusterer-0.0.2-py3-none-any.whl.
File metadata
- Download URL: text_based_clusterer-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30c1f9c119d0f7af8c4f8bbb42b010a03bc625e72d7fa85684dc28b2fea6476b
|
|
| MD5 |
3b13548491a69e43b6ddce9d4db90f34
|
|
| BLAKE2b-256 |
2e6420f1337a7959720142dac5dd03e8b5be4516a65b2a314908c172d7a84fda
|