Skip to content

Commit 2a309e5

Browse files
author
Johannes Hötter
committed
adds basic rasa adapter
1 parent 1c0a65d commit 2a309e5

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
data/
12
.vscode/
23
secrets.json
34

kern/adapter/__init__.py

Whitespace-only changes.

kern/adapter/rasa.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import yaml
2+
import os
3+
from collections import OrderedDict
4+
5+
6+
class literal(str):
7+
pass
8+
9+
10+
def literal_presenter(dumper, data):
11+
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
12+
13+
14+
yaml.add_representer(literal, literal_presenter)
15+
16+
17+
def ordered_dict_presenter(dumper, data):
18+
return dumper.represent_dict(data.items())
19+
20+
21+
yaml.add_representer(OrderedDict, ordered_dict_presenter)
22+
23+
24+
def build_literal_from_iterable(iterable):
25+
return "\n".join([f"- {value}" for value in iterable]) + "\n"
26+
27+
28+
def build_intent_yaml(
29+
client, input_name, label_name, dir_name="data", file_name="nlu.yml"
30+
):
31+
df = client.get_record_export(tokenize=False)
32+
33+
nlu_list = []
34+
for label, df_label in df.groupby(label_name):
35+
literal_string = build_literal_from_iterable(df_label[input_name].tolist())
36+
nlu_list.append(OrderedDict(intent=label, examples=literal(literal_string)))
37+
nlu_dict = OrderedDict(nlu=nlu_list)
38+
39+
if dir_name is not None and not os.path.isdir(dir_name):
40+
os.mkdir(dir_name)
41+
42+
file_path = os.path.join(dir_name, file_name)
43+
44+
with open(file_path, "w") as f:
45+
yaml.dump(nlu_dict, f, allow_unicode=True)

requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ backcall==0.2.0
77
beautifulsoup4==4.11.1
88
black==22.3.0
99
bleach==5.0.0
10+
boto3==1.23.1
11+
botocore==1.26.1
1012
certifi==2021.10.8
1113
cffi==1.15.0
1214
charset-normalizer==2.0.12
@@ -24,14 +26,14 @@ ipython-genutils==0.2.0
2426
ipywidgets==7.7.0
2527
jedi==0.18.1
2628
Jinja2==3.1.2
29+
jmespath==1.0.0
2730
jsonschema==4.5.1
2831
jupyter==1.0.0
2932
jupyter-client==7.3.1
3033
jupyter-console==6.4.3
3134
jupyter-core==4.10.0
3235
jupyterlab-pygments==0.2.2
3336
jupyterlab-widgets==1.1.0
34-
kern-python-client @ file:///Users/jhoetter/repos/kern-python
3537
MarkupSafe==2.1.1
3638
matplotlib-inline==0.1.3
3739
minio==7.1.8
@@ -62,10 +64,12 @@ pyparsing==3.0.9
6264
pyrsistent==0.18.1
6365
python-dateutil==2.8.2
6466
pytz==2022.1
67+
PyYAML==6.0
6568
pyzmq==22.3.0
6669
qtconsole==5.3.0
6770
QtPy==2.1.0
6871
requests==2.27.1
72+
s3transfer==0.5.2
6973
Send2Trash==1.8.0
7074
six==1.16.0
7175
soupsieve==2.3.2.post1

0 commit comments

Comments
 (0)