Text

Stop words

Stop words of 58 languages (the, and, of; le, et, de), and text with them taken out, for search queries, keywords and tag clouds.

Version 1.0.0 · 4 functions · 1 crate

#search#text#languages#keywords

Functions

What use stopwords.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use stopwords_list, stopwords_is from stopwords (Quillo 0.6).

stopwords_list(language: str) → listor an error

The stop words of language, a two-letter code ("en", "fr", "de", "es", "ja"...), in lower case.

stopwords_is(word: str, language: str) → boolor an error

Whether word is a stop word of language, case ignored.

stopwords_remove(text: str, language: str) → listor an error

The words of text that are not stop words, in order, as written: the text split at anything but letters, digits, ' and -. Up to 1 MB.

stopwords_languages() → list

The languages there are, as codes.

Get it

$ quillo install stopwords               # stopwords.qwer into this folder$ quillo install stopwords --example     # and its example, stopwords.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/stopwords.qwer$ curl -O https://quillolang.org/plugins/files/stopwords.qwe

Then, in your program, all of it or only what you call:

main.qwe
use stopwords.qweruse stopwords_list, stopwords_is from stopwords      // Quillo 0.6: only these

It uses this crate, which cargo fetches the first time the plugin is built:

[dependencies]
stop-words = "0.10"

Example

stopwords.qwe
// A search box that ignores "the", "a" and "of", and a word count of what is left.////   quillo run stopwords.qwe      then open http://localhost:8080/query?q=the%20history%20of%20the%20roman%20empireuse "stopwords.qwer"route GET /query ? { q: str, lang: str = "en" } = { terms: stopwords_remove(q, lang)? }route GET /french = { terms: stopwords_remove("Le petit prince et la rose de son astéroïde", "fr")?, is_stop: stopwords_is("Les", "fr")? }route GET /languages = { count: len(stopwords_languages()), english: len(stopwords_list("en")?) }
$ quillo run stopwords.qwe$ curl 'localhost:8080/query?q=the%20history%20of%20the%20roman%20empire'$ curl 'localhost:8080/french'

Source

stopwords.qwer
//! Stop words ("the", "and", "of"; "le", "et", "de") of 50+ languages, and text with them taken out, for search, keywords and tag clouds.//! version: 1.0.0//!//! [dependencies]//! stop-words = "0.10"use std::collections::HashSet;fn words(language: &str) -> Result<&'static [&'static str], String> {    let l = language.trim().to_lowercase();    stop_words::lookup(if l.is_empty() { "en" } else { &l }).ok_or_else(|| format!("no stop words for {:?}; see stopwords_languages()", language))}/// The stop words of `language`, a two-letter code ("en", "fr", "de", "es", "ja"...), in lower case.pub fn stopwords_list(language: &str) -> Result<Vec<String>, String> {    Ok(words(language)?.iter().map(|w| w.to_string()).collect())}/// Whether `word` is a stop word of `language`, case ignored.pub fn stopwords_is(word: &str, language: &str) -> Result<bool, String> {    Ok(words(language)?.contains(&word.trim().to_lowercase().as_str()))}/// The words of `text` that are not stop words, in order, as written: the text split at anything but letters, digits, `'` and `-`. Up to 1 MB.pub fn stopwords_remove(text: &str, language: &str) -> Result<Vec<String>, String> {    if text.len() > 1_000_000 {        return Err("text up to 1 MB".into());    }    let set: HashSet<&str> = words(language)?.iter().copied().collect();    Ok(text        .split(|c: char| !(c.is_alphanumeric() || c == '\'' || c == '’' || c == '-'))        .map(|w| w.trim_matches(|c: char| c == '\'' || c == '’' || c == '-'))        .filter(|w| !w.is_empty() && !set.contains(w.to_lowercase().as_str()))        .map(String::from)        .collect())}/// The languages there are, as codes.pub fn stopwords_languages() -> Vec<String> {    stop_words::available_languages().iter().map(|s| s.to_string()).collect()}
Thread
79Useful? Like it, or add to its thread below.

Thread 0 posts

On Stop words: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.