-
Notifications
You must be signed in to change notification settings - Fork 0
/
daystrial.py
42 lines (34 loc) · 1.02 KB
/
daystrial.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
#Import the keywords
f = open('daysgazetteer.txt', 'r')
alldays = f.read().lower().split("\n")
f.close()
#Import the texts you want to search
f = open('31julytextNSFM.txt', 'r')
allTexts = f.read().lower().split("\n")
f.close()
#Our programme:
for entry in allTexts:
matches = 0
storedMatches = []
#for each entry:
allWords = entry.split(' ')
for words in allWords:
#remove punctuation that will interfere with matching
words = words.replace(',', '')
words = words.replace('.', '')
words = words.replace(';', '')
#if a keyword match is found, store the result.
if words in alldays:
if words in storedMatches:
continue
else:
storedMatches.append(words)
matches += 1
#if there is a stored result, print it out
if matches == 0:
print ' '
else:
matchString = ''
for matches in storedMatches:
matchString = matchString + matches + "\t"
print matchString