def component4d(): print("-----Component 4d (Check results folder)-----") model1 = MarcovModel("franz_kafka_collected_works.txt", "word", 3) model2 = MarcovModel("practice_phrenology_simplified.txt", "word", 3) model3 = MarcovModel("william_shakespeare_collected_works.txt", "word", 3) models = [model1, model2, model3] f = open("results/component4d.txt", "a") length_of_test_input = 60 for model in models: f.write(f"\n\n-----Estimation Results for {model.corpus_filename}-----\n") for estimator_model in models: f.write(f"\n-----When estimated by: {estimator_model.corpus_filename}-----\n") estimates = [] text = "" nextPos = 0 while nextPos < (len(model.testset) - length_of_test_input): text = model.testset[nextPos:nextPos + length_of_test_input] estimate = estimator_model.estimate(text) # print(estimate) estimates.append(estimate) text = "" nextPos += length_of_test_input f.write(f"{statistics.mean(estimates)}")
def component4f(): # intentionally chose Franz Kafka and Edgar Allan Poe because we thought they were similar print("-----Component 4f (Check results folder)-----") f = open("results/component4f.txt", "a") for order in range(1, 4): f.write("\n Level: Word\n") f.write(f"\n Order: {order}\n") model1 = MarcovModel("franz_kafka_collected_works.txt", "word", 1) model2 = MarcovModel("edgar_allan_poe_collected_works.txt", "word", 1) models = [model1, model2] length_of_test_input = 60 for model in models: f.write(f"\n\n-----Estimation Results for {model.corpus_filename}-----\n") for estimator_model in models: f.write(f"\n-----When estimated by: {estimator_model.corpus_filename}-----\n") estimates = [] text = "" nextPos = 0 while nextPos < (len(model.testset) - length_of_test_input): text = model.testset[nextPos:nextPos + length_of_test_input] estimate = estimator_model.estimate(text) # print(estimate) estimates.append(estimate) text = "" nextPos += length_of_test_input f.write(f"{statistics.mean(estimates)}")
def component2f(): print("-----Component 2f (Check results folder)-----") f = open("results/component2f.txt", "a") for order in range(1, 13): f.write(f"\n Order: {order} \n") model = MarcovModel("harry_potter_1.txt", "word", order) f.write(model.generate(40))
def component2b(): print("-----Component 2b (Check results folder)-----") f = open("results/component2b.txt", "a") for order in range(1, 6): f.write(f"\n-----Level: Word / Order: {order}-----\n") model = MarcovModel("franz_kafka_collected_works.txt", "word", order) f.write(model.generate(20, "The"))
def component4(): # Basic idea for the hybrid generation is to prioritize meaning over syntax. In other words, we generate a text using the original generate method. Then you correct any jarring grammar mistakes with the pos generation scheme. print("-----working on component4 (Check 'results' folder)-----") f = open("results/component4.txt", "a") model = MarcovModel("arthur_conan_doyle_collected_works.txt", level="word", order=3, hybrid=True) for i in range(3): f.write("-----Hybrid Generate Engaged, Level: word, Order: 3-----\n") f.write(model.generate(50) + "\n")
def component3b(): print("-----working on component3b (Check 'results' folder)-----") f = open("results/component3b.txt", "a") f.write("\n-----POS ENGAGED-----\n\n") for order in range(1, 8): model = MarcovModel("alexander_dumas_collected_works.txt", level="word", order=order, pos=True) f.write( f"-----Results for {model.corpus_filename}, Order: {order} -----\n" ) f.write(model.generate(30) + "\n")
def component2e(): print("-----Component 2e (Check results folder)-----") model1 = MarcovModel("franz_kafka_collected_works.txt", "character", 5) model2 = MarcovModel("arthur_conan_doyle_collected_works.txt", "word", 3) model3 = MarcovModel("edgar_allan_poe_collected_works.txt", "word", 2) models = [model1, model2, model3] f = open("results/component2e.txt", "a") for model in models: f.write( f"\n-----Results for {model.corpus_filename} / Level: {model.level} / Order: {model.order}-----\n" ) f.write(model.generate(30))
def component3b(): print("-----Component 3b (Check results folder)-----") f = open("results/component3b.txt", "a") # Sue model1 = MarcovModel("harry_potter_1.txt", "word", 5) # Yemi model2 = MarcovModel("franz_kafka_collected_works.txt", "word", 5) # Nicole model3 = MarcovModel("origin_of_species.txt", "word", 5) # Maanya model4 = MarcovModel("practice_phrenology_simplified.txt", "word", 5) models = [model1, model2, model3, model4] for model in random.sample(models, len(models)): f.write("\nmodel: \n") f.write(model.generate(30))
def component3c(): print("-----Component 3c (Check results folder)-----") f = open("results/component3c.txt", "a") # Sue model1 = MarcovModel("harry_potter_1.txt", "word", 4) # Yemi model2 = MarcovModel("franz_kafka_collected_works.txt", "word", 4) # Nicole model3 = MarcovModel("origin_of_species.txt", "word", 4) # Maanya model4 = MarcovModel("practice_phrenology_simplified.txt", "word", 4) models = [model1, model2, model3, model4] for model in random.sample(models, len(models)): f.write(f"\n-----{model.corpus_filename}/ Level: Word / Order: 4-----\n") f.write(model.generate(35))
def component2d(): print("-----Component 2d (Check results folder)-----") f = open("results/component2d.txt", "a") f.write(f"\n-----Mystery Model / Level: Character / Order: 3-----\n") model1 = MarcovModel("franz_kafka_collected_works.txt", "character", 3) model2 = MarcovModel("arthur_conan_doyle_collected_works.txt", "character", 3) f.write("\n Results for Mystery Model \n") f.write(model1.generate(50, "The")) f.write("\n\n Results for Mystery Model \n") f.write(model2.generate(50, "The"))
def component3c(): print("-----working on component3c (Check 'results' folder)-----") f = open("results/component3c.txt", "a") f.write("-----without the POS-----") model = MarcovModel("alexander_dumas_collected_works.txt", level="word", order=5, pos=False) f.write(model.generate(30) + "\n") f.write("-----with the POS-----") model2 = MarcovModel("alexander_dumas_collected_works.txt", level="word", order=5, pos=True) f.write(model2.generate(30) + "\n")
def component2c(): print("-----Component 2c (Check results folder)-----") f = open("results/component2c.txt", "a") for order in range(1, 6): f.write(f"\n-----Mystery Model / Level: Word / Order: {order}-----\n") model1 = MarcovModel("franz_kafka_collected_works.txt", "word", order) model2 = MarcovModel("arthur_conan_doyle_collected_works.txt", "word", order) f.write("\n Level: word \n") f.write(f"\n Order: {order} \n") f.write("\n Results for Mystery Model \n") f.write(model1.generate(50, "The")) f.write("\n Results for Mystery Model \n") f.write(model2.generate(50, "The"))