Author Topic: Separating out a text Variable  (Read 1605 times)

jonsky7

  • Newbie
  • *
  • Posts: 14
Separating out a text Variable
« on: February 18, 2021, 10:35:01 AM »
Hi,

Sorry, lot's of questions I know, can never seem to find what I'm looking for.

I have to program a lot of airfields by position and I'm trying to see if there is a easier/faster way of doing it.
at the moment I set each of the Variables IDENTx, Nx, and Ex individually.

Code: [Select]
When I say -  [Directions;Direct] [to;] Tangmere

Set Boolean [westeast] to True
Set text [longitude] to 'west'
Begin Boolean Compare : [speech] Equals True
    Say, '{CMDSEGMENT:2}'  (and wait until it completes)
End Condition

----------------------------------------Doesn't have an ICAO Ident code, uses LAT/LON instead------------------------------
Give it a Ident CODE
Set text [IDENT1] to '3'
Set text [IDENT2] to 'T'
Set text [IDENT3] to 'A'
Set text [IDENT4] to 'N'
Set Boolean [numbreadback] to False
----------------------------------------------------------------------DDD.MM.MM
----------------------------------------------------------------------Enters North
Set text [N0] to '0'
Set text [N1] to '5'
Set text [N2] to '0'
Set text [N3] to '5'
Set text [N4] to '0'
Set text [N5] to '6'
Set text [N6] to '9'
----------------------------------------------------------------------Enters East
Set text [E0] to '0'
Set text [E1] to '0'
Set text [E2] to '0'
Set text [E3] to '4'
Set text [E4] to '2'
Set text [E5] to '1'
Set text [E6] to '2'
--------------------------------------------Commands entry into GPS
Execute command, '[NS430 Automatic;] Airport Position automatic entry ' (and wait until it completes)

Ideally what I would like to be able to do is extract the text from another variable, something like:

Code: [Select]
set text [airfield] 3TAN 0505069 0004212
and then the Variables IDENTx Nx, and Ex are created from it, just so I'm not setting 18 individual variables for every airfield.

Is that possible?

I thought there might me something like CMDSEGMENT but for TXT variables

Thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Separating out a text Variable
« Reply #1 on: February 18, 2021, 10:18:06 PM »
I thought there might me something like CMDSEGMENT but for TXT variables

There is not, though a feature suggestion for that has been made.


To split those using native actions, you'd need to use a combination of the "{TXTPOS:}" and "{TXTSUBSTR}" tokens, with some looping and counting.

The arguably simpler option is to use String.Split() in an inline function instead, E.G.
Code: [Select]
using System;

public class VAInline
{
public void main()
{
string[] airfieldData = (VA.GetText("airfield") ?? "").Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
if (airfieldData.Length == 0)
{
VA.WriteToLog("Airfield data has not been set", "red");
return;
}
if (airfieldData.Length != 3)
{
VA.WriteToLog("Airfield data is not in the correct format (" + airfieldData.Length + " sections where 3 are expected)", "red");
return;
}

SetSingleVAVariables(airfieldData[0], "IDENT");
SetSingleVAVariables(airfieldData[1], "N");
SetSingleVAVariables(airfieldData[2], "E");
}

void SetSingleVAVariables(string input, string variablePrefix)
{
char[] inputDigits = input.ToCharArray();
for (int i = 0; i < inputDigits.Length; i++)
{
VA.SetText(variablePrefix + i, inputDigits[i].ToString());
//VA.WriteToLog(variablePrefix + i + " = " + inputDigits[i]); /*Writes the variable names and their values to the log; if desired for debugging, remove the "//" prefix */
}
}
}

Note that all variable naming starts at 0 (you currently have "IDENT" starting at 1, but the other two at 0), which is both more consistent, and doesn't require special handling.

jonsky7

  • Newbie
  • *
  • Posts: 14
Re: Separating out a text Variable
« Reply #2 on: February 19, 2021, 03:51:17 PM »
Yep, that is super awesome, thanks very much!!!

