Last active
June 25, 2019 04:22
-
-
Save krisgesling/56f0c8440dba2ae686349baba9486977 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sre_yield | |
from os.path import join | |
skill_path = '/opt/mycroft/skills/skill-date-time.ndato' | |
output_file = './tests_to_create.csv' | |
intent_handler = 'handle_query_current_time_adapt' | |
expected_dialog = "time.future" | |
offset = 8 | |
location = 'London' | |
### time.current | |
# input_strings = [ | |
# f"(do you know|(could you|) (tell|give) (me|)|(can you|) (check|(tell|give) (me|))|may i (ask|know)|) (what time (is it|it is) ((currently|(right|) now|) ((at|in|for) {location}|)|((at|in|for) {location}|) (currently|(right|) now|))|the (current|) time ((at|in|for) {location}|)) (|please)", | |
# f"(excuse me|) (what is|what\'s) the (current time ((at|in|for) {location}|) |time ((at|in|for) {location}|) (currently|(right|) now|)|time (currently|(right|) now|) ((at|in|for) {location}|)) (|please)", | |
# f"((do|can you|) check the|check|the|) clock (((at|in|for) {location}|) ((right|) now|)|((right|) now|) ((at|in|for) {location}|)|) (|please)" | |
# f"((check (the|)|(tell|give) (me|) the|)|the|) (time (((right|) now|) ((at|in|for) {location}|)|((at|in|for) {location}|) ((right|) now|)|)|current time ((at|in|for) {location}|)) (|please)" | |
# ] | |
### time.future | |
input_strings = [ | |
f"(in|) {offset} (hours|minutes|seconds) what (time will it be|will the time be) (from now|) ((at|in|for) {location}|)", | |
f"what (time will it be|will the time be) (in|) {offset} (hours|minutes|seconds) (from now|) ((at|in|for) {location}|)", | |
f"(do you know|may i (ask|know)|) when is it {offset} (hours|minutes|seconds) (from now|) ((at|in|for) {location}|)", | |
f"(do you know|may i (ask|know)|) (the|) time in {offset} (hours|minutes|seconds) (from now|) (|please) ((at|in|for) {location}|)" | |
] | |
def test_template(utt, handler): | |
return '\n'.join(['{', | |
f' "utterance": "{utt}",', | |
f' "expected_dialog": "time.future"', | |
'}']) | |
def expand_regex(regex): | |
result = list(sre_yield.AllStrings(regex)) | |
return result | |
all_strings = [] | |
[all_strings.extend(expand_regex(regex)) for regex in input_strings] | |
def write_to_csv(data, csv_file): | |
output = [] | |
for s in data: | |
output.append([s.strip(), intent_handler]) | |
## Preview output | |
print(output[0]) | |
## Write output to csv | |
with open(csv_file, 'w') as f: | |
writer = csv.writer(f, quoting=csv.QUOTE_ALL) | |
writer.writerows(output) | |
# write_to_csv(all_strings, output_file) | |
files_created = [] | |
def create_test(utt, handler): | |
test_file_name = ''.join( | |
x for x in utt if (x.isalnum() or x in '._-')) + '.intent.json' | |
test_path = f'{skill_path}/test/intent/{test_file_name}' | |
files_created.append(test_path) | |
with open(test_path, "w+") as test_file: | |
test_file.write(test_template(utt, handler)) | |
test_file.close() | |
print(f'Creating {len(all_strings)} tests') | |
for utt in all_strings: | |
create_test(utt, intent_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment