Crates.io | syllabize-es |
lib.rs | syllabize-es |
version | 0.5.2 |
source | src |
created_at | 2021-08-11 16:06:00.416196 |
updated_at | 2023-05-07 13:43:41.429812 |
description | Syllabize Spanish text, and much more |
homepage | |
repository | https://github.com/weiwei/syllabize-es |
max_upload_size | |
id | 434844 |
size | 56,895 |
Turns Spanish words into syllables, and much more.
The package tries to duplicate most of the functions from Silabeador TIP and provide some more:
It is tested against a comprehensive dataset, so the package should be quite reliable.
use syllabize_es::{syllable::Syllable, Word, StressType, DiphthongType, RhymeOptions};
// Convert a word into syllabized struct
let word: Word = "construir".into();
// Number of syllables
assert_eq!(word.syllables.len(), 2);
// First syllable, in string form
assert_eq!(word.syllables[0].to_string(), "cons");
// Second syllable, in struct form
assert_eq!(
word.syllables[1],
Syllable {
onset: "tr".to_string(),
nucleus: "ui".to_string(),
coda: "r".to_string()
}
);
// Get syllabified string, using "-" as delimiter
assert_eq!(word.syllabize("-"), "cons-truir");
// Index of the stressed syllable of `word.syllables`
assert_eq!(word.stress_index, 1);
// Named type of the stress
assert_eq!(word.stress(), StressType::Oxytone);
// All existing vowel combinations
let vowel_combos = word.vowel_combos();
// The word doesn't contain hiatuses or triphthongs
assert_eq!(vowel_combos.hiatuses.len(), 0);
assert_eq!(vowel_combos.triphthongs.len(), 0);
// But it contains a diphthong
assert_eq!(vowel_combos.diphthongs.len(), 1);
let dp = &vowel_combos.diphthongs[0];
// All its attributes
assert_eq!(dp.syllable_index, 1);
assert_eq!(dp.kind, DiphthongType::Homogenous);
assert_eq!(dp.composite, "ui");
// The rhyming part of the word
assert_eq!(word.rhyme(), "ir");
// The rhyming with default options `RhymeOptions { yeismo: true, seseo: false, b_equals_v: true}`
assert!(word.rhymes_with(&Word::from("ir"), None));
// Rhyming with custom options
assert!(word.rhymes_with(&Word::from("ir"), Some(RhymeOptions { yeismo: true, seseo: true, b_equals_v: true})));
// Assonant rhymes
assert!(word.assonant_rhymes_with(&Word::from("colibrí")));
$ syllabize palabra
pa-la-bra
Some attributes aren't provided because they are trivial to tell, without syllabizing a word:
Some attributes aren't provided because it's trivial to get. For example: Tonic syllable is easy to get when you have a vector of syllables and the index of the stressed syllable.
Some features may be provided in future releases, for example:
MIT.
The package is a rewriting of the NPM package silabacion, but with a simpler interface.