-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokens.py
54 lines (38 loc) · 1.37 KB
/
Tokens.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#-*- coding: utf-8 -*-
import nltk
from nltk.tokenize import sent_tokenize
from nltk.tag import pos_tag
from nltk.corpus import wordnet as wn
print"Give me phrase1!"
x=raw_input()
print"Give me phrase2!"
y=raw_input()
x=nltk.word_tokenize(x)
y=nltk.word_tokenize(y)
tokens1=pos_tag(x)
tokens2=pos_tag(y)
print tokens1
print tokens2
a=[]
b=[]
#προσθήκη λέξεων με συγκεκριμένα tag(ρήματα,ουσιαστικά,επίθετα) σε νέες λίστες
for (word,tag) in tokens1:
if tag[:2]=='VB' or tag[:2]=='NN' or tag[:2]=='JJ':
a.append(word)
print a
for (word,tag) in tokens2:
if tag[:2]=='VB'or tag[:2]=='NN'or tag[:2]=='JJ':
b.append(word)
print b
#εύρεση συνώνυμων λέξεων με βαση τα στοιχεία του α και αποθήκευση στο syn_set
syn_set=[]
for i in a:
for synset in wn.synsets(i):
for item in synset.lemmas():
syn_set.append(item.name())
print ("Synonym words from phrase 1:" ,syn_set)
#Έλεγχος για ύπαρξη συνώνυμων λέξεων(ρήματων,ουσιαστικών και επιθετών) αναμέσα στις συνώνυμες λεξεις του α και αυτές του β
if any(word in syn_set for word in b):
print "There are similarities"
else:
print "No similarities"