dictation-toolbox / Vocola2

A Voice Command Language
Other
4 stars 3 forks source link

Vocola does not handle contextual commands correct #1

Open quintijn opened 4 years ago

quintijn commented 4 years ago

When using contextual commands in a Vocola "grammar", rules are not reswitched on when the context re-appears. In fact nog rules are switched on when a specific context is lost.

This should be solved in the Vocola python generating files in C:\DT\Natlink\Vocola\exec\vcl2py (DT being my root directory).

Also see https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=25&threadid=34503&enterthread=y

quintijn commented 4 years ago

I basically found the error, but I did not succeed to delve into the vocola compiler via a debugger in order to see what happens exactly. Also printing info is very difficult as things are wrapped very deep.

quintijn commented 4 years ago

I put my "manual"fix file in the Natlink\Vocola directory, filename fix_example_contexts.py

The essentials:

    def activate_rule(self, rule, window, status):
        if status:
            try:
                # print("activate rule %s for window: %s"% (rule,window))
                self.activate(rule, window)
            except natlink.BadWindow:
                pass
        else:
            # print('deactivate rule %s for window %s'% (rule, window))
            self.deactivate(rule, noError=1)

    def gotBegin(self,moduleInfo):
        self.firstWord = 0
        # Return if wrong application
        window = matchWindow(moduleInfo,'brave','')
        if not window: return None
        # Return if same window and title as before
        if moduleInfo == self.currentModule: return None
        self.currentModule = moduleInfo

        title = moduleInfo[1].lower()
        for titlepart, rule in [('knowbrainer', 'sequence_set2'), ('faunabescherming', 'sequence_set3')]:
            status = title.find(titlepart) >= 0
            if status:
                self.activate_rule(rule, moduleInfo[2], True)
                print('set rule %s (%s)'% (rule, titlepart))
                break
        else:
            print('set default rule sequence')
            self.activate_rule('sequence', moduleInfo[2], True)

So a simplified activate_rule function, and an adapted gotBegin function, as the activate_rule (and deactivate_rule) of natlinkutils already keeps the bookkeeping. Note a smarter way to go through the contexts in example above, falling back on the default one if none of the special contexts meet the requirements.

The essentials in the .vcl file are, giving those two extra contexts (apart from the default one):

KnowBrainer:
    knowbrainer test = MSG("context knowbrainer");

Faunabescherming:
    faunabescherming test een = MSG("context aaZZaunabescherming");
    faunabescherming test twee = MSG("context faunabescherming twee");
quintijn commented 4 years ago

fix_example_contexts.py.txt

mdbridge commented 2 years ago

I was able to reproduce this with the following file:

KnowBrainer:

is this KnowBrainer = MsgBoxConfirm("absolutely", 64, "Debug info");

:

is this chrome = MsgBoxConfirm("chrome is here", 64, "Debug info");

When I switch to a different tab, the Vocola grammar file deactivates just the rule for KnowBrainer but somehow that also stops the rule for the global context as well. This appears to be a Dragon bug.

Adding debugging to NatLink code shows it isn't doing anything funny -- its state mirrors what Vocola thinks it should be.

mdbridge commented 9 months ago

fixed in version 2.9

quintijn commented 9 months ago

Hi Mark, I now see, that I noticed this problem long time ago. Forgot about this. You now say "fixed in version 2.9", but I see no changes in the github source code, and no new pip version. Could we have contact about this, and preferably with Doug Ransom too, as he recently streamlined the release on pip procedure.

Thanks, Quintijn

quintijn commented 9 months ago

BTW, on my computer the contextual commands work well. I really don't know what might be the cause of them not functioning for other users!

mdbridge commented 7 months ago

version 2.9 is currently on a branch, dragonfly. I will merge it into master once I have released 2.8.8

mdbridge commented 7 months ago

see e.g., https://github.com/mdbridge/Vocola-2/blob/dragonfly/src/Release-2-9-notes.txt