Skip to content

fix: parse intent in action condition #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions assistant_skill_analysis/utils/skills_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def retrieve_workspace(skill_id, conversation, export_flag=True):
return ws_json.get_result()


def _get_intent_name_from_action_condition(condition: dict):
if "intent" in condition and condition["intent"] is not None:
return condition["intent"]
for v in condition.values():
if isinstance(v, list):
for cond in v:
return _get_intent_name_from_action_condition(cond)


def parse_workspace_json(workspace_json):
"""
Parse workspace json and returns list of utterances, list of intents, and list of entities, and intent to action title mapping
Expand All @@ -202,13 +211,17 @@ def parse_workspace_json(workspace_json):

else:
# intent name to action title mapping for readability
raw_intent_name_to_action_title_mapping = {
action["condition"]["intent"]: action["title"]
for action in workspace_json["workspace"]["actions"]
if action.get("condition", {}).get("intent")
}
raw_intent_name_to_action_title_mapping = {}
for action in workspace_json["workspace"]["actions"]:
possible_intent = _get_intent_name_from_action_condition(action.get("condition", {}))
if possible_intent:
raw_intent_name_to_action_title_mapping[possible_intent] = action["title"]
for intent in workspace_json["workspace"]["intents"]:
action_title = raw_intent_name_to_action_title_mapping[intent["intent"]]
intent_name = intent["intent"]
action_title = raw_intent_name_to_action_title_mapping.get(intent_name)
if action_title is None:
raw_intent_name_to_action_title_mapping[intent_name] = intent_name
action_title = intent_name
for example in intent["examples"]:
utterances.append(example["text"])
intents.append(action_title)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tabulate
matplotlib
nltk
seaborn
ibm-watson>=4.5.0
ibm-watson>=9.0.0
scipy>=1.2.0
jupyter
spacy~=2.3.2
Expand Down
22 changes: 22 additions & 0 deletions tests/utils/test_skills_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ def test_extract_workspace_data(self):
len(workspace_pd["intent"].unique()), 9, "Extract workspace failed"
)

def test_parse_intent_from_action_condition(self):

data = {
"intent": "action_10017_intent_27671"
}
self.assertEqual(
skills_util._get_intent_name_from_action_condition(data), "action_10017_intent_27671"
)
data = {
"and": [
{
"intent": "action_15841_intent_20012"
},
{
"expression": "false"
}
]
}
self.assertEqual(
skills_util._get_intent_name_from_action_condition(data), "action_15841_intent_20012"
)

@classmethod
def tearDownClass(cls):
cls.skill_file.close()
Expand Down
Loading