Skip to content
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

feat: view options and suggestions response type #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 29 additions & 5 deletions src/assistant_improve_toolkit/computation_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@ def extract_intent_completed(payload):
return res


def extract_response_generic(payload):
res = ''
rt = ''
if len(payload) > 0:
for member in payload:
if 'response_type' in member:
rt = member['response_type']
if rt == 'text':
if 'text' in member:
res = res + member['text']
if rt == 'option':
if 'title' in member:
res = res + member['title'] + ' '
if 'options' in member:
res = res + extract_label(member['options'])
if rt == 'suggestion':
if 'title' in member:
res = res + member['title'] + ' '
if 'suggestions' in member:
res = res + extract_label(member['suggestions'])
return res

def format_data(df):
"""This function formats the log data from watson assistant by separating columns and changing datatypes
Parameters
Expand All @@ -282,17 +304,19 @@ def format_data(df):
print('Extracting request and response ...')
df1 = pd.concat([df.drop(['request', 'response'], axis=1).reset_index(drop=True),
df['request'].apply(pd.Series).add_prefix('request_').reset_index(drop=True),
pd.DataFrame(df['response']
.tolist()).add_prefix('response_')], axis=1) # type: pd.DataFrame
pd.DataFrame(df['response'].tolist()).add_prefix('response_')], axis=1) # type: pd.DataFrame

df1['request_input'] = pd.json_normalize(df['request'])['input.text']

# Add context and output fields
print('Extracting context and output ...')
df2 = pd.concat([df1.drop(['response_context', 'response_output'], axis=1),
df1['response_context'].apply(pd.Series).add_prefix('response_context_'),
pd.DataFrame(df1['response_output'].tolist()).add_prefix('response_')],
axis=1) # type: pd.DataFrame

pd.DataFrame(df1['response_output'].tolist()).add_prefix('response_')], axis=1) # type: pd.DataFrame

print('Extract from response generic array ...')
df2['response_text'] = df2['response_generic'].apply(lambda x: extract_response_generic(x))

# Add context_system fields
df3 = pd.concat([df2.drop(['response_context_system'], axis=1),
df2['response_context_system'].apply(pd.Series).add_prefix('response_')],
Expand Down