A package for managing histograms.
Project description
grams
A Python library for managing the histograms of text corpuses.
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
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
grams-0.0.3.tar.gz
(19.0 kB
view details)
Built Distribution
grams-0.0.3-py3-none-any.whl
(36.8 kB
view details)
File details
Details for the file grams-0.0.3.tar.gz
.
File metadata
- Download URL: grams-0.0.3.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb91b4b6690fdebf9d04958face07b1fa5b0a76559c236754347700788345ec1 |
|
MD5 | 0b054017e4245361a6ea54bf9109a999 |
|
BLAKE2b-256 | 585060f63ab8eed9d36ab2aa054e45f69c8a63adf045d803edaf238335a57f58 |
File details
Details for the file grams-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: grams-0.0.3-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 530fb26315be322bd15afc2c39357d03a99cf9ec106bc74929f2e951533beb1a |
|
MD5 | a49f798b7346d1cd6d19b21cc3cb74da |
|
BLAKE2b-256 | e8d061ecd1ce1b2e82e03ef61b877ae60f3cd6fab2f5acbb895699c6e261ab0a |