-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCode.py
More file actions
71 lines (51 loc) · 1.83 KB
/
Copy pathCode.py
File metadata and controls
71 lines (51 loc) · 1.83 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from gensim.models import Word2Vec
import bs4 as bs
import urllib.request
import re
import nltk
from allwordsfile import *
# scrapped_data = urllib.request.urlopen('https://en.wikipedia.org/wiki/Artificial_intelligence')
# article = scrapped_data .read()
# parsed_article = bs.BeautifulSoup(article,'lxml')
# paragraphs = parsed_article.find_all('p')
# # #
# article_text=''
# for p in paragraphs:
# article_text+=p.text
# processed_article = article_text.lower()
# processed_article = re.sub('[^a-zA-Z]', ' ', processed_article )
# processed_article = re.sub(r'\s+', ' ', processed_article)
# #print(type(processed_article))
# # Preparing the dataset
# all_sentences = nltk.sent_tokenize(processed_article)
# nltk.download('stopwords')
# all_words = [nltk.word_tokenize(sent) for sent in all_sentences]
# from nltk.corpus import stopwords
# for i in range(len(all_words)):
# all_words[i] = [w for w in all_words[i] if w not in stopwords.words('english')]
#print(all_words)
word2vec= Word2Vec.load("word2vec.model")
#word2vec = Word2Vec(all_words, min_count=1)
# word2vec.save("word2vec.model")
# vocabulary = word2vec.wv.vocab
s=str(input())
try:
print(word2vec.most_similar(s))
except:
KeyError
allwords[0].append(s);
word2vec=Word2Vec(allwords,min_count=1)
print(word2vec.most_similar(s))
word2vec.save("word2vec.model")
#print(word2vec.most_similar('Knowledge'))
# arr = nltk.sent_tokenize(word)
# arr1=[nltk.word_tokenize(sent) for sent in arr]
# #worddict['s'].append('supernatural')
# print(arr1)
# w2v=Word2Vec(arr1, min_count=1,size=10,seed=1,workers=1)
# vocabulary= w2v.wv.vocab
# v1 = w2v.wv['King']
# print(v1)
# print(w2v.wv.most_similar('King',topn=10))
#print(worddict)
#print(models.similarity('france','spain'))