Giter VIP home page Giter VIP logo

python-shash's Introduction

python-shash

Charikar's Hash for Identifying Similar Documents

What is it?

This module wraps around an excellent C implementation of Charikar's Hash, used to identify (and thus check) the similarity of documents.

It has been tested with Python 3.8 on Ubuntu 20.04 AMD64, but should work with pretty much every 3.x version of Python.

Binary Installation

There is none yet, since I would like to thoroughly test this module in a production envrionment. When that's done, it will be uploaded to PyPI.

Compilation From Source

Clone the repository and build from source:

$ git clone https://github.com/ronen25/python-shash
$ cd python-shash
$ python3 setup.py install

It is recommended to do so in a virtual environment, so as not to pollute your global environment.

The API

The API is rather simplistic and remains true to the original C source, with two hash functions and a Hamming distance function.

To import the module, use:

import shash
Function Parameters Description
charikar_hash64 str or bytes array Calculates Charikar's hash for the given data
charikar_hash64_wide str or bytes array ; token width (int) Calculates Charikar's hash for the given data, with configurable token_width
hamming_dist Two integers, representing Charikar hashes Calculates the Hamming distance between the two hashes

Example

import shash
s1 = 'testing this beautiful string'
h1 = shash.charikar_hash64(s1)

print(h1)
>>> 8049384540012662773

s2 = 'testings this beautiful string'
h2 = shash.charikar_hash64(s2)

print(h2)
>>> 5115011339482989567

print(shash.hamming_dist(h1, h2))
>>> 17

print(shash.hamming_dist(h1, h1)) # Strings are the same, should print 0
>>> 0

s4 = 'testing this beautiful strings'
h3 = shash.charikar_hash64(s4)

print(shash.hamming_dist(h1, h3))
>>> 17

License

This library is distributed under the Creative Commons Attribution 3.0 Unported License.

python-shash's People

Contributors

ronen25 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.