test.py 2.2 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. # order = order.decode('utf-8')
  13. # print type(order)
  14. oa = OrderAnalyser(order)
  15. oa.start()
  16. # user_said = "jarvis régle le réveil pour sept heures et pour vingts minutes"
  17. #
  18. # order = "régle le réveil pour {{ hour }} heures et pour {{ minute }} minutes"
  19. #
  20. #
  21. # def counterSubset(list1, list2):
  22. # """
  23. # check if the number of occurrences matches
  24. # :param list1:
  25. # :param list2:
  26. # :return:
  27. # """
  28. # c1, c2 = Counter(list1), Counter(list2)
  29. # for k, n in c1.items():
  30. # if n > c2[k]:
  31. # return False
  32. # return True
  33. #
  34. #
  35. # def _spelt_order_match_brain_order_via_table(order_to_analyse, user_said):
  36. # list_word_user_said = user_said.split()
  37. # split_order_without_bracket = _get_list_word_without_bracket(order_to_analyse)
  38. #
  39. # number_of_word_in_order = len(split_order_without_bracket)
  40. # # if all words in the list of what the user said in in the list of word in the order
  41. # # return len(set(split_order_without_bracket).intersection(list_word_user_said)) == number_of_word_in_order
  42. # return counterSubset(split_order_without_bracket, list_word_user_said)
  43. #
  44. #
  45. # def _get_list_word_without_bracket(order):
  46. # """
  47. # Get an order with bracket inside like: "hello my name is {{ name }}.
  48. # return a list of string without bracket like ["hello", "my", "name", "is"]
  49. # :param order: sentence to split
  50. # :return: list of string without bracket
  51. # """
  52. # pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
  53. # # find everything like {{ word }}
  54. # matches = re.findall(pattern, order)
  55. # for match in matches:
  56. # order = order.replace(match, "")
  57. # # then split
  58. # split_order = order.split()
  59. # return split_order
  60. #
  61. # # main test
  62. # if _spelt_order_match_brain_order_via_table(order, user_said):
  63. # print "order matched"
  64. # else:
  65. # print "order does not match"