def respond(message):
    if not is_valid_for_checking(message):
        return chitchat.respond(message)

    language = i18n.detect(message)
    if is_link(message):
        try:
            response = requests.get("https://api.fakenewsdetector.org/votes",
                                    params={
                                        'url': message,
                                        'title': ''
                                    },
                                    timeout=10)
            response = json.loads(response.text)
            predicted = response['robot']
            keywords = response['keywords']
            language = i18n.detect(" ".join(keywords))
        except Exception as err:
            print("Error", err)
            return i18n.translate(language, "SORRY_ERROR")
    else:
        predicted = robinho.predict("", message, "")
        keywords = robinho.find_keywords("", message, "")

    if len(keywords) >= 3:
        google_search = ("\n\n" + i18n.translate(language, "SEARCH_YOURSELF") +
                         "https://www.google.com/search?" +
                         urlencode({"q": " ".join(keywords)}))
    else:
        google_search = ""
    return respond_text_prediction(language, predicted) + google_search
Exemplo n.º 2
0
def respond(message):
    response = chatbot.get_response(message)
    if response.confidence < 0.60:
        language = i18n.detect(message)
        return i18n.translate(language, "COULD_NOT_UNDERSTAND")

    return response.text
Exemplo n.º 3
0
 def test_detects_language_as_english_when_cannot_tell(self):
     self.assertEqual('en', detect('11111'))
Exemplo n.º 4
0
 def test_detects_language(self):
     self.assertEqual('es', detect('Una prueba más'))