def find_the_most_suitable_answer(keywords):
    dao = Dao()
    answers = dao.get_dictionary()
    # print(answers)
    value_list = {}
    i = 0
    while i < 500:
        value_list[i] = 0.0
        i += 1

    '''for keyword in keywords:
        #print(keyword)
        for answer in answers:
            #print(answer)
            if answers[answer].count(keyword) == 1:
                value_list[answer] += 1'''

    # print(keyword)
    for answer in answers:
        for keyword in keywords:
            # print(answer)
            if answers[answer].count(keyword) == 1:
                value_list[answer] += 1
        if len(answers[answer]) != 0:
            # print("Sss" + str(value_list[answer]) + str(len(answers[answer]) * 1.0))
            value_list[answer] = value_list[answer] / (len(answers[answer]) * 1.0)
            # print(value_list[answer])
        # print(dao.execute("select `text` from hack.`key` where `answer_id` = " + str(answer)))

    return sorted(value_list.items(), key=operator.itemgetter(1))[len(value_list) - 1][0]
Пример #2
0
    def render(self, screen):
        # if it's not sticky, e.g. we're not on the latest and greatest, and the user is scrolling...
        if not self.start_sticky:
            # pull from db if we don't have enough records to display without crashing
            end = min(len(self.display_stamps), self.element_count + 1)
            if len(self.display_stamps) < end + self.scroll_offset + 1:
                # pull records
                d = Dao()
                timestamps = d.get_n_timestamp_records_starting_from(
                    self.total_stamps, interval=self.DB_PULL_INTERVAL)
                self.total_stamps += self.DB_PULL_INTERVAL
                stamps: List[Stamp] = []
                # convert into stamps
                for timestamp in timestamps:
                    if timestamp.ms <= 0:
                        self.dead_counter += 1
                    stamps.append(
                        Stamp(timestamp.receiver_readable,
                              timestamp.ms,
                              offset=self.label_offset_y))
                self.display_stamps.extend(stamps)

                # if we still don't have enough records, remove the last step the user did...
                if len(self.display_stamps) < end + self.scroll_offset + 1:
                    if self.scroll_offset > self.STEP_UP:
                        self.scroll_offset -= self.STEP_UP
                    else:
                        self.scroll_offset = 0

        self.draw_axes(screen)
        self.draw_misc(screen)
        self.draw_stamps(screen, self.GREEN, self.MARINE)
def add_to_bd_type_two(filename, lines_count, start_id):
    try:
        row = start_id
        dao = Dao(True)
        file = open(filename, 'r', encoding="UTF-8")
        for i in range(0, lines_count, 3):
            keys = file.readline()
            answer = file.readline()
            nothing = file.readline()

            lst = tokenizer.tokenize_ru(keys)
            keywords = []
            for word in lst:
                checked = spellchecker.correct(word)
                # stemmed = stemmer.stem(word)
                lemma = pymorphy2.MorphAnalyzer().parse(checked)[0].normal_form
                keywords.append(lemma)

            for keyword in keywords:
                sql = "insert into hack.`key`(text, answer_id) values ('" + keyword + "', " + str(
                    row) + ");"
                dao.execute(sql)
            sql = "insert into answer(id, text) values (" + str(
                row) + ", '" + answer + "')"
            dao.execute(sql)

            row += 1
    finally:
        file.close()
Пример #4
0
    def __init__(self, src_addr: str):
        with open("servers.json", 'r', encoding="utf-8") as file:
            data: List[List[str], List[str]] = load(file)

        self.servers: List = data[0]
        self.servers_readable: List = data[1]
        self.local_history = []

        self.db = Dao()
        self.interface = src_addr

        for _ in self.servers:
            self.local_history.append(0)

        if len(self.servers) != len(self.servers_readable):
            raise ServerHostNameMismatchException()
from db.dao import Dao

dao = Dao()

print(dao.execute("select * from hack.`answer`;"))
Пример #6
0
def get_user_response(msg):
    message = str(msg)
    dao = Dao()
    num = bot.get_response(message)
    print(dao.get_answer(num)[0])
    return dao.get_answer(num)[0]
Пример #7
0
    handler.parse_sys_args(argv)
    handler.post_processing(Sniffer.get_interface_list(), Sniffer.get_interface_ip_list())

    # if we encounter any exceptions, bail
    if handler.exceptions:
        for e in handler.exceptions:
            print(e.__str__() + "\n")
        exit(0)

    any_special_flag = handler.RECORDS_FLAG or handler.PICKLE_FOUND or handler.SAVE_FOUND
    any_output_flag = handler.PICKLE_FOUND or handler.SAVE_FOUND

    if handler.RECORDS_FLAG:
        # if we found records flag, for each MM/DD/HH/MM/SS (depending on if YYYY/MM/DD/HH/MM was given),
        # print number of unique records and then exit
        tsc, pkc = get_record_count(Dao(), handler.RECORDS_DATE, handler.RECORDS_TYPE)
        print(f"Found {tsc} timestamps and {pkc} sniff records in the given date.")

    if any_output_flag:
        generator = Generator()

    if handler.PICKLE_FOUND:
        # if cmd handler found any pickles as an arg, open
        # noinspection PyUnboundLocalVariable
        generator.open_saved_pickles(handler.pickles)

    if handler.SAVE_FOUND:
        # do stuff for output here
        # noinspection PyUnboundLocalVariable
        generator.start_new_pass(handler.OUTPUT_PATH, handler.ANON_FLAG)
        d = Dao()