def main(args): a_dict = word_dict.word_dict() ### test class pt_node anode = pt_node(a_dict, "python") bnode = pt_node(a_dict, "zzxyz") anode.print_pt_node(a_dict) print ### test class ptree my_dict = word_dict.word_dict() a_ptree = ptree(my_dict) a_ptree.add_word_to_tree('equality', 'yes') a_ptree.add_word_to_tree('fraternity', 'yes') a_ptree.add_word_to_tree('liberty', 'no') a_ptree.print_tree() print 40*'*' sentence = "chuck could a wood chuck chuck if a wood chuck could chuck wood" sentence = sentence.split(' ') reversed_sentence = sentence reversed_sentence.reverse my_ptree = learn_ccc(sentence, reversed_sentence, 5) print 40*'_' some_text = open(args[0], 'r').read() some_text = some_text[:-1].split(' ') my_ptree = ptree(my_dict) build_tree('yes', some_text, my_ptree) my_ptree.print_tree() print 40*'-'
def main(args): a_dict = word_dict.word_dict() ### test class pt_node anode = pt_node(a_dict, "python") bnode = pt_node(a_dict, "zzxyz") anode.print_pt_node(a_dict) print ### test class ptree my_dict = word_dict.word_dict() a_ptree = ptree(my_dict) a_ptree.add_word_to_tree('equality', 'yes') a_ptree.add_word_to_tree('fraternity', 'yes') a_ptree.add_word_to_tree('liberty', 'no') a_ptree.print_tree() print 40 * '*' sentence = "chuck could a wood chuck chuck if a wood chuck could chuck wood" sentence = sentence.split(' ') reversed_sentence = sentence reversed_sentence.reverse my_ptree = learn_ccc(sentence, reversed_sentence, 5) print 40 * '_' some_text = open(args[0], 'r').read() some_text = some_text[:-1].split(' ') my_ptree = ptree(my_dict) build_tree('yes', some_text, my_ptree) my_ptree.print_tree() print 40 * '-'
def main(args): # args = ["medical insuranceY5jPHX.txt", 'health policyTlYqX1.txt'] my_dict = word_dict.word_dict() pages = [] page_lbls = [] for page in args: a_scrape = a_web_scrape() a_scrape.one_tok_file(page) pages.append(a_scrape) page_lbls.append(a_scrape.claim_lbl) my_ptree = pruned_ptree(my_dict, depth=(N_depth-1), lbls=ptree.labels(page_lbls)) for p in pages: p.add_to_ptree(my_ptree) my_ptree.peruse_tree() print 40*'*'
def learn_ccc(yes_sample, no_sample, n_gram_length): "Return a prefix tree learned from two text samples" the_dict = word_dict.word_dict() the_tree = ptree(the_dict, n_gram_length) return build_tree('no', no_sample, build_tree('yes', yes_sample, the_tree))