<commit_before>mod alphabet;
mod combined;

use std::fmt;
use std::str::FromStr;

use crate::Lang;

pub trait NormalizedOutcome {
    fn normalized_scores(&self) -> &[(Lang, f64)];
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Method {
    Trigram,
    Alphabet,
    Combined,
}

impl FromStr for Method {
    // TODO: implement normal error
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().trim() {
            "trigram" => Ok(Method::Trigram),
            "alphabet" => Ok(Method::Alphabet),
            _ => Err(format!("Cannot obtain Method from {:?}", s)),
        }
    }
}

impl fmt::Display for Method {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let name = match self {
            Method::Trigram => "Trigram",
            Method::Alphabet => "Alphabet",
            Method::Combined => "Combined",
        };
        write!(f, "{}", name)
    }
}

pub fn detect_by_method(text: &str, method: Method) -> Option<Lang> {
    if let Some(script) = crate::detect_script(text) {
        match method {
            Method::Trigram => crate::detect_lang(text),
            Method::Alphabet => alphabet::detect_by_alphabet(text, script),
            Method::Combined => combined::detect_by_combined(text, script),
        }
    } else {
        None
    }
}
<commit_msg>Fix Method::Combined<commit_after>mod alphabet;
mod combined;

use std::fmt;
use std::str::FromStr;

use crate::Lang;

pub trait NormalizedOutcome {
    fn normalized_scores(&self) -> &[(Lang, f64)];
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Method {
    Trigram,
    Alphabet,
    Combined,
}

impl FromStr for Method {
    // TODO: implement normal error
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().trim() {
            "trigram" => Ok(Method::Trigram),
            "alphabet" => Ok(Method::Alphabet),
            "combined" => Ok(Method::Combined),
            _ => Err(format!("Cannot obtain Method from {:?}", s)),
        }
    }
}

impl fmt::Display for Method {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let name = match self {
            Method::Trigram => "Trigram",
            Method::Alphabet => "Alphabet",
            Method::Combined => "Combined",
        };
        write!(f, "{}", name)
    }
}

pub fn detect_by_method(text: &str, method: Method) -> Option<Lang> {
    if let Some(script) = crate::detect_script(text) {
        match method {
            Method::Trigram => crate::detect_lang(text),
            Method::Alphabet => alphabet::detect_by_alphabet(text, script),
            Method::Combined => combined::detect_by_combined(text, script),
        }
    } else {
        None
    }
}

{'fraction_non_alphanumeric': 0.15525277877375404, 'fraction_numerical': 0.0014342058085335247, 'mean_word_length': 2.554140127388535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624141', 'n_tokens_mistral': 895, 'n_tokens_neox': 884, 'n_words': 203}