Repository navigation
Conversation
The old rule only broke a vowel group apart when the second vowel was an
accented high vowel or when both vowels were strong, so "ai" and "ia" were
always counted as one syllable: "rainha" gave 2 instead of 3 and
"fotografia" gave 4 instead of 5.
Track the stressed vowel and use it to decide whether a high vowel is a
nucleus or a glide:
- a high vowel that carries the stress is a nucleus ("ra-i-nha",
"fo-to-gra-fi-a", "sa-í-de");
- a stressed high vowel before a strong vowel also splits ("Ma-ri-a",
"a-tu-a");
- an unstressed high vowel after another vowel in the same group glides
onto it, so the following vowel starts a new syllable ("prai-a",
"chei-o", "sa-iu").
Rising diphthongs such as "dia", "rua", "cai" and "ria" still stay
together. The vowel groups are now index ranges so the stress can be
compared against the group, and the silent "u" of "que"/"gue"/"gui" is
dropped before counting.
Because Portuguese does not mark the stress of unaccented words, the
handful of common words where a high vowel is stressed instead of glided
("rainha", "sair", "raiz", ...) are listed in HIATUS_WORDS. Stress in
words like "criança" or "diálogo" is still lexical and stays wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #1: vowel groups are now split on hiatus when a high vowel (
i,u)carries the stress, so
rainhacounts 3 (ra-i-nha) andfotografiacounts 5 (
fo-to-gra-fi-a) instead of 2 and 4.Why
HIATUS_MARKERS = "íú"only matched an accented high vowel in secondposition, and neither
inoruis inSTRONG. So the pairai/ianeversplit, and every unaccented word with a high-vowel hiatus was undercounted.
The fix
Portuguese decides hiatus versus diphthong by whether the high vowel carries
the stress, so the counter now locates the stressed vowel first
(
stressed_vowel) and then breaks a vowel group when a high vowel is anucleus rather than a glide:
ra-i-nha,fo-to-gra-fi-a,sa-í-de,ru-ímMa-ri-a,po-e-si-a,a-tu-aprai-a,chei-o,sa-iuco-e-lho,le-ãoThree supporting changes came with it:
compared against a position inside the group;
uofque/gue/guiis dropped before counting;HIATUS_MARKERSis replaced byHIGH,STRESS_MARKandHIATUS_WORDS(the old constant is gone, since it no longer describes the rule).
Rising diphthongs are deliberately left alone:
dia,rua,pai,caixa,história,família,diabo,médioall keep their current counts, andthe existing 11 words in
test_portuguese_syllablesstill pass unchanged.Tests
test_portuguese_syllablesgains the words from the issue plus guards on bothsides of the new rule, and a new test pins the silent-
ubehaviour. The suiteis 9 runs / 60 assertions, still dependency-free and green on Ruby 3.1 and 3.3.
I also diffed the new counter against the old one over a 318-word Portuguese
word list: 32 words move to the correct count, 0 regress.
Known limits
This stays a heuristic, and two classes of word are still wrong:
words where a high vowel is stressed instead of glided are listed in
HIATUS_WORDS. That list is admittedly a stopgap; a real syllabledictionary or a stress model would replace it.
criança(cri-an-ça) versuscaixa(cai-xa),diálogo(di-á-lo-go)versus
diabo(dia-bo). Those are unchanged from before.Happy to rework any of this if you'd rather scope it differently.
Disclosure
This PR was written with AI assistance. I used
Alpha to locate the root
cause, prototype the rule set against a 318-word Portuguese word list, and
draft the patch and this description. Every change was reviewed by me before
committing, and I verified the diff is a strict improvement over the previous
counter with no regressions.