Skip to content

Commit

Permalink
Rasanlu: The Rasa API states the key is 'confidence' but the fact is …
Browse files Browse the repository at this point in the history
…the key is 'confidence_entity' for the entity extraction. (#1888)

https://rasa.com/docs/rasa/pages/http-api#operation/parseModelMessage

Co-authored-by: Oleg Fiksel <oleg@fiksel.info>
  • Loading branch information
oleg-fiksel and Oleg Fiksel committed Feb 20, 2022
1 parent 4ac4464 commit 1bdafbd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
15 changes: 12 additions & 3 deletions opsdroid/parsers/rasanlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,18 @@ async def parse_rasanlu(opsdroid, skills, message, config):
if matcher["rasanlu_intent"] == result["intent"]["name"]:
message.rasanlu = result
for entity in result["entities"]:
message.update_entity(
entity["entity"], entity["value"], entity["confidence"]
)
if "confidence_entity" in entity:
message.update_entity(
entity["entity"],
entity["value"],
entity["confidence_entity"],
)
elif "extractor" in entity:
message.update_entity(
entity["entity"],
entity["value"],
entity["extractor"],
)
matched_skills.append(
{
"score": confidence,
Expand Down
30 changes: 27 additions & 3 deletions tests/test_parser_rasanlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def test_parse_rasanlu(self):
"end": 32,
"entity": "state",
"extractor": "ner_crf",
"confidence": 0.854,
"confidence_entity": 0.854,
"start": 25,
"value": "running",
}
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_parse_rasanlu_entities(self):
"value": "chinese",
"entity": "cuisine",
"extractor": "CRFEntityExtractor",
"confidence": 0.854,
"confidence_entity": 0.854,
"processors": [],
}
],
Expand All @@ -190,6 +190,30 @@ async def test_parse_rasanlu_entities(self):
skill["message"].entities["cuisine"]["value"], "chinese"
)

with amock.patch.object(rasanlu, "call_rasanlu") as mocked_call_rasanlu:
mocked_call_rasanlu.return_value = {
"text": "show me chinese restaurants",
"intent": {"name": "restaurant_search", "confidence": 0.98343},
"entities": [
{
"start": 8,
"end": 15,
"value": "chinese",
"entity": "cuisine",
"extractor": "RegexEntityExtractor",
}
],
}
[skill] = await rasanlu.parse_rasanlu(
opsdroid, opsdroid.skills, message, opsdroid.config["parsers"][0]
)

self.assertEqual(len(skill["message"].entities.keys()), 1)
self.assertTrue("cuisine" in skill["message"].entities.keys())
self.assertEqual(
skill["message"].entities["cuisine"]["value"], "chinese"
)

async def test_parse_rasanlu_raises(self):
with OpsDroid() as opsdroid:
opsdroid.config["parsers"] = [
Expand All @@ -215,7 +239,7 @@ async def test_parse_rasanlu_raises(self):
"end": 32,
"entity": "state",
"extractor": "ner_crf",
"confidence": 0.854,
"confidence_entity": 0.854,
"start": 25,
"value": "running",
}
Expand Down

0 comments on commit 1bdafbd

Please sign in to comment.