Skip to content

Commit

Permalink
[mod] rename split_ngram_modifiers to process_hold_modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
dariogoetz committed Oct 24, 2023
1 parent a97058a commit fc3137c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
7 changes: 7 additions & 0 deletions keyboard_layout/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ impl Layout {
(base, mods)
}

/// If the layout has at least one layer configured as hold layer
pub fn has_hold_layers(&self) -> bool {
self.layerkeys
.iter()
.any(|lk| std::matches!(lk.modifiers, LayerModifiers::Hold(_)))
}

/// If the layout has at least one layer configured as one-shot layer
pub fn has_one_shot_layers(&self) -> bool {
self.layerkeys
Expand Down
10 changes: 5 additions & 5 deletions layout_evaluation/src/ngram_mapper/bigram_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl OnDemandBigramMapper {
map_bigrams(bigrams, layout, exclude_line_breaks);

if layout.has_one_shot_layers() {
bigram_keys_vec = self.process_one_shot_layers(bigram_keys_vec, layout);
bigram_keys_vec = self.process_one_shot_modifiers(bigram_keys_vec, layout);
}

let bigram_keys = if self.split_modifiers.enabled {
self.split_bigram_modifiers(bigram_keys_vec, layout)
let bigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() {
self.process_hold_modifiers(bigram_keys_vec, layout)
} else {
bigram_keys_vec.into_iter().collect()
};
Expand Down Expand Up @@ -135,7 +135,7 @@ impl OnDemandBigramMapper {
///
/// Each bigram of higher-layer symbols will transform into a series of bigrams with permutations of
/// the involved base-keys and modifers. However, the base-key will always be after its modifier.
fn split_bigram_modifiers(&self, bigrams: BigramIndicesVec, layout: &Layout) -> BigramIndices {
fn process_hold_modifiers(&self, bigrams: BigramIndicesVec, layout: &Layout) -> BigramIndices {
let mut bigram_w_map = AHashMap::with_capacity(bigrams.len() / 3);

bigrams.into_iter().for_each(|((k1, k2), w)| {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl OnDemandBigramMapper {
bigram_w_map
}

fn process_one_shot_layers(
fn process_one_shot_modifiers(
&self,
bigrams: BigramIndicesVec,
layout: &Layout,
Expand Down
10 changes: 5 additions & 5 deletions layout_evaluation/src/ngram_mapper/trigram_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ impl OnDemandTrigramMapper {
map_trigrams(trigrams, layout, exclude_line_breaks);

if layout.has_one_shot_layers() {
trigram_keys_vec = self.process_one_shot_layers(trigram_keys_vec, layout);
trigram_keys_vec = self.process_one_shot_modifiers(trigram_keys_vec, layout);
}

let trigram_keys = if self.split_modifiers.enabled {
self.split_trigram_modifiers(trigram_keys_vec, layout)
let trigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() {
self.process_hold_modifiers(trigram_keys_vec, layout)
} else {
trigram_keys_vec.into_iter().collect()
};
Expand Down Expand Up @@ -140,7 +140,7 @@ impl OnDemandTrigramMapper {
/// trigram can be large (tens of trigrams) if multiple symbols of the trigram are accessed using multiple modifiers.
// this is one of the most intensive functions of the layout evaluation
fn split_trigram_modifiers(
fn process_hold_modifiers(
&self,
trigrams: TrigramIndicesVec,
layout: &Layout,
Expand Down Expand Up @@ -276,7 +276,7 @@ impl OnDemandTrigramMapper {
trigram_w_map
}

fn process_one_shot_layers(
fn process_one_shot_modifiers(
&self,
trigrams: TrigramIndicesVec,
layout: &Layout,
Expand Down
10 changes: 5 additions & 5 deletions layout_evaluation/src/ngram_mapper/unigram_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl OnDemandUnigramMapper {
let (mut unigram_keys_vec, not_found_weight) = map_unigrams(unigrams, layout);

if layout.has_one_shot_layers() {
unigram_keys_vec = self.process_one_shot_layers(unigram_keys_vec, layout);
unigram_keys_vec = self.process_one_shot_modifiers(unigram_keys_vec, layout);
}

let unigram_keys = if self.split_modifiers.enabled {
Self::split_unigram_modifiers(unigram_keys_vec, layout)
let unigram_keys = if self.split_modifiers.enabled && layout.has_hold_layers() {
Self::process_hold_modifiers(unigram_keys_vec, layout)
} else {
unigram_keys_vec.into_iter().collect()
};
Expand All @@ -85,7 +85,7 @@ impl OnDemandUnigramMapper {
///
/// Each unigram of a higher-layer symbol will transform into a unigram with the base-layer key and one
/// for each modifier involved in accessing the higher layer.
fn split_unigram_modifiers(unigrams: UnigramIndicesVec, layout: &Layout) -> UnigramIndices {
fn process_hold_modifiers(unigrams: UnigramIndicesVec, layout: &Layout) -> UnigramIndices {
let mut idx_w_map = AHashMap::with_capacity(unigrams.len() / 3);
unigrams.into_iter().for_each(|(k, w)| {
let (base, mods) = layout.resolve_modifiers(&k);
Expand Down Expand Up @@ -117,7 +117,7 @@ impl OnDemandUnigramMapper {
idx_w_map
}

fn process_one_shot_layers(
fn process_one_shot_modifiers(
&self,
unigrams: UnigramIndicesVec,
layout: &Layout,
Expand Down

0 comments on commit fc3137c

Please sign in to comment.