Skip to content

Commit e1129b9

Browse files
Add EACL poster
1 parent 680c751 commit e1129b9

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

eacl_poster.pdf

1.54 MB
Binary file not shown.

src/sdialog/datasets.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,26 @@ def read_graph(task_name, as_dot: bool = True):
4848
"""
4949
Read the action graph for a given task.
5050
51-
:param task_name: Name of the task (folder name under tasks/).
52-
:type task_name: str
51+
:param task_name: Name of the task (folder name under tasks/), or a pre-loaded
52+
JSON dict (as returned by the task's JSON file) to skip disk I/O.
53+
:type task_name: Union[str, dict]
5354
:param as_dot: If True, return a DOT string; else return the raw graph dict.
5455
:type as_dot: bool
5556
:return: Graph in DOT format or raw dictionary mapping edges.
5657
:rtype: Union[str, dict]
5758
"""
58-
with open(os.path.join(STAR._path, f"tasks/{task_name}/{task_name}.json")) as reader:
59-
if not as_dot:
60-
return json.load(reader)["graph"]
61-
dot_edges = ";\n".join(f" {a} -> {b}" for a, b in json.load(reader)["graph"].items())
59+
if isinstance(task_name, dict):
60+
data = task_name
61+
label = ""
62+
else:
63+
with open(os.path.join(STAR._path, f"tasks/{task_name}/{task_name}.json")) as reader:
64+
data = json.load(reader)
65+
label = task_name
6266

63-
return "digraph %s {\n%s\n}" % (task_name, dot_edges)
67+
if not as_dot:
68+
return data["graph"]
69+
dot_edges = ";\n".join(f" {a} -> {b}" for a, b in data["graph"].items())
70+
return "digraph %s {\n%s\n}" % (label, dot_edges)
6471

6572
@staticmethod
6673
def read_graph_responses(task_name, as_dict: bool = False):
@@ -69,19 +76,22 @@ def read_graph_responses(task_name, as_dict: bool = False):
6976
7077
Placeholders of the form {variable[:format]} are uppercased for visibility.
7178
72-
:param task_name: Name of the task.
73-
:type task_name: str
79+
:param task_name: Name of the task, or a pre-loaded responses dict to skip disk I/O.
80+
:type task_name: Union[str, dict]
7481
:param as_dict: If True, return a dict; otherwise a JSON-formatted string.
7582
:type as_dict: bool
7683
:return: Mapping node -> example response, or JSON dump.
7784
:rtype: Union[dict, str]
7885
"""
79-
with open(os.path.join(STAR._path, f"tasks/{task_name}/responses.json")) as reader:
80-
responses = json.load(reader)
81-
responses = {key: re.sub(r"{(.+?)(?::\w+?)?}", lambda m: m.group(1).upper(), value)
82-
for key, value in responses.items()
83-
if key != "out_of_scope"}
84-
return responses if as_dict else json.dumps(responses, indent=2)
86+
if isinstance(task_name, dict):
87+
raw = task_name
88+
else:
89+
with open(os.path.join(STAR._path, f"tasks/{task_name}/responses.json")) as reader:
90+
raw = json.load(reader)
91+
responses = {key: re.sub(r"{(.+?)(?::\w+?)?}", lambda m: m.group(1).upper(), value)
92+
for key, value in raw.items()
93+
if key != "out_of_scope"}
94+
return responses if as_dict else json.dumps(responses, indent=2)
8595

8696
@staticmethod
8797
def get_task_names():

0 commit comments

Comments
 (0)