case sensitivity fix

This commit is contained in:
Xevion
2019-08-24 19:12:51 -05:00
parent 39082ef8b3
commit f6370de2ef

View File

@@ -38,18 +38,22 @@ def processWord(word):
token = getToken(sub.lower()) token = getToken(sub.lower())
if token: if token:
# Sometimes mulitple tokens can appear for the same one, we just select the one that is longest # Sometimes mulitple tokens can appear for the same one, we just select the one that is longest
possible.append((token, len(sub))) possible.append((token, len(sub), sub))
# A token replacement has been found at this index
if possible: if possible:
# Find the best one, based on the sub
select = max(possible, key=lambda item : item[1]) select = max(possible, key=lambda item : item[1])
# print(index, select, word[index:index + select[1]]) # print(index, select, word[index:index + select[1]])
word = word[:index] + select[0] + word[index + select[1]:] word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:]
# word[index:index + select[1]] = select[0] # word[index:index + select[1]] = select[0]
index += 1 index += 1
return word return word
# Process a single line
def processLine(line): def processLine(line):
return ' '.join([processWord(word) for word in line.split(' ')]) return ' '.join([processWord(word) for word in line.split(' ')])
# Drive Code
def main(): def main():
path = os.path.join(sys.path[0], 'input') path = os.path.join(sys.path[0], 'input')
data = open(path, 'r').read().split('\n')[1:] data = open(path, 'r').read().split('\n')[1:]