def run_tag_sentences(self, tag_tree_path, sentences_market_path, tags_path, untag_sentence_path) : file_operator = TextFileOperator() sentences = [u'技能贴 | 黑色打底裤的10种正确穿搭方式', u'春季男鞋韩版潮流行英伦男士休闲鞋'] cmd_list = file_operator.reading(tag_tree_path) tag_tree = TagTree(cmd_list) robot = Robot() tags, untag_sentences = robot.tag_sentences(tag_tree, sentences[0:1000]) print 'finish'
def run_robot(self, tag_tree_path, sentences_market_path, tags_path) : robot = Robot() loader = PickleMarket() file_operator = TextFileOperator() cmd_list = file_operator.reading(tag_tree_path) tag_tree = TagTree(cmd_list) sentences = loader.load_market(sentences_market_path) tags = loader.load_market(tags_path) print 'start' string = raw_input().decode('gb18030') # string = u'我想要毛衣' sentences = robot.question_and_answer(string, sentences, tags, tag_tree)
def run_tag_sentences(self, tag_tree_path, sentences_market_path, tags_martket_path, dict_market_path) : file_operator = TextFileOperator() loader = PickleMarket() sentences = loader.load_market(sentences_market_path) cmd_list = file_operator.reading(tag_tree_path) tag_tree = TagTree(cmd_list) robot = Robot() tags, tags_show, untag_sentences = robot.tag_sentences(tag_tree, sentences[0:]) loader = JsonMarket() loader.dump_market(tags, tags_martket_path) loader.dump_market(tag_tree.dict_tuple, dict_market_path) print '%.2f%% article >= 1 tags, number is, %d.' \ % (100.0 * len([tag for tag in tags_show if len(tag) >= 1]) / len(sentences)) \ % len([tag for tag in tags_show if len(tag) >= 1])
def run_test(self, tag_tree_path, sentences_market_path, tags_path, \ tags_martket_path, untag_sentence_path) : file_operator = TextFileOperator() loader = PickleMarket() sentences = loader.load_market(sentences_market_path) cmd_list = file_operator.reading(tag_tree_path) tag_tree = TagTree(cmd_list) robot = Robot() tags, tags_show, untag_sentences = robot.tag_sentences(tag_tree, sentences[0:]) loader = JsonMarket() self.write_tags(sentences, tags_show, tags_path) loader.dump_market(tags, tags_martket_path) file_operator.writing(untag_sentences, untag_sentence_path) # loader.dump_market(untag_sentences, sentences_market_path) # print '%.2f%% article >= 2 tags' % (100.0 * len([tag for tag in tags_show if len(tag) >= 1]) / len(sentences)) print '%.2f%% article >= 3 tags' % (100.0 * len([tag for tag in tags_show if len(tag) >= 1]) / len(sentences))