Skip to content

Commit

Permalink
Add 'special' checks for DNA
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Feb 13, 2025
1 parent 3b52466 commit 9411a42
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/codebook/src/dictionaries/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod dictionary;
pub mod manager;
pub mod repo;
pub mod special;
33 changes: 33 additions & 0 deletions crates/codebook/src/dictionaries/special.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pub fn check_special(word: &str) -> bool {
is_dna_sequence(word)
}

fn is_dna_sequence(s: &str) -> bool {
if s.len() < 4 {
return false;
}
for c in s.chars() {
match c {
'A' | 'T' | 'C' | 'G' | 'a' | 't' | 'c' | 'g' => {
continue;
}
_ => return false,
}
}
true
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_dna_sequence() {
assert!(is_dna_sequence("ATCGATCG"));
assert!(is_dna_sequence("ATCG"));
assert!(is_dna_sequence("atcgatcg"));
assert!(!is_dna_sequence("xyzATCGAbc"));
assert!(!is_dna_sequence("Hello"));
assert!(!is_dna_sequence("ATC"));
}
}
5 changes: 4 additions & 1 deletion crates/codebook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod splitter;
use std::sync::Arc;

use codebook_config::CodebookConfig;
use dictionaries::{dictionary, manager::DictionaryManager};
use dictionaries::{dictionary, manager::DictionaryManager, special::check_special};
use dictionary::Dictionary;
use parser::WordLocation;

Expand Down Expand Up @@ -43,6 +43,9 @@ impl Codebook {
if self.config.is_allowed_word(word) {
return true;
}
if check_special(word) {
return true;
}
for dictionary in &dictionaries {
if dictionary.check(word) {
return true;
Expand Down

0 comments on commit 9411a42

Please sign in to comment.