test.py 2.3 KB

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