-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironmentFinder.py
43 lines (38 loc) · 1.13 KB
/
EnvironmentFinder.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
import csv
""" This script takes in a file, asks for a pattern to find, and returns
the sorrounding matches of the provided pattern.
@Author Cesar Villalobos
"""
def Environments():
""" Given a file, and provided a "pattern", it finds words with this pattern and
returns their phonological environments
"""
filename = input("What file would you like to use? ")
f = open(filename ,"r")
word_list = []
for line in f:
word_list.append(line)
while (True):
pattern_String = input("What patterns should I find? ")
if (pattern_String == "stop"):
return
pattern_List = list(pattern_String.split(','))
for p in pattern_List:
patterns = []
print ("### Patterns for " + p + " ###")
for word in word_list:
if p in word:
placeholder = word.find(p)
if (placeholder == 0):
front = word[placeholder + 1]
back = '#'
elif (placeholder == len(word) - 2):
front = '#'
back = word[placeholder - 1]
else:
front = word[placeholder + 1]
back = word[placeholder - 1]
pattern = back + '_' + front
if pattern not in patterns:
patterns.append(pattern)
print (pattern)