test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # coding: utf8
  2. import logging
  3. import re
  4. from collections import Counter
  5. from core import OrderAnalyser
  6. logging.basicConfig()
  7. logger = logging.getLogger("jarvis")
  8. logger.setLevel(logging.DEBUG)
  9. # This does not work because of different encoding when using accent
  10. from core import OrderAnalyser
  11. order = "jarvis régle le réveil pour sept heures et vingt minutes"
  12. oa = OrderAnalyser(order)
  13. oa.start()
  14. # user_said = "jarvis régle le réveil pour sept heures et pour vingts minutes"
  15. #
  16. # order = "régle le réveil pour {{ hour }} heures et pour {{ minute }} minutes"
  17. #
  18. #
  19. # def counterSubset(list1, list2):
  20. # """
  21. # check if the number of occurrences matches
  22. # :param list1:
  23. # :param list2:
  24. # :return:
  25. # """
  26. # c1, c2 = Counter(list1), Counter(list2)
  27. # for k, n in c1.items():
  28. # if n > c2[k]:
  29. # return False
  30. # return True
  31. #
  32. #
  33. # def _spelt_order_match_brain_order_via_table(order_to_analyse, user_said):
  34. # list_word_user_said = user_said.split()
  35. # split_order_without_bracket = _get_list_word_without_bracket(order_to_analyse)
  36. #
  37. # number_of_word_in_order = len(split_order_without_bracket)
  38. # # if all words in the list of what the user said in in the list of word in the order
  39. # # return len(set(split_order_without_bracket).intersection(list_word_user_said)) == number_of_word_in_order
  40. # return counterSubset(split_order_without_bracket, list_word_user_said)
  41. #
  42. #
  43. # def _get_list_word_without_bracket(order):
  44. # """
  45. # Get an order with bracket inside like: "hello my name is {{ name }}.
  46. # return a list of string without bracket like ["hello", "my", "name", "is"]
  47. # :param order: sentence to split
  48. # :return: list of string without bracket
  49. # """
  50. # pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
  51. # # find everything like {{ word }}
  52. # matches = re.findall(pattern, order)
  53. # for match in matches:
  54. # order = order.replace(match, "")
  55. # # then split
  56. # split_order = order.split()
  57. # return split_order
  58. #
  59. # # main test
  60. # if _spelt_order_match_brain_order_via_table(order, user_said):
  61. # print "order matched"
  62. # else:
  63. # print "order does not match"