forked from adi07tya/Restaurant_Cuisine_Predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThird.py
27 lines (21 loc) · 883 Bytes
/
Third.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pymongo import MongoClient
from nltk.stem.wordnet import WordNetLemmatizer
tags_collection = MongoClient('mongodb://localhost:27017/')['reviews_Tags']['reviews_Collection']
corpus_collection = MongoClient('mongodb://localhost:27017/')['reviews_Tags']['noun_corpus_Collection']
reviews_cursor = tags_collection.find()
reviewsCount = reviews_cursor.count()
reviews_cursor.batch_size(5000)
lem = WordNetLemmatizer()
for review in reviews_cursor:
nouns = []
words = [word for word in review["words"] if word["pos"] in ["NN", "NNS"]]
for word in words:
nouns.append(lem.lemmatize(word["word"]))
corpus_collection.insert_one({
"cityName": "Bangalore",
"reviewNo": review["reviewNo"],
"restaurantName": review["restaurantName"],
"rating": review["rating"],
"review": review["review"],
"words": nouns
})