SEPIA-Framework / sepia-docs

Documentation and Wiki for SEPIA. Please post your questions and bug-reports here in the issues section! Thank you :-)
https://sepia-framework.github.io/
236 stars 16 forks source link

Migration of sentences - JSGF Grammar / Ini-style #203

Open hoamer opened 2 years ago

hoamer commented 2 years ago

name: Question about SEPIA about: Ask general questions title: 'JSGF / Rhasspy init-style' labels: '' assignees: ''


Hi,

I want to start with expressing my congratulations for this nice piece of software. It looks very promising. Following with my setup:

Currently I am using rhasspy as assistant, which is also great in terms of maturity. Peeking in directions of SEPIA, I wanted to migrate step by step to SEPIA. As described above, I am using Node-Red for my "actions" together with MQTT.

I want to migrate my Sentences from Rhasspy, which are in JSGF-/INI-Style. It seems, there is no direct way using this in SEPIA?

My very problem is, that I have sentences like

Füge {mode} zur Wäschekasse (0..15) {frankenDiff} Franken hinzu

If I am not totally wrong, there is no easy way to realize this (or more complicated) cases like this, together with MQTT via SEPIA?

Thanks, and best regards Sebastian

fquirin commented 2 years ago

Hi Sebastian,

unfortunately there is no direct import feature right now, but I've been thinking about this for a while now. Michael does a great job building Rhasspy (and now Mycroft) and we're discussing compatibility from time to time, but are usually both too busy with other features :see_no_evil: to work on this. Maybe I should finally put it on top of the to-do list ^^.

That said there are some options available right now to achieve a similar result. The most flexible is building a custom service. Usually you would first define parameter handlers for your service (or choose predefined ones) and let SEPIA use them to search your sentence automatically. Each parameter class (a kind of "slot" or "named-entity") has 2 core functions: extract and build. The idea is to first find some variation of your parameter in the extract phase (in German e.g. for color blue: "blaues", "blauen", "blau", "blaue" ...) and then you generalize it (e.g. to "blue") to use it in your service. Parameter handlers can start very simple but often become pretty complex depending on how much fine tuning is required ^^.

Now coming back to your initial question, in custom services there is an extended regular-expression feature to generate parameters on the fly and skip most of the coding. It works a bit like JSGF and looks for example like this:

info.setCustomTriggerRegX("(set (?<ParameterA>.*?) to (?<ParameterB>1|2|3))", LANGUAGES.EN);

This simple example generates the "variables" ParameterA and ParameterB as dynamic parameters and makes the result available in your script to handle the intent (e.g. a broadcast via MQTT etc.). ParameterA matches anything between "set" and "to" and ParameterB matches the rest if its 1, 2 or 3. 1|2|3 could be replaced with \\d+ to match any real number or [1-9] etc. etc..

To make all this work there is a bit of boilerplate code required, but if you're interested in experimenting with it I can build something to get started. There are a few smart-service examples as well (including an MQTT service) in the extensions repo.

To import JSGF into SEPIA the approach would probably be to try and transfer as much JSGF info as possible to the extract and build phases of dynamically generated parameters (as described above).

hoamer commented 2 years ago

Hey Florian,

thanks for your fast and very precise explanation. Unfortunately this seems a bit too complicated to me for "day to day"-use^^ But I hope, your nice and detailed answer helped other users!

I really appreciate that you are using some kind of regexes in this approach. This will make it much more flexible. After posting your answer, I found this discussion (https://github.com/SEPIA-Framework/sepia-docs/issues/29), which seems directly related. Maybe this gives other ones interested in this an extra hint.

Viele Grüße nach Essen, Sebastian

fquirin commented 2 years ago

Unfortunately this seems a bit too complicated to me for "day to day"-use^^

There is a simpler but less powerful option using the Teach-UI command Execute command(s) right inside the app. It is meant to map one sentence to another and supports simple variables. The only thing you need is a service that will handle your request. Do you simply want to broadcast the extracted parameters via MQTT?

Here is an example of remapping smart home service commands:

image

To make this work I simply created a smart-home 'device' called "Wäschekasse" via the Control-HUB with input type number :).

Viele Grüße nach Essen

Grüße zurück nach (?) :grin: . Nur so aus Neugier, wo kam die Info zur Stadt her? ^^

hoamer commented 2 years ago

Hi,

sorry for the delayed answer. Perfect, is peeked into this solution before and will give it a try. Thanks!

Die Stadt steht in deinem Impressum auf "bytemind [punkt] de", welche du in deinem Github-Profil angegeben hast.

fquirin commented 2 years ago

Perfect, I peeked into this solution before and will give it a try. Thanks!

Let me know if it works for you or if you need some extra features :-)

Die Stadt steht in deinem Impressum auf "bytemind [punkt] de", welche du in deinem Github-Profil angegeben hast.

Ach stimmt, da war was ^^