-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.R
120 lines (111 loc) · 5.04 KB
/
set.R
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
sets<-function(textname)
{
if(textname=="text1")
{
python.exec("length=len(set([word.lower() for word in text1 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text1 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text2")
{
python.exec("length=len(set([word.lower() for word in text2 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text2 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text3")
{
python.exec("length=len(set([word.lower() for word in text3 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text3 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text4")
{
python.exec("length=len(set([word.lower() for word in text4 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text4 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text5")
{
python.exec("length=len(set([word.lower() for word in text5 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text5 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text6")
{
python.exec("length=len(set([word.lower() for word in text6 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text6 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text7")
{
python.exec("length=len(set([word.lower() for word in text7 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text7 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text8")
{
python.exec("length=len(set([word.lower() for word in text8 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text8 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else if(textname=="text9")
{
python.exec("length=len(set([word.lower() for word in text9 if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in text9 if word.isalpha()]))")
rlength<-python.get("length")
rsorted<-python.get("s")
label1<-glabel(paste("The number of unique words are : ",rlength),container=mainwindow)
dump("rsorted",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
else
{
python.exec("import nltk")
file<-scan(file=textname,what="list",n=-1,sep="",skip=0,na.strings="NA")
str<-unlist(file)
str<-paste(file,collapse=" ")
prop<-str_replace_all(str,"'","")
prop<-str_replace_all(prop,'"',"")
python.assign("pystr",prop)
python.exec("pylst=pystr.split()")
python.exec("length=len(set([word.lower() for word in pylst if word.isalpha()]))")
python.exec("s=sorted(set([word.lower() for word in pylst if word.isalpha()]))")
rlen<-python.get("length")
label1<-glabel(paste("The number of unique words are : ",rlen),container=mainwindow)
rstr<-python.get("s")
dump("rstr",file="Unique.txt")
label2<-glabel("All the different words have been written to the file 'Unique.txt' ",container=mainwindow)
}
}