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

Low-level modules should handle NluIntentParsed instead of NluIntent (support) #21

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
27 changes: 27 additions & 0 deletions rhasspyhermes/nlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ def topic(cls, **kwargs) -> str:
"""Get topic for message."""
return "hermes/nlu/intentParsed"

def to_rhasspy_dict(self) -> typing.Dict[str, typing.Any]:
"""Convert to Rhasspy format."""
return {
"intent": {
"name": self.intent.intent_name,
"confidence": self.intent.confidence_score,
},
"entities": [
{
"entity": s.slot_name,
"value": s.value.get("value"),
"value_details": s.value,
"raw_value": s.raw_value,
"start": s.start,
"end": s.end,
"raw_start": (s.raw_start if s.raw_start is not None else s.start),
"raw_end": (s.raw_end if s.raw_end is not None else s.end),
}
for s in self.slots or []
],
"slots": {s.slot_name: s.value.get("value") for s in self.slots or []},
"text": self.input,
"raw_text": self.input or "",
"tokens": self.input.split(),
"raw_tokens": self.input.split(),
}


@dataclass_json(letter_case=LetterCase.CAMEL)
@dataclass
Expand Down