Rasa NLU training data migrator from JSON format to Markdown
#!/usr/local/bin/python3 | |
import json | |
from pprint import pprint | |
from collections import defaultdict | |
from pathlib import Path | |
def main(): | |
path = Path("./data.json").resolve() | |
print(path) | |
with path.open() as f: | |
content = json.load(f) | |
lookup = { | |
"intents": defaultdict(list), | |
"synonyms": defaultdict(list) | |
} | |
content = content['rasa_nlu_data']['common_examples'] | |
for item in content: | |
intent = item['intent'] | |
text = item['text'] | |
for entity in reversed(item['entities']): | |
text = text.replace(entity['value'], f"[{entity['value']}]({entity['entity']})") | |
lookup['intents'][intent].append(text) | |
for intent, words in lookup['intents'].items(): | |
print(f"## intent:{intent}") | |
[print(f"- {text}") for text in words] | |
print("") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment