Пример #1
0
def main():
    # Check if database with claims and counterarguments and bert embeddings already been created, otherwise create.
    if os.path.isfile('embeddings_df.pkl'):
        dataframe = pd.read_pickle('embeddings_df.pkl')
    else:
        if os.path.isfile('Pickles/Trolley.pkl'):
            dataframe = pd.read_pickle('Pickles/trolley.pkl')
        else:
            create_dataframe()
            dataframe = pd.read_pickle('Pickles/trolley.pkl')

        bert_encoding(dataframe)
        embeddings = pd.read_pickle('embeddings_df.pkl')
    if os.path.isfile('embeddings_df2.pkl'):
        dataframe2 = pd.read_pickle('embeddings_df2.pkl')
    else:
        dataframe2 = pd.read_pickle('sentiment_dataframe.pkl')
        claims = dataframe2['claim']
        word_tokens = []
        for c in claims:
            tokens = informative_words_list(c)
            word_tokens.append(tokens)
        dataframe2['word_tokens'] = word_tokens
        pd.to_pickle(dataframe2, 'embeddings_df2.pkl')

    print(dataframe2)

    # Start bot conversation...
    print('BOT: As a bot I am a terrible debater and always agree')

    exit_words = ['bye', 'fuckoff', 'quit', 'exit', 'cya', 'goodbye']

    while (True):
        user_input = input()
        user_input = user_input.lower()
        if user_input in exit_words:
            print('BOT: Good talk')
            break
        else:
            print('BOT: ' + counter_argument(user_input, dataframe2))
Пример #2
0
def main():
    check_folders()
    # Check if database with claims and counterarguments and bert embeddings already been created, otherwise create.
    if os.path.isfile('Pickles/Trolley.pkl'):
        dataframe = pd.read_pickle('Pickles/trolley.pkl')
    else:
        create_dataframe()
        dataframe = pd.read_pickle('Pickles/trolley.pkl')

    # Start bot conversation...
    print('BOT: As a bot I am a terrible debater and always agree')

    exit_words = ['bye', 'fuckoff', 'quit', 'exit', 'cya', 'goodbye']

    while True:
        user_input = input()
        user_input = user_input.lower()
        if user_input in exit_words:
            print('BOT: Good talk')
            break
        else:
            response = counter_argument(user_input, dataframe)
            print('BOT: ' + response[1] + '\n' + response[0])
Пример #3
0
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        # Create widgets
        self.entry_label = tk.Label(text="Name of file to load:")
        self.entry_filename = tk.Entry(
            text="trolley")  # TODO change to drop-down list
        self.entry_load = tk.Button(text="Load file", command=self.start)

        self.textCons = tk.Text(width=20,
                                height=8,
                                bg="#17202A",
                                fg="#EAECEE",
                                font="Helvetica 14",
                                padx=5,
                                pady=5)
        self.labelBottom = tk.Label(bg="#ABB2B9", height=10)
        self.entryMsg = tk.Entry(bg="#2C3E50",
                                 fg="#EAECEE",
                                 font="Helvetica 13")
        self.buttonMsg = tk.Button(text="Send",
                                   font="Helvetica 10 bold",
                                   width=20,
                                   bg="#ABB2B9",
                                   command=self.send_to_bot)
        self.scrollbar = tk.Scrollbar(command=self.textCons.yview)

        # lay the widgets out on the screen.
        self.entry_label.place(relx=0, rely=0.025)
        self.entry_filename.place(relx=0.4, rely=0.025)
        self.entry_load.place(relx=0.8, rely=0.025)

        self.textCons.place(relwidth=0.95, relheight=0.73, rely=0.1)
        self.labelBottom.place(relwidth=1, rely=0.825)
        self.entryMsg.place(relwidth=0.8, relx=0.025, rely=0.9)
        self.buttonMsg.place(relwidth=0.1, relx=0.865, rely=0.9)
        # self.scrollbar.place(relheight=1, relx=0.974)
        self.scrollbar.place(relheight=0.73, relx=0.955, rely=0.1)

        self.scrollbar.config(command=self.textCons.yview)
        self.textCons.config(cursor="arrow")
        self.textCons.config(state=tk.DISABLED)

        self.exit_words = ['bye', 'fuckoff', 'quit', 'exit', 'cya', 'goodbye']
        self.load_config()

        self.check_folders()
        if os.path.isfile('embeddings_df.pkl'):
            self.dataframe = pd.read_pickle('embeddings_df.pkl')
        else:
            if os.path.isfile('Pickles/Trolley.pkl'):
                self.dataframe = pd.read_pickle('Pickles/trolley.pkl')
            else:
                counterargument_db.create_dataframe()
                self.dataframe = pd.read_pickle('Pickles/trolley.pkl')

            bert_encoding(self.dataframe)
            embeddings = pd.read_pickle('embeddings_df.pkl')

        if os.path.isfile('embeddings_df2.pkl'):
            self.dataframe2 = pd.read_pickle('embeddings_df2.pkl')
        else:
            self.dataframe2 = pd.read_pickle('sentiment_dataframe.pkl')
            claims = self.dataframe2['claim']
            word_tokens = []
            for c in claims:
                tokens = informative_words_list(c)
                word_tokens.append(tokens)
            self.dataframe2['word_tokens'] = word_tokens
            pd.to_pickle(self.dataframe2, 'embeddings_df2.pkl')
        self.tb = sentiment_model()
        self.queue = None

        # Redirect print:
        bot_response.print = self.write

        # Bind Return to send messages
        # self.bind('<Return>', self.send_to_bot_event)

        # Start bot conversation...
        self.write('BOT: As a bot I am a terrible debater and always agree')
input_file = "rewritten_arguments.txt"
print_in_out = True
number_of_lines_to_check = 199
bot_response.print = write_nothing

f = open('test_arg.txt', 'r')
inputs = f.read().splitlines()

outputs = []
wrongs = []

check_folders()
if os.path.isfile('Pickles/Trolley.pkl'):
    dataframe = pd.read_pickle('Pickles/trolley.pkl')
else:
    create_dataframe()
    dataframe = pd.read_pickle('Pickles/trolley.pkl')
tb = sentiment_model()

for i in range(min(number_of_lines_to_check, len(inputs))):
    outputs.append(
        bot_response.counter_argument_testing(inputs[i], dataframe, tb))
    if print_in_out:
        print(f'In: {inputs[i].rstrip()}')
        print(f'Out: {dataframe["claim"].iloc[outputs[i]]}\n')
    if i != outputs[i]:
        wrongs.append(i)

print(f"Wrong indexes: {wrongs}")