-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2onsetsample.py
75 lines (56 loc) · 1.77 KB
/
2onsetsample.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
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
from nltk.corpus import words
import pandas as pd
import numpy as np
df_csv3 = pd.read_csv('onsetsample.csv')
df_csv2 = pd.read_csv('onsetsample.csv')
df_csv1 = pd.read_csv('onsetsample.csv')
df= pd.DataFrame(columns=['Onset word for second letter'])
ftCol = df_csv1.iloc[:, 0].values
def onset(word):
result=[]
a = word
alphabet = 'abcdefghijklmnopqrstuvwxyz'
post_string = a[1:]
final = [letter+post_string for letter in alphabet]
setofwords = set(words.words())
for i in final:
if i in setofwords:
result.append(i)
return result
def onset2word(word):
result = []
a = word
alphabet = 'abcdefghijklmnopqrstuvwxyz'
post_string1 = a[0]
post_string2 = a[2:]
final2 = [post_string1+letter+post_string2 for letter in alphabet]
setofwords = set(words.words())
for i in final2:
if i in setofwords:
result.append(i)
return result
print(ftCol)
sarray1word2=[]
for j in ftCol:
print(j)
add = []
resultn=[]
sflatList1 = []
oflatList2=[]
sarray1word2 =[]
oarray2word1=[]
first= onset(j)
second = onset2word(j)
for i in first:
oarray2word1.append(onset2word(i))
oflatList2 = [ item for elem in oarray2word1 for item in elem]
for k in second:
sarray1word2.append(onset(k))
sflatList1 = [ item for elem in sarray1word2 for item in elem]
add = sflatList1 + oflatList2
for i in add:
if i not in resultn:
resultn.append(i)
print(resultn)
df = pd.DataFrame([resultn])
df.to_csv('osw.csv', index=False, mode= 'a', header=False,sep=';')