Skip to main content

A package for dealing with histograms.

Project description

grams

A Python library for managing the histograms of text corpuses.

Build Status

codecov

Installation

Use the package manager pip to install grams.

pip install grams

Usage

import grams

# Generate a histogram from a list of sentences
hist = grams.Histogram(['A sentence here.',
                        'A sentence there.',
                        'A sentence anywhere.'])

# Generate a histogram from a text file
with open('corpus.txt', 'r') as file:
    file_hist = grams.Histogram(file)

# Find the distance between histograms ∈ [0, 1]
similarity = hist.similarity(file_hist)

# Sample a random word weighted by its number of occurrences
word = hist.sample()

# Display word frequencies in the terminal
hist.visualize()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Lorem      : ▇▇▇▇ 4.00
# Ipsum      : ▇▇▇▇ 4.00
# is         : ▇ 1.00
# simply     : ▇ 1.00
# dummy      : ▇▇ 2.00
# text       : ▇▇ 2.00
# of         : ▇▇▇▇ 4.00
# the        : ▇▇▇▇▇▇ 6.00
# printing   : ▇ 1.00
# and        : ▇▇▇ 3.00
# typesetting: ▇▇ 2.00
# industry   : ▇ 1.00
# has        : ▇▇ 2.00
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Create a distribution object from code coverage data
cov = grams.Covergram("Documents/.coverage")

# We can visualize our code coverage data as well.
cov.visualize()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# __init__.py       : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
# grams.py          : ▇▇▇▇▇▇▇▇▇▇▇▇ 25.00
# hashtable.py      : ▇▇▇▇▇▇▇▇▇▇▇ 22.00
# linkedlist.py     : ▇▇▇▇▇▇▇ 15.00
# online.py         : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40.00
# stats.py          : ▇▇▇▇▇▇▇▇▇▇ 21.00
# termgraph.py      : ▇▇▇▇▇▇ 12.00
# utils.py          : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 31.00
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Our distribution also maintains some useful statistics
avg_code_cov = int(cov.mean)
frequency_standard_deviation = int(hist.std)
frequency_variance = int(hist.var)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

grams-0.0.2.tar.gz (18.9 kB view hashes)

Uploaded Source

Built Distribution

grams-0.0.2-py3-none-any.whl (36.7 kB view hashes)

Uploaded Python 3

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