Created
January 14, 2020 09:33
-
-
Save Mazyod/26c052391d487f768895d2144702cb33 to your computer and use it in GitHub Desktop.
Rasa NLU training data migrator from JSON format to Markdown
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
#!/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