bot_2.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """
  2. # See: https://pythonhosted.org/chatbot/
  3. # See: https://www.codeproject.com/Articles/36106/Chatbot-Tutorial
  4. # See: https://www.smallsurething.com/implementing-the-famous-eliza-chatbot-in-python/
  5. """
  6. import logging
  7. from textblob import TextBlob
  8. from textblob_fr import PatternTagger, PatternAnalyzer
  9. logging.basicConfig()
  10. logger = logging.getLogger()
  11. logger.setLevel(logging.DEBUG)
  12. def answer_to(sentence):
  13. """Main program loop: select a response for the input sentence and return it"""
  14. logger.debug("> received: %s", sentence)
  15. blob = TextBlob(sentence, pos_tagger=PatternTagger(), analyzer=PatternAnalyzer())
  16. print("tags", blob.tags)
  17. print("phrases", blob.sentences)
  18. # print("mots", blob.words)
  19. # print("phrases nom.", blob.noun_phrases)
  20. print("mot 6:", blob.words[6])
  21. print("lemma:", blob.words[6].lemmatize())
  22. # print("pluriel:", blob.words[3].pluralize())
  23. print("mot 12:", blob.words[12])
  24. print("lemma:", blob.words[12].lemmatize())
  25. # print("singulier:", blob.words[12].singularize())
  26. if __name__ == '__main__':
  27. msg = ""
  28. answer_to("Ceci est une phrase de test. J'adore le film \"la soupe aux choux\"")
  29. # print("Oui monsieur?")
  30. # while msg != ".":
  31. # msg = input("> ")
  32. # print(answer_to(msg))
  33. # answer_to("This is a test sentence.")