Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gazetteer keyword searching
#This Python programme will let you find pre-defined keywords in a series of entries.
#Written by Adam Crymble 2 March 2015, for Intro to Digital History class, University of Hertfordshire
#Import the keywords
f = open('keywords.txt', 'r')
allKeywords ="\n")
#Import the texts you want to search
f = open('texts.txt', 'r')
allTexts ="\n")
#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 allKeywords:
if words in storedMatches:
matches += 1
#if there is a stored result, print it out
if matches == 0:
print ' '
matchString = ''
for matches in storedMatches:
matchString = matchString + matches + "\t"
print matchString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment