Пример #1
0
              preprocessors=[
                  "chatterbot.preprocessors.clean_whitespace",
                  "chatterbot.preprocessors.unescape_html",
                  "chatterbot.preprocessors.convert_to_ascii"
              ],
              logic_adapters=[{
                  'import_path': 'chatterbot.logic.BestMatch',
                  'default_response': 'I am sorry, but I do not understand.',
                  'maximum_similarity_threshold': 0.90
              }, {
                  'import_path':
                  'chatterbot.logic.MathematicalEvaluation',
              }])

trainer = ListTrainer(bot)  # set the trainer
trainer.export_for_training('./my_export.json')


def speak(word):
    engine.say(word)
    engine.runAndWait()


def Find(query):
    # findall() has been used
    # with valid conditions for urls in string
    url = re.findall(
        'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
        query)
    return url
Пример #2
0
     "We don't have a phone number for this type of account"),
    ("mailing address",
     "You can email our corporate headquaters at [email protected] "),
    ("chatterbot",
     "library making it easy to generate automated responses to a user’s input, visit https://chatterbot.readthedocs.io/en/stable/"
     ),
    ("textblob",
     "library for processing textual data, please visit https://textblob.readthedocs.io/en/dev/"
     )
]

classifier = [
    "silly", "dumb", "stupid", "I'dont think so", "I don't care",
    "do you know anything", "not good", "omg", "this is not working"
    "this is bad", "not what I want", "live help", "get me a rep",
    "I need a real person", "forget you"
]

for topic, link in documentation_topics:
    trainer.train([f"{topic}", f"Sure, here is the {topic} link: {link}"])

for topic, description in twilio_knowledge:
    trainer.train([f"{topic}", f"Ok sure, {description}"])

for i in classifier:
    trainer.train([
        f"{i}", "I am sorry you feel that way, please ask the question again"
    ])

trainer.export_for_training('twilybot.json')
Пример #3
0
    database_uri='sqlite:///database.sqlite3')

# For training
trainer = ListTrainer(chatbot)

"""
# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)

#Train the chatbot based on the english corpus only is necessary one time.
trainer.train("chatterbot.corpus.english")
"""
# Select the language (download previously)(sm = small)
nlp = spacy.load("en_core_web_sm")

"""
# We can export the data to a file json
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.export_for_training("./bot_mongo.json")
"""

def speak ():
    response = chatbot.get_response(user)
    print("BOT: "+str(response))
    return response


# With this function we can search in the memory of the bot for check for example the fever of the user.
"""
def reg (txto):
    patron = "\d{2}[\.\d]*"
Пример #4
0
class Bot:
    def __init__(self, name, acurrency):
        self.name = name
        self.acurrency = acurrency
        self.bot = ChatBot(name)
        # Salva as perguntas e respostas do usuário
        self.fulltext = 'Você gosta de cozinhar?'

    # Faz o treino em array
    def training_array(self, speaking):
        self.trainer = ListTrainer(self.bot)
        self.trainer.train(speaking)

    # Faz o treino em csv
    def training_csv(self, path):
        csv = CsvFactory(path)
        list = csv.to_array()

        self.trainer = ListTrainer(self.bot)
        self.trainer.train(list)

    # Exporta o treino do banco de dados
    def export_train(self):
        self.trainer.export_for_training('./my_export.json')

    def add_model(self, path, rows):
        csv = CsvFactory(path)
        csv.write(rows)

    #### Acuracia Naive Bayes #####
    def get_accuracy(self, path):
        dataset = pd.read_csv(path, sep=';', encoding="ISO-8859-1")

        token = RegexpTokenizer(r'[a-zA-Z0-9]+')
        cv = CountVectorizer(analyzer='word',
                             lowercase=True,
                             stop_words='english',
                             min_df=1,
                             ngram_range=(1, 1),
                             tokenizer=token.tokenize)
        text_counts = cv.fit_transform(dataset['Text'])

        # Aqui começa o treinamento
        y = dataset['Sentiment']
        X = text_counts

        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.3,
                                                            random_state=10)

        NaiveB = MultinomialNB()
        NaiveB.fit(X_train, y_train)

        y_pred_test_NaiveB = NaiveB.predict(X_test)

        #retorno
        print('Acurácia NaiveBayes:',
              metrics.accuracy_score(y_test, y_pred_test_NaiveB))

    # Resposta do robo
    def response(self, question):
        answer = self.bot.get_response(question)
        text = 'Eita, não entendi.'

        if float(answer.confidence) > self.acurrency:
            # acumulador para salvar no futuro modelo
            self.fulltext += ' ' + question + ' ' + str(answer)
            text = str(answer)

        return text
Пример #5
0
        if (joke['rating'] > 3 and len(joke['body']) < 70
                and joke['category'] != 'Blonde Jokes'):
            chosenJokes.append("Tell me a joke")
            chosenJokes.append(joke['body'])

        count += 1

# with open('wocka.json', encoding="utf-8") as json_file:
#     data = json.load(json_file)
#     for joke in data:
#         if (len(joke['body']) < 70 and not ('Blond' in joke['category']) ):
#             chosenJokes.append( re.sub(r'[^\x00-\x7F]+',' ', joke['body'].replace('\r', "").replace('\n', "")))

#         count+=1

trainer.train(chosenJokes)
trainer.export_for_training('./full_list_trainer.json')

# # The following loop will execute each time the user enters input
# while True:
#     try:
#         user_input = input(">> ")

#         bot_response = chatbot.get_response(user_input)

#         print(bot_response)

#     # Press ctrl-c or ctrl-d on the keyboard to exit
#     except (KeyboardInterrupt, EOFError, SystemExit):
#         break
Пример #6
0
        }
    ],
    database_uri='sqlite:///database-chatbot.db' #use sqlite
    #database_uri = "postgresql://*****:*****@localhost/rus_bot"  #use postgres
)

# Create a new trainer for the chatbot, using corpus trainer - uncomment, if demand
trainer = ListTrainer(bot)

# Train the chatbot based on the english corpus - uncomment, if demand
#trainer.train("chatterbot.corpus.english")

#print('Type something to begin...')
for dialog in train_corpus_full:
    trainer.train(dialog)
trainer.export_for_training('./attempt1.json')


# if __name__ =='__main__':
#     # The following loop will execute each time the user enters input
#     trainer.train(train_corpus_full)
#     while True:
#         try:
#             user_input = input()

#             bot_response = bot.get_response(user_input)

#             print(bot_response)

#         # Press ctrl-c or ctrl-d on the keyboard to exit
#         except (KeyboardInterrupt, EOFError, SystemExit):
Пример #7
0
    "isis", "taliban", "cp", "bomb", "ied", "explosive"
]  #more bad words to limit searches, cos I really don't trust people
f = open(f"{filepath}/config/token.txt")
token = str(
    f.readline()
)  #Gets the token from another text file so I don't have to leave the token in this file where anyone can read it
f.close()
null = None  #so I can write "null" instead of "None" and look like hackerman

#Chatterbot stuff

chatbot = ChatBot('Bottombot')

trainer = ListTrainer(chatbot)

trainer.export_for_training(
    f'{filepath}/my_export.json')  #exporting the saved training data

trainer.train([
    "UwU"  #It starts with one word. I chose this
])
#Chatterbot stuff

client = discord.Client()

client = commands.Bot(command_prefix="-")

client.remove_command('help')
starttime = null

bannedids = [
    369234715015905292, 567522840752947210, 459685744387162112,