ax.set_title('Distance between Word Instances by Book and Author') ax.set_xticks(index + bar_width / 2) plt.xticks(fontsize=8, rotation=90) ax.set_xticklabels(book) ax.legend() fig.tight_layout() #plt.show() filepng = "visualizations/" + title + ".png" filepdf = "visualizations/" + title + ".pdf" plt.savefig(filepng, bbox_inches='tight') plt.savefig(filepdf, bbox_inches='tight') if __name__ == '__main__': corpus = Corpus('sample_novels') novels = corpus._load_novels() num = 0 #while num <10: medians_he = [] medians_she = [] books = [] for novel in novels[num * 10:num * 10 + 9]: result_he = instance_dist(novel, "he") result_she = instance_dist(novel, "she") try: medians_he.append(median(result_he)) except: medians_he.append(0)
>>> find_female_adj(scarlett) {'beautiful': 3, 'sad': 1} :param:novel :return: dictionary of adjectives that appear around female pronouns and the number of occurences """ return find_gender_adj(novel, True) if __name__ == '__main__': test_function() print("loading corpus") corpus = Corpus('sample_novels') print("loading novel") novel = corpus._load_novels()[15] print(novel.author, novel.title, novel.word_count) print("running function") result = find_male_adj(novel) output = [] for key in result.keys(): output.append((result[key], key)) print(sorted(output, reverse=True)) def process_medians(helst, shelst, authlst): """ >>> medians_he = [12, 130, 0, 12, 314, 18, 15, 12, 123] >>> medians_she = [123, 52, 12, 345, 0, 13, 214, 12, 23] >>> books = ["a", "b", "c", "d", "e", "f", "g", "h", "i"] >>> process_medians(helst=medians_he, shelst=medians_she, authlst=books)