jonsky7

  • Newbie
  • *
  • Posts: 14
Re: Separating out a text Variable
« Reply #3 on: March 14, 2021, 05:10:59 PM »
Hi,

adding to this, I seem to have gotten dictating two 7 digit numbers to work, could you tell me how I would use the string.split to seperate that into my N0-6 and E0-6 variables please.

I tried backwards engineering your string.split, but I couldn't get it to work.

Any help appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Separating out a text Variable
« Reply #4 on: March 14, 2021, 05:24:46 PM »
What are the contents of your command?


Depending on the format, if you store the relevant parts in the "airfield" variable separated by spaces, no modification to the inline function should be required.

Otherwise, the "SetSingleVAVariables()" method should make it fairly simple to separate out just the parts you need.

jonsky7

  • Newbie
  • *
  • Posts: 14
Re: Separating out a text Variable
« Reply #5 on: March 15, 2021, 01:58:04 PM »
Sorry, I haven't made myself very clear there.

Basically, after playing around a bit with the speech dictionary, I can now record two 7 digit numbers through dictation with reasonable success. But I have problems saying one number, it's often recorded as the word, and individual letters often come out as words too. So I will manually enter the "first part" eg 3TAN

Then using dictation I record two seven digit numbers and then set the variable "airfield" to {DICTATION} and the output is like:
0505069 0004212

The same as before, I'd like to separate each number into the variables N0-6 and E0-6.

So I was trying to use your string.split code but seperate into two parts instead of three, and omit the IDENT part, but I failed.

Code: [Select]
When I say - Pilot Rescue
Set text [IDENT0] to 'S'
Set text [IDENT1] to 'A'
Set text [IDENT2] to 'R'
Set text [IDENT3] to '1'
Clear Dictation Buffer
Say, 'ready to copy'  (and wait until it completes)
Pause 0.2 seconds
Start Dictation Mode
Pause 20 seconds      --------time to record numbers
Stop Dictation Mode
Set text [airfield] to '{DICTATION}'
Inline C# Function: , wait until execution finishes
Write [Gray] '{DICTATION}' to log
Write [Blue] 'N {TXT:N0}{TXT:N1}{TXT:N2}°{TXT:N3}{TXT:N4}.{TXT:N5}{TXT:N6}  E {TXT:E0}{TXT:E1}{TXT:E2}°{TXT:E3}{TXT:E4}.{TXT:E5}{TXT:E6}' to log
DISABLED - Write [Blue] '{TXT:IDENT0}{TXT:IDENT1}{TXT:IDENT2}{TXT:IDENT3}' to log
Say, '{TXT:N0}{TXT:N1}{TXT:N2},, {TXT:N3}{TXT:N4},, {TXT:N5}{TXT:N6}.... {TXT:E0}{TXT:E1}{TXT:E2},, {TXT:E3}{TXT:E4},, {TXT:E5}{TXT:E6}'
Wait for spoken response: 'yes;no'
Begin Text Compare : [yesno] Equals 'yes'
     Say, 'ok'
     Execute command, '[NS430 Automatic;] Airport Position automatic entry ' (and wait until it completes)
  Else
    Say, 'sorry about that'
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Separating out a text Variable
« Reply #6 on: March 15, 2021, 04:41:39 PM »
With your current command, all that should be required is to replace "3" with "2" in the second length check, and to remove "SetSingleVAVariables(airfieldData[0], "IDENT");" while having the call for "N" get the data at array index 0 rather than 1, and the call for "E" at array index 1 rather than 2.

