Question about using groups


#1

Hi, I’m currently learning how to use ‘group()’ and ‘use()’

In the example https://help.keyman.com/developer/language/reference/match

any(vowel) + '^' > context U+0302
match > use(CombineDiacritics)
      
group(CombineDiacritics)

any(vowel) U+0302 > index(vowelWithCircumflex, 1)

could also be expressed

any(vowel) + '^' > index(vowelWithCircumflex, 1)

isn’t it?

But I haven’t find a way to express this pseudocode

function main(args) {
if (opt1==1) aksara(args);
else if (opt1==2) latin(args);

I tried below and some other variations, but they didn’t work

begin Unicode > use(Main)

group (Main) using keys

store(opt1) '1'
+ [CTRL K_1] > set(opt1='1') 
+ [CTRL K_2] > set(opt1='2')

if(opt1='1') + any(Alfanumerical) > context c basically + any(Input)
match > use(Aksara)
if(opt1='2') + any(Alfanumerical) > context
match > use(Latin)

Is it possible to ‘forward’ the input to the corresponding group depending on some kind of toggle?

If it isn’t possible, then my other option would be to create two sets of keyboard.


#2

@Marc_Keyman would be better at explaining. In the example

any(vowel) + '^' > context U+0302
match > use(CombineDiacritics)

group(CombineDiacritics)
any(vowel) U+0302 > index(vowelWithCircumflex, 1)

would be equivalent to:

any(vowel) + '^' > index(vowelWithCircumflex, 1)

where the power of groups comes in would be:

any(vowel) + '^' > context U+0302
match > use(CombineDiacritics)

group(CombineDiacritics)
any(vowelBase) U+0302 > index(vowelWithCircumflex, 1)

Where vowelBase is a subset of vowel ie you can add a combining diacritic to any vowel, but those vowel and combining diacritic combinations that have a precomposed form would be converted to the precomposed form.

This is useful for African langauges that have more than five vowels and not all vowel and diacrtic combinations exist as precomposed characters.

it is also useful for Devanagari when some character+nukta combinations should be precomposed in unicode and some combinations should be combining sequences.

If memory serves an alternative would be:

any(vowel) + '^' > context U+0302 use(CombineDiacritics)

group(CombineDiacritics)
any(vowelBase) U+0302 > index(vowelWithCircumflex, 1)

Is this correct @Marc_Keyman?


#3

I would probably write that as

if(opt1='1') + any(Alfanumerical) > context(2) use(Aksara)
if(opt1='2') + any(Alfanumerical) > context(2) use(Latin)

Not sure if this is correct.

Although most input frameowrks provide a keyboard switching mechanism. I assume that what you are trying to achieve is ability to type in Aksara or Latin orthography for a given language. Normally I would separate the two scripts into seperate keyboards. So that what i have declared the input locale is and what i am typing is consistent. Depending on the application this is useful where spellchecking and proofing are available in the language, and when language markup is automatically occurring eg MS Word (Windows)

One place i have used options is for brahmi/pallava derived scripts in SE Asia where there is a strong preference for visually ordered input rather than logical input, So options and switches are available to allow user to use to type in logical order or visual order, ie type pre-vowels before the base consonant rather than after.

If you are also building the keyboard for touch environments you may want to add an explict key to touch layout to select an option.


#4

The following code should do what you want. There can be only a single match rule per group: it fires if any rule in the group is matched.

Thus, your example of using options to swap groups is nearly correct. But instead of putting the use statement into two match rules, just put them into the rules (you can omit context as there were no context changes).

begin Unicode > use(Main)

group (Main) using keys

store(opt1) '1'
+ [CTRL K_1] > set(opt1='1') 
+ [CTRL K_2] > set(opt1='2')

if(opt1='1') + any(Alfanumerical) > use(Aksara)
if(opt1='2') + any(Alfanumerical) > use(Latin)

But we can go one better. Make your initial group a context-only group:

begin Unicode > use(Main)

group (Main)

store(opt1) '1'

if(opt1='1') > use(Aksara)
nomatch > use(Latin)

group(Aksara) using keys
+ [CTRL K_2] > set(opt1='2')
...

group(Latin) using keys
+ [CTRL K_1] > set(opt1='1') 

The advantage of this approach (apart from being slightly easier to read) is that you don’t need to include the full set of possible keystrokes in your Alfanumerical store; it can be tedious to keep that in sync with the rules in your keystroke processing groups.

A side benefit is that the opt1 store now only has one significant value (1). If it is anything other than 1, then processing goes to the Latin group.


#5

Yes, correct.

Not quite right – the context(2) in this example has no meaning (there is no context here, so nothing to copy to the output of the rule).

+1 Agree.


#6

Thanks for the corrections Marc