stop_words/lib.rs
1#![warn(clippy::all)]
2#![warn(missing_docs)]
3#![warn(clippy::missing_docs_in_private_items)]
4#![doc = include_str!("../README.md")]
5
6mod language_names;
7pub use crate::language_names::LANGUAGE;
8
9#[allow(clippy::missing_docs_in_private_items)]
10mod generated {
11 include!(concat!(env!("OUT_DIR"), "/stopwords.rs"));
12}
13
14use crate::generated::lookup;
15
16/// This function fetches stop words for a language using either a member of the `LANGUAGE` enum
17/// or a lookup code as any type implementing [`std::convert::AsRef`]`<str>`.
18/// For most languages the lookup code is a two-character ISO 639-1 code.
19/// Constructed languages use three-character codes (`dot`, `dov`, `nav`, `qya`, `sjn`, `tlh`,
20/// `val`), and NLTK-specific `hinglish` is supported when the `nltk` feature is enabled.
21/// ```ignore
22/// let first_list = stop_words::get("ar");
23/// let second_list = stop_words::get(stop_words::LANGUAGE::Arabic);
24/// assert_eq!(first_list, second_list)
25/// ```
26/// # Panics
27///
28/// Panics if the provided language code is not recognized.
29pub fn get<T: std::convert::AsRef<str>>(input_language: T) -> &'static [&'static str] {
30 let language_name: &str = input_language.as_ref();
31 lookup(language_name).unwrap_or_else(|| {
32 panic!(
33 "The '{language_name}' language is not recognized. Please check the documentation for a supported list of languages."
34 )
35 })
36}