However, if you modify your command like this:
Code: [Select]
Set text [airfield] to 'SAR1'
Clear Dictation Buffer
Say, 'ready to copy'  (and wait until it completes)
Pause 0.2 seconds
Start Dictation Mode
Pause 20 seconds      --------time to record numbers
Stop Dictation Mode
Set text [airfield] to '{TXT:AIRFIELD} {DICTATION}'
Inline C# Function: , wait until execution finishes
Write [Gray] '{DICTATION}' to log
Write [Blue] 'N {TXT:N0}{TXT:N1}{TXT:N2}°{TXT:N3}{TXT:N4}.{TXT:N5}{TXT:N6}  E {TXT:E0}{TXT:E1}{TXT:E2}°{TXT:E3}{TXT:E4}.{TXT:E5}{TXT:E6}' to log
DISABLED - Write [Blue] '{TXT:IDENT0}{TXT:IDENT1}{TXT:IDENT2}{TXT:IDENT3}' to log
Say, '{TXT:N0}{TXT:N1}{TXT:N2},, {TXT:N3}{TXT:N4},, {TXT:N5}{TXT:N6}.... {TXT:E0}{TXT:E1}{TXT:E2},, {TXT:E3}{TXT:E4},, {TXT:E5}{TXT:E6}'
Wait for spoken response: 'yes;no'
Begin Text Compare : [yesno] Equals 'yes'
     Say, 'ok'
     Execute command, '[NS430 Automatic;] Airport Position automatic entry ' (and wait until it completes)
  Else
    Say, 'sorry about that'
End Condition
It should work without any modification to the inline function (assuming dictation is working consistently, though that applies whether you modify it or not).


You could also use a while loop to check whether dictation has completed based on the contents of the dictation buffer, rather than an arbitrary time limit.

E.G.
Code: [Select]
Set text [airfield] to 'SAR1'
Clear Dictation Buffer
Say, 'ready to copy'  (and wait until it completes)
Pause 0.2 seconds
Start Dictation Mode
Start Loop While : [{EXP: {TXTLEN:"{DICTATION}"} < 9}] Equals '0'
End Loop
Stop Dictation Mode
Set text [airfield] to '{TXT:AIRFIELD} {DICTATION}'
Inline C# Function: , wait until execution finishes
Write [Gray] '{DICTATION}' to log
Write [Blue] 'N {TXT:N0}{TXT:N1}{TXT:N2}°{TXT:N3}{TXT:N4}.{TXT:N5}{TXT:N6}  E {TXT:E0}{TXT:E1}{TXT:E2}°{TXT:E3}{TXT:E4}.{TXT:E5}{TXT:E6}' to log
DISABLED - Write [Blue] '{TXT:IDENT0}{TXT:IDENT1}{TXT:IDENT2}{TXT:IDENT3}' to log
Say, '{TXT:N0}{TXT:N1}{TXT:N2},, {TXT:N3}{TXT:N4},, {TXT:N5}{TXT:N6}.... {TXT:E0}{TXT:E1}{TXT:E2},, {TXT:E3}{TXT:E4},, {TXT:E5}{TXT:E6}'
Wait for spoken response: 'yes;no'
Begin Text Compare : [yesno] Equals 'yes'
     Say, 'ok'
     Execute command, '[NS430 Automatic;] Airport Position automatic entry ' (and wait until it completes)
  Else
    Say, 'sorry about that'
End Condition

That just checks whether more than 9 characters are in the dictation buffer (seven for the first section, a space, and at least one for the second section; you could check for the exact 15 characters, but then it'd keep looping if there is a character missing when the recognition didn't quite work accurately) before proceeding to process the data.

jonsky7

  • Newbie
  • *
  • Posts: 14
Re: Separating out a text Variable
« Reply #7 on: March 17, 2021, 10:36:47 AM »
Hi Pfeil, just popping back to say thank you very much.

I especially liked the line
Code: [Select]
"Start Loop While : [{EXP: {TXTLEN:"{DICTATION}"} < 9}] Equals '0'"and with it you had already answered what was probably going to be my next question  ;)

I thought I had the number dictation all figured out, but I had only been testing my 7 digit numbers beginning with zero.
Once I started using other numbers as the first digit, I came across the fact that windows speech recognition likes to put a hyphen after the first digits, arrrggggghhhhhhhh FFS.

I did find the "replace xxx with xxx" at the bottom of the "set text" action which sorted that out thank fully.

Thanks again, quite pleased with the result.

https://www.youtube.com/watch?v=woZP6yfuMVE