-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yash Srivastava <yashsrivastava3005@gmail.com>
- Loading branch information
Yash Srivastava
committed
Feb 9, 2019
1 parent
4637731
commit f002726
Showing
32 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.vscode | ||
.DS* | ||
**/.DS* | ||
**/__*/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Reddit Flair Prediction.ipynb | ||
Automatically generated by Colaboratory. | ||
Original file is located at | ||
https://colab.research.google.com/github/radonys/Reddit-Flair-Detector/blob/master/Reddit_Flair_Prediction.ipynb | ||
## Reddit India Flair Prediction | ||
### Install and Import Required Modules | ||
""" | ||
|
||
#!pip install scikit-learn praw nltk | ||
|
||
import sklearn | ||
import pickle | ||
import praw | ||
import re | ||
from bs4 import BeautifulSoup | ||
import nltk | ||
nltk.download('all') | ||
from nltk.corpus import stopwords | ||
|
||
"""### Variable Declarations and Utility Functions""" | ||
|
||
reddit = praw.Reddit(client_id='_4Z0SOGEI31a3Q', client_secret='fzhJE6_cjPqLN6goG4R7cJ6SK3Q', user_agent='reddit-flair-detector', username='radonys', password='Yash@1234') | ||
#loaded_model = pickle.load(open('finalized_model.sav', 'rb')) | ||
|
||
REPLACE_BY_SPACE_RE = re.compile('[/(){}\[\]\|@,;]') | ||
BAD_SYMBOLS_RE = re.compile('[^0-9a-z #+_]') | ||
STOPWORDS = set(stopwords.words('english')) | ||
|
||
def clean_text(text): | ||
|
||
text = BeautifulSoup(text, "lxml").text | ||
text = text.lower() | ||
text = REPLACE_BY_SPACE_RE.sub(' ', text) | ||
text = BAD_SYMBOLS_RE.sub('', text) | ||
text = ' '.join(word for word in text.split() if word not in STOPWORDS) | ||
return text | ||
|
||
"""### Detect Reddit India Post Flair""" | ||
|
||
def detect_flair(url,loaded_model): | ||
|
||
submission = reddit.submission(url=url) | ||
|
||
data = {} | ||
|
||
data['title'] = submission.title | ||
data['url'] = submission.url | ||
|
||
submission.comments.replace_more(limit=None) | ||
comment = '' | ||
for top_level_comment in submission.comments: | ||
comment = comment + ' ' + top_level_comment.body | ||
data["comment"] = comment | ||
data['title'] = clean_text(data['title']) | ||
data['comment'] = clean_text(data['comment']) | ||
data['combine'] = data['title'] + data['comment'] + data['url'] | ||
|
||
return loaded_model.predict([data['combine']]) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.