Skip to content

Commit 124e7aa

Browse files
committed
Refactoring: Minor changes.
1 parent b4bdb0a commit 124e7aa

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/jarvis/jarvis/core/nlp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _create_response(self, sentence):
113113
noun = self._extract_noun(parts_of_speech)
114114

115115
# ----------------------------
116-
# Question type classification
116+
# Command type classification
117117
# ----------------------------
118118
if self.is_question_with_modal(parts_of_speech):
119119
logging.info('The user speech has a modal question')
@@ -122,7 +122,7 @@ def _create_response(self, sentence):
122122
logging.info('The user speech has an inverse question')
123123
answer = 'I ' + ' ' + verb + ' ' + noun
124124
else:
125-
logging.debug('Unclassified question type')
125+
logging.info('Unclassified user command..')
126126
answer = ''
127127

128128
return re.sub('\s\s+', ' ', answer)

src/jarvis/jarvis/core/processor.py

+36-12
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def __init__(self, console_manager, settings_):
3939
self.settings = settings_
4040
self.response_creator = ResponseCreator()
4141
self.skill_analyzer = SkillAnalyzer(
42-
weight_measure=TfidfVectorizer,
43-
similarity_measure=cosine_similarity,
44-
args=self.settings.SKILL_ANALYZER.get('args'),
45-
sensitivity=self.settings.SKILL_ANALYZER.get('sensitivity'),
46-
)
42+
weight_measure=TfidfVectorizer,
43+
similarity_measure=cosine_similarity,
44+
args=self.settings.SKILL_ANALYZER.get('args'),
45+
sensitivity=self.settings.SKILL_ANALYZER.get('sensitivity'),
46+
)
4747

4848
def run(self):
4949
"""
@@ -61,26 +61,50 @@ def run(self):
6161
skill = self.skill_analyzer.extract(transcript)
6262

6363
if skill:
64-
skill_to_execute = {'voice_transcript': transcript, 'skill': skill}
65-
66-
response = self.response_creator.create_positive_response(transcript) if skill_to_execute \
67-
else self.response_creator.create_negative_response(transcript)
64+
# ----------------------------------------------------------------------------------------------------------
65+
# Successfully extracted skill
66+
# ----------------------------------------------------------------------------------------------------------
67+
68+
# ---------------
69+
# Positive answer
70+
# ---------------
71+
response = self.response_creator.create_positive_response(transcript)
6872
jarvis.output_engine.assistant_response(response)
6973

74+
# ---------------
75+
# Skill execution
76+
# ---------------
77+
skill_to_execute = {'voice_transcript': transcript, 'skill': skill}
7078
self._execute_skill(skill_to_execute)
7179

7280
else:
73-
# If no skill to execute, it calls the WolframAlpha API
81+
# ----------------------------------------------------------------------------------------------------------
82+
# No skill extracted
83+
# ----------------------------------------------------------------------------------------------------------
84+
85+
# ---------------
86+
# Negative answer
87+
# ---------------
88+
response = self.response_creator.create_negative_response(transcript)
89+
jarvis.output_engine.assistant_response(response)
90+
91+
# ---------------
92+
# WolframAlpha API Call
93+
# ---------------
7494
skill_to_execute = {'voice_transcript': transcript,
7595
'skill': {'name': WolframSkills.call_wolframalpha.__name__}
7696
}
7797

7898
response = WolframSkills.call_wolframalpha(transcript)
7999

100+
# --------------------------------------------------------------------------------------------------------------
101+
# Add new record to history
102+
# --------------------------------------------------------------------------------------------------------------
103+
80104
record = {'user_transcript': transcript,
81105
'response': response if response else '--',
82106
'executed_skill': skill_to_execute if skill_to_execute else '--'
83-
}
107+
}
84108

85109
db.insert_many_documents('history', [record])
86110

@@ -94,5 +118,5 @@ def _execute_skill(self, skill):
94118
skill_func = skill_objects[skill_func_name]
95119
skill_func(**skill)
96120
except Exception as e:
97-
self.console_manager.console_output(error_log="Failed to execute skill {0} with message {1}"
121+
self.console_manager.console_output(error_log="Failed to execute skill {0} with message: {1}"
98122
.format(skill_func_name, e))

0 commit comments

Comments
 (0)