# Helper utility to make thesaurus input file. # Not a program for students. import re def main(): # build phone book as list grewords = set() with open("grewords.txt") as file: for line in file: tokens = line.strip().split("\t") if len(tokens) != 2: continue word, defn = tokens grewords.add(word.lower()) thesaurus = {} part_of_speech = {} with open("oo-mythes/th_en_US_new.dat") as file: line = file.readline() while line != "": line = file.readline() if re.match(pattern=r'^[a-zA-Z]+[|][0-9]+$', string=line): word, count = line.strip().split("|") if word in grewords: synonyms = [] for i in range(int(count)): for syn in file.readline().strip().split("|"): if syn[0] == "(" and syn[-1] == ")": part_of_speech[word] = syn[1:-1] elif syn not in synonyms: synonyms.append(syn) thesaurus[word] = synonyms with open("thesaurus.txt", "w") as out: for word in sorted(thesaurus.keys()): print(word, file=out) print(part_of_speech[word], file=out) print("|".join(thesaurus[word]), file=out) print("", file=out) # blank line main()