https://github.com/sr-murthy/word-n-grams
Computes word-n-gram stats from a given piece of text (local file or a string literal)
https://github.com/sr-murthy/word-n-grams
Last synced: 8 months ago
JSON representation
Computes word-n-gram stats from a given piece of text (local file or a string literal)
- Host: GitHub
- URL: https://github.com/sr-murthy/word-n-grams
- Owner: sr-murthy
- Created: 2016-12-21T22:09:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-31T21:22:28.000Z (over 8 years ago)
- Last Synced: 2024-12-27T06:43:56.308Z (over 1 year ago)
- Language: Python
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Word n-Grams
A simple script that scans a piece of text (a local file in the same location as the script, or a string literal enclosed in quotes) and displays the top *k* word *n*-grams (word sequences of length *n*) from the text, including their absolute and relative frequencies. For example, in the following sentence
> "It is raining today, and I will need an umbrella."
the word *4*-grams are *"It is raining today"*, *"is raining today and"*, *"raining today and I"*, *"and I will need"*, *"I will need an"*, *"will need an umbrella."* Case and punctuation marks and ignored when comparing word grams, so that the word *4*-grams "It is raining today," and "it is raining today" are considered the same.
An example:
The top 10 word 5-grams and their frequencies (absolute and relative) are as follows.
it's important to be confident 4 (0.014)
a photo is real or 4 (0.014)
be confident and stand up 4 (0.014)
photo is real or retouched 4 (0.014)
important to be confident and 3 (0.01)
idea of what beauty is 3 (0.01)
confident and stand up to 3 (0.01)
think words can never hurt 3 (0.01)
to be confident and stand 3 (0.01)
and stand up to bullies 3 (0.01)