Author Topic: Getting enabled commands using regex  (Read 2430 times)

0 Members and 1 Guest are viewing this topic.

zen_SuR

  • Jr. Member
  • **
  • Posts: 15
  • Karma: 2
    • View Profile
Getting enabled commands using regex
« on: August 30, 2017, 11:24:55 AM »
hy,

i am trying to get an AND regex to work for the last few hours and i give up and hope somebody here can help me...

first i file.read my voicecommands.xml
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands version="2.2.3.7" space="preserve" date="8/30/2017 12:00:00 AM">
    <commandGroup open="True" name="Vox Commands" enabled="True" prefix="" priority="1" requiredProcess="" description="">
        <command id="8" name="Don't Listen" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>VC.Standby</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>ignore me,don't listen,stand by</phrase>
        </command>
        <command id="31" name="Listen" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>VC.On</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>computer, start listening, pay attention</phrase>
            <event>Amulet.On</event>
        </command>
        <command id="32" name="Option" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>VC.Option</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>Option,Select Option</phrase>
            <payloadRange>1,10</payloadRange>
        </command>
        <command id="43" name="Vox Off" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>VC.Off</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>vox off, vox commando off,disable vox commando</phrase>
            <event>Amulet.Off</event>
        </command>
    </commandGroup>
    <commandGroup open="True" name="Show Help" enabled="True" prefix="" priority="0" requiredProcess="" description="">
        <command id="266" name="Show help" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Help.ShowAll</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>These are all of the voice commands for this configuration.</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>Show help, What can I say</phrase>
        </command>
        <command id="264" name="Show active commands" enabled="False" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Help.ShowEnabled</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>These are voice commands in groups that are enabled.</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>Show</phrase>
            <phrase optional="true">me, us</phrase>
            <phrase optional="true">the</phrase>
            <phrase>active, enabled</phrase>
            <phrase optional="true">voice</phrase>
            <phrase>commands</phrase>
        </command>
        <command id="305" name="Send help" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>File.Read</cmdType>
                <params>
                    <param>Resources\help.css</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>File.Write</cmdType>
                <params>
                    <param>plugins\TCP\html\commandhelp2.html</param>
                    <param>&lt;html&gt;&lt;head&gt;&lt;meta charset="UTF-8"&gt;&lt;title&gt;aaaaa&lt;/title&gt;&lt;style&gt;{LastResult}asdfasdf&lt;/style&gt;&lt;/head&gt;</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegExSingle</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Help.ShowEnabled</cmdType>
                <params />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>Refreshing command list on your local web server.</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>File.Read</cmdType>
                <params>
                    <param>commandhelp2.html</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegExSingle</cmdType>
                <params>
                    <param>&lt;/head&gt;(.*?)$</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>File.Append</cmdType>
                <params>
                    <param>plugins\TCP\html\commandhelp2.html</param>
                    <param>{Match.1}</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <phrase>Send help</phrase>
        </command>
    </commandGroup>
    <commandGroup open="True" name="reuters" enabled="True" prefix="" priority="0" requiredProcess="" description="">
        <command id="1173" name="Reuters news" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{Match.{i}.1} is the headline (where {i} is 1st, 2nd, 3rd ... headlines)&#xD;&#xA;{Match.{i}.2} is the URL linking to each full story.&#xD;&#xA;&#xD;&#xA;There will be more matches stored in the payload xml file than the 4 announced in the command.">
            <action>
                <cmdType>Scrape</cmdType>
                <params>
                    <param>http://feeds.reuters.com/reuters/worldNews</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegExSingle</cmdType>
                <params>
                    <param>&lt;item&gt;.*?&lt;title&gt;(.*?)&lt;.*?description.*?&lt;link&gt;(.*?)&lt;</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>PayloadXML.Clear</cmdType>
                <params>
                    <param>reuters.xml</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>PayloadXML.AddPair</cmdType>
                <params>
                    <param>reuters.xml</param>
                    <param>{Match.{i}.2}</param>
                    <param>{i}</param>
                </params>
                <cmdRepeat>{#M}</cmdRepeat>
            </action>
            <action>
                <cmdType>OSD.ShowText</cmdType>
                <params>
                    <param>Today's Reuter's headlines ({#M} total):</param>
                    <param>10000</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>OSD.AddText</cmdType>
                <params>
                    <param>{i}. {Match.{i}.1}.</param>
                </params>
                <cmdRepeat>4</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.SpeakSync</cmdType>
                <params>
                    <param>Here are the top 4 of {#M} Reuter's headlines</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>{i}. {Match.{i}.1}.</param>
                </params>
                <cmdRepeat>4</cmdRepeat>
            </action>
            <phrase>What's the news from Reuters</phrase>
        </command>
        <command id="1179" name="More from Reuters" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Shows the first line of the story. Reads out the whole story.&#xD;&#xA;&#xD;&#xA;If you want it to only read the first few sentences, you can change {#M} to a specific number. So, if you use 2 instead of {#M} then it will read the first 3 lines, because the first sentence is read in the separate, TTS.Speak - {Match.1} action. (Or, you can create a separate &quot;shut up&quot; command with a TTS.Stop action to stop the TTS in mid-read. This would allow you to hear as much or as little as you wanted.)">
            <action>
                <cmdType>Launch.OpenURL</cmdType>
                <params>
                    <param>{1}</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Scrape</cmdType>
                <params>
                    <param>{1}</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegExSingle</cmdType>
                <params>
                    <param>="description"\scontent="(.*?)"</param>
                    <param><![CDATA[ ]]></param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>{Match.1}</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>OSD.ShowText</cmdType>
                <params>
                    <param>{Match.1}</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.RegExSingle</cmdType>
                <params>
                    <param>&lt;.*?midArticle_\d"&gt;&lt;/span&gt;&lt;p&gt;(.*?)&lt;</param>
                </params>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>TTS.Speak</cmdType>
                <params>
                    <param>{Match.{i}}</param>
                </params>
                <cmdRepeat>{#M}</cmdRepeat>
            </action>
            <phrase>Tell me more about headline number</phrase>
            <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">reuters.xml</payloadFromXML>
        </command>
    </commandGroup>
</VoiceCommands>

and with my regex i want all commandnames where enabled="true"...

no matter what i tried i dont get it.

the first half of the regex works very well:
Code: [Select]
<command\s[^<>]*name="(.*?)"gives me all the command names... but yeah... all of them. and i just want the enabled commands.

here would be a quick regex-onlinetool in case somebody wants to try... http://regexr.com/

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Getting enabled commands using regex
« Reply #1 on: August 30, 2017, 05:44:43 PM »
If all you want are the command names (for those that are enabled):

Code: [Select]
<command.id.*?name="(.*?)"\senabled="true"
should do it.
« Last Edit: August 30, 2017, 06:33:00 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

zen_SuR

  • Jr. Member
  • **
  • Posts: 15
  • Karma: 2
    • View Profile
Re: Getting enabled commands using regex
« Reply #2 on: August 30, 2017, 06:56:15 PM »
oh it should... but the next problem is when the commandgroup is disabled. that does not reflect in the enabled="true" in command id...

for that and for other reasons i try to get the following going: i just wanna find commandnames thats description starts with "public "...

<command\sid[^<>]*name="(.*?)"[^<>]*description="public\s(.*?)"

does not at all work great... this regexstuff does not exactly boost my selfconfidence ;)

EDIT: yes... its my intend that i want the description as a submatch also... the endgoal is an automated dynamic html-interfacecreator and it kind of works already... but i just want certain commands to appear - therefor i decided to tell vc that way...
« Last Edit: August 30, 2017, 07:01:41 PM by zen_SuR »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Getting enabled commands using regex
« Reply #3 on: August 31, 2017, 12:52:50 PM »
Commands are always "on".  When I set up the XML I thought I might want to be able to disable commands but then it made more sense to do it on the group level so that value is never used.

Only the groups get turned on and off so you would need to remove the groups that are off first.  You could use something like this with RegEx replace to get rid of the groups that are off.
Code: [Select]
<commandGroup[^>]*?enabled="False".*?</commandGroup>
Once you replace the empty groups with nothingness you can process the commands that are left over.

But really, what you are trying to do would be a lot easier if you used a python script with some libraries that allow you to navigate through the XML.

Maybe something like this: https://docs.python.org/2/library/xml.etree.elementtree.html

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Getting enabled commands using regex
« Reply #4 on: August 31, 2017, 01:00:31 PM »
for that and for other reasons i try to get the following going: i just wanna find commandnames thats description starts with "public "...


If all you are looking for is the command names you can use this:
Code: [Select]
<command.*?name="(.*?)" .*?description="public">

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Getting enabled commands using regex
« Reply #5 on: August 31, 2017, 01:01:58 PM »
here would be a quick regex-onlinetool in case somebody wants to try... http://regexr.com/

VoxCommando comes with its own RegEx tool built in.  I recommend people use this whenever possible.

http://voxcommando.com/forum/index.php?topic=1699.0

zen_SuR

  • Jr. Member
  • **
  • Posts: 15
  • Karma: 2
    • View Profile
Re: Getting enabled commands using regex
« Reply #6 on: August 31, 2017, 01:04:51 PM »
right in this second i came up with this:

<command\sid[^<>]*name="(.*?)"[^<>]*description="public(.*?)"

now i get what i want. your solution works the same while being way more beautiful ;)


i also know and heavily use the regextool.

EDIT: it just works if i result.replace description="" with description="_" so match.1.1 and match 1.2 add up since i store it in seperate txts... but everything works now ;)

i now try to also read the according phrase... and maybe commandgroup... but that seems to be superhard ;) is there somewhere the codesnippets responsible for creating the commandhelp.html? it basically needs the same functionality from what i am trying to achieve....


« Last Edit: August 31, 2017, 01:09:43 PM by zen_SuR »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Getting enabled commands using regex
« Reply #7 on: August 31, 2017, 01:36:58 PM »
No.