Beispiel #1
0
    def __inner_job(index=choice):
        start = time.time()
        
        text_binary = analyze_current_screen_text(
            directory=data_directory,
            compress_level=image_compress_level[1],
            index=choice
        )
        keywords = get_text_from_image(
            image_data=text_binary,
        )
        ##print('中国',keywords)
        if not keywords:
            print("failed")
            return
        ##true_flag,问题是否为正向问题,选择错误项的问题为反向问题
        true_flag, question, answers = parse_question_and_answer(keywords)
        
        print('\n',question)
    

        # notice browser
        if enable_chrome:
            with question_obj.get_lock():
                question_obj.value = question
                keyboard.press("space")

        search_question = pre_process_question(question)
        summary = baidu_count(search_question, answers, timeout=timeout)
        summary_li = sorted(summary.items(), key=operator.itemgetter(1), reverse=True)
        data = [("选项", "相关度")]
        for a, w in summary_li:
            data.append((a, w))
        table = AsciiTable(data)
        print(table.table)

        print("*" * 36)
        if true_flag:
            print("肯定回答(**): ", summary_li[0][0])
            print("否定回答(  ): ", summary_li[-1][0])
        else:
            print("肯定回答(  ): ", summary_li[0][0])
            print("否定回答(**): ", summary_li[-1][0])
        print("*" * 36)

        end = time.time()
        print("use {0} 秒".format(end - start))
        save_screen(
            directory=data_directory
        )
Beispiel #2
0
    def __inner_job():
        start = time.time()
        text_binary = analyze_current_screen_text(
            directory=data_directory,
            compress_level=image_compress_level[0]
        )
        keywords = get_text_from_image(
            image_data=text_binary,
        )
        if not keywords:
            print("text not recognize")
            return

        true_flag, question, answers = parse_question_and_answer(keywords)
        print('-' * 72)
        print(question)
        print('-' * 72)
        print("\n".join(answers))

        # notice browser
        if enable_chrome:
            with question_obj.get_lock():
                question_obj.value = question
                keyboard.press("space")

        search_question = pre_process_question(question)
        summary = baidu_count(search_question, answers, timeout=timeout)
        summary_li = sorted(summary.items(), key=operator.itemgetter(1), reverse=True)
        data = [("选项", "同比")]
        for a, w in summary_li:
            data.append((a, w))
        table = AsciiTable(data)
        print(table.table)

        print("*" * 72)
        if true_flag:
            print("肯定回答(**): ", summary_li[0][0])
            print("否定回答(  ): ", summary_li[-1][0])
        else:
            print("肯定回答(  ): ", summary_li[0][0])
            print("否定回答(**): ", summary_li[-1][0])
        print("*" * 72)

        end = time.time()
        print("use {0} 秒".format(end - start))
        save_screen(
            directory=data_directory
        )
 def run(self):
     if self.engine == 'baidu':
         self.result = baidu_count(self.question,
                                   self.answer,
                                   delword=self.delword,
                                   timeout=self.timeout,
                                   numofquery=self.numofquery)
     elif self.engine == 'baiduqmi':
         self.result = baidu_qmi_count(self.question,
                                       self.answer,
                                       delword=self.delword,
                                       timeout=self.timeout,
                                       numofquery=self.numofquery)
     elif self.engine == 'bing':
         self.result = bing_count(self.question,
                                  self.answer,
                                  delword=self.delword,
                                  timeout=self.timeout)
     elif self.engine == 'zhidao':
         self.result = zhidao_count(self.question,
                                    self.answer,
                                    delword=self.delword,
                                    timeout=self.timeout)
     elif self.engine == 'so':
         self.result = so_count(self.question,
                                self.answer,
                                delword=self.delword,
                                timeout=self.timeout)
     elif self.engine == 'zhidaotree':
         self.result = zhidao_tree(self.question,
                                   self.answer,
                                   timeout=self.timeout)
     elif self.engine == 'speaker':
         speakword(self.answer)
     else:
         self.result = zhidao_count(self.question,
                                    self.answer,
                                    delword=self.delword,
                                    timeout=self.timeout)
Beispiel #4
0
def __inner_job(title, answers):
    start = time.time()

    true_flag, real_question, question, answers = parse_question_and_answer(
        title, answers)
    print('-' * 72)
    print(real_question)
    print('-' * 72)
    print("\n".join(answers))

    # notice browser
    if enable_chrome:
        writer.send(question)
        noticer.set()

    search_question = pre_process_question(question)
    summary = baidu_count(search_question, answers, timeout=timeout)
    summary_li = sorted(summary.items(),
                        key=operator.itemgetter(1),
                        reverse=True)
    data = [("选项", "同比")]
    for a, w in summary_li:
        data.append((a, w))
    table = AsciiTable(data)
    print(table.table)

    print("*" * 72)
    if true_flag:
        print "肯定回答(**):%s" % summary_li[0][0]
        print "否定回答(  ):%s " % summary_li[-1][0]
    else:
        print "肯定回答(  ): %s" % summary_li[0][0]
        print "否定回答(**): %s" % summary_li[-1][0]

    print("*" * 72)
    end = time.time()
    print("use {0} 秒".format(end - start))
Beispiel #5
0
    def __inner_job():
        start = time.time()
        text_binary = analyze_current_screen_text(
            directory=data_directory, compress_level=image_compress_level[0])

        keywords = get_text_from_image(image_data=text_binary, )
        if not keywords:
            print("text not recognize")
            return

        true_flag, question, answers = parse_question_and_answer(keywords)
        #questions=question.decode('unicode-escape')
        #new_ans=[]
        #for ans in answers:
        # new_ans.append(ans.decode('unicode-escape'))

        print('-' * 72)
        print(question)
        print('-' * 72)
        print("\n".join(answers))

        # notice browser
        if enable_chrome:
            with question_obj.get_lock():
                question_obj.value = question
                keyboard.press("space")

        search_question = pre_process_question(question)
        summary = baidu_count(search_question, answers, timeout=timeout)
        summary_li = sorted(summary.items(),
                            key=operator.itemgetter(1),
                            reverse=True)
        data = [("选项", "同比")]
        for a, w in summary_li:
            data.append((a, w))
        table = AsciiTable(data)
        print(table.table)

        print("*" * 72)
        if true_flag:
            print("肯定回答(**): ", summary_li[0][0])
            print("否定回答(  ): ", summary_li[-1][0])
        else:
            print("肯定回答(  ): ", summary_li[0][0])
            print("否定回答(**): ", summary_li[-1][0])
        print("*" * 72)

        ##############################################################
        input_message = question

        if len(input_message) > 60:
            print(mybot.respond("句子长度过长"))
        elif input_message.strip() == '':
            print(mybot.respond("无"))

        #print(input_message)
        message = T.wordSegment(input_message)
        # 去标点
        #print('word Seg:' + message)
        #print('词性:')
        words = T.postag(input_message)

        if message == 'q':
            exit()
        else:
            response = mybot.respond(message)

            #print("=======")
            #print(response)
            #print("=======")

            if response == "":
                ans = mybot.respond('找不到答案')
                print('Eric:' + ans)
            # 百科搜索
            elif response[0] == '#':
                # 匹配百科
                if response.__contains__("searchbaike"):
                    #print("searchbaike")
                    #print(response)
                    res = response.split(':')
                    # 实体
                    entity = str(res[1]).replace(" ", "")
                    # 属性
                    attr = str(res[2]).replace(" ", "")
                    #print(entity + '<---->' + attr)

                    ans = baike.query(entity, attr)
                    # 如果命中答案
                    if type(ans) == list:
                        print('Eric:' + QAT.ptranswer(ans, False))

                    elif ans.decode('utf-8').__contains__(u'::找不到'):
                        # 百度摘要+Bing摘要
                        print("通用搜索")
                        ans = search_summary.kwquery(input_message)

                # 匹配不到模版,通用查询
                elif response.__contains__("NoMatchingTemplate"):
                    #print("NoMatchingTemplate")
                    ans = search_summary.kwquery(input_message, answers)

                if len(ans) == 0:
                    print('Eric:' + '找不到答案')
                elif len(ans) > 1:
                    print("不确定候选答案")
                    print('Eric: ')
                    for a in ans:
                        print(a)
                else:
                    print('Eric:' + ans[0])

            # 匹配模版
            else:
                print('Eric:' + response)

        end = time.time()
        print("use {0} 秒".format(end - start))
        save_screen(directory=data_directory)