Skip to main content
# Reddit NLP Package

A lightweight Python module that performs tokenization and processing of text on Reddit. It allows you to analyze users, titles, comments and subreddits to understand their vocabulary. The module comes packaged with its own inverted index builder for storing vocabularies and word frequencies, such that it can generate large corpora of tf-idf weighted words. This means that you don't have to worry about storing and reading word counts if you're running scripts over long periods.

## License

Copyright 2014 Jai Juneja.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).

## Installation

### Using pip or easy_install

You can download the latest release version using `pip` or `easy_install`:

```
pip install redditnlp
```

### Latest development version
You can alternatively download the latest development version directly from GitHub:

```
git clone https://github.com/jaijuneja/reddit-nlp.git
```

Change into the root directory:

```
cd reddit-nlp
```

Then install the package:

```
python setup.py install
```

### Usage:

A more complex sample program using the redditnlp module can be found at `https://github.com/jaijuneja/reddit-nlp/blob/master/example.py`. Here we outline a basic word counter application.

The module consists of two classes: a Reddit word counter and a tf-idf corpus builder. These can be instantiated as follows:

```python
from redditnlp import RedditWordCounter, TfidfCorpus

counter = RedditWordCounter('your_username')
corpus = TfidfCorpus()
```

To adhere to the Reddit API rules, it is asked that you use your actual Reddit username in place of `'your_username'` above.

For further information on the attributes and methods of these two classes you can run:

```python
help(RedditWordCounter)
help(TfidfCorpus)
```

Next, we can tokenize 1000 comments from a selection of subreddits, extract the most common words and save all of our data to disk:

```python
for subreddit in ['funny', 'aww', 'pics']:
# Tokenize and count words for 1000 comments
word_counts = counter.subreddit_comments(subreddit, limit=1000)

# Add the word counts to our corpus
corpus.add_document(word_counts, subreddit)

# Save the corpus to a specified path (must be JSON)
corpus.save(path='word_counts.json')

# Save the top 50 words (by tf-idf score) from each subreddit to a text file
for subreddit in corpus.get_document_list():
top_words = corpus.get_top_terms(document, num_terms=50)
with open('top_words.txt', 'ab') as f:
f.write(document + '\n' + '\n'.join(top_words.keys()))
```

## Contact

If you have any questions or have encountered an error, feel free to contact me at `jai -dot- juneja -at- gmail -dot- com`.

Release files for redditnlp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redditnlp 0.1.1
File Size Uploaded
redditnlp-0.1.1.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redditnlp 0.1.1
File Interpreter ABI Platform
redditnlp-0.1.1-py2.7.egg Legacy Egg format - - Details

Total release size: 48.2 kB

Release files / redditnlp-0.1.1.tar.gz

Download URL redditnlp-0.1.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
67ab852bc76c23afb62d8bd16c69074ad3d8452b69d863181f3b37f4b558062e
BLAKE2b-256 checksum
How to use checksums
b9bcc36ff21dadffd4cabf8ab754f7a266a2af3b7b92d01db2a1b12f01b2f834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / redditnlp-0.1.1-py2.7.egg

Download URL redditnlp-0.1.1-py2.7.egg
Size 31.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
3180fed4d84fdcaa91717f9c479de95305c3468953631ddc34dea3fde795efd8
BLAKE2b-256 checksum
How to use checksums
42f1866bb01399c6eee9caeb08a1e45f0caa02d6323e6ef3b71b27dad45b5915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.3

2 release files

This release

0.1.1 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page