visaruruqi opened a new pull request, #16957:
URL: https://github.com/apache/lucene/pull/16957

   ### Description
   
   ### What
   
   A new language package `org.apache.lucene.analysis.sq` in 
`lucene/analysis/common`, laid out like
   the existing `bg` / `hu` / `fa` packages:
   
   | Type | Purpose |
   |---|---|
   | `AlbanianAnalyzer` | `StandardTokenizer` → `LowerCaseFilter` → 
`AlbanianNormalizationFilter` → `StopFilter` → (`SetKeywordMarkerFilter`) → 
`AlbanianLightStemFilter`; `normalize()` applies lower-casing and the 
normalization filter to query terms |
   | `AlbanianNormalizer` / `AlbanianNormalizationFilter` / 
`AlbanianNormalizationFilterFactory` (`albanianNormalization`) | Folds `ë→e`, 
`ç→c` (precomposed or written with combining marks), the Gheg circumflex and 
acute vowels (`âsht`, `Malcís`), drops elided one-letter clitics (`ç'është` → 
`është`, `s'ka` → `ka`) and other in-word apostrophes (`Kur'an` → `kuran`). 
Both spellings are in everyday use, so they have to index to the same term. The 
factory overrides `normalize()` so multi-term queries are folded too. |
   | `AlbanianLightStemmer` / `AlbanianLightStemFilter` / 
`AlbanianLightStemFilterFactory` (`albanianLightStem`) | Light suffix-stripping 
stemmer (details below). |
   | `stopwords.txt` | Default stop word list (see sources). |
   
   Both factories are registered in `META-INF/services` and in 
`module-info.java`
   (`exports` + `provides`), and `CHANGES.txt` has a "New Features" entry for 
12.0.0 (to be
   prefixed with this PR's `GITHUB#` number once it exists).
   
   ### Why
   
   Albanian (`sq`) is spoken by about 7.5 million people and has no analyzer in 
Lucene, Snowball or
   Elasticsearch/OpenSearch today. Its nouns inflect for definiteness, number 
and case with stacked
   endings (`shtëpi / shtëpia / shtëpinë / shtëpisë / shtëpive`), its verbs 
have a large regular
   paradigm, and the two non-ASCII letters `ë` and `ç` are routinely dropped in 
informal text and
   queries, so `StandardAnalyzer` recall is poor.
   
   ### Design and sources
   
   - **Stemmer algorithm**: longest-match suffix removal with a minimum 
remaining stem of 3
     characters, repeated until no ending matches, then one productive 
derivational suffix, then
     inflection again; a final step undoes two regular stem alternations 
(ë-syncope `libër / libri`,
     `-ëm / -izëm`, and palatal plurals `miq → mik`, `zogj → zog`, `popull → 
popuj`). The whole thing
     repeats to a fixpoint, which also makes the stemmer idempotent. This is 
the approach of the two
     published Albanian stemmers:
     - N. N. Karanikolas, *Bootstrapping the Albanian Information Retrieval*, 
4th Balkan Conference
       in Informatics, 2009 (longest-match suffix removal, "at least remain 
letters" condition,
       second-pass removal).
     - J. Sadiku, M. Biba, *A Novel Stemming Algorithm for Albanian in a Data 
Mining Approach for
       Document Classification*, 2012 ("JStem", rule-based affix removal).
   
     Neither has public source code, so the rule tables were derived from the 
regular paradigms of
     Standard Albanian (Newmark, Hubbard & Prifti, *Standard Albanian: A 
Reference Grammar for
     Students*, 1982) and the declension/conjugation tables of the English 
Wiktionary: definite and
     case endings of nouns, regular plurals, feminine adjectives, and the 
endings of the regular verb
     classes in the active and passive voice. The style follows the UniNE light 
stemmers already in
     the module (`HungarianLightStemmer` etc.). Ambiguous endings carry context 
guards (`-et` after
     `-itet`, `-ive` after `t`/`s`, `-së`/`-s` only after `i`, `-nim/-ni/-sh` 
only after a consonant,
     `-të/-t` only after a palatal plural, `-tor` only as `-ëtor`); each one is 
documented in the
     Javadoc of `isInflection` / `isDerivation` with the words that motivated 
it.
   - **Stop words**: the Albanian list shipped by spaCy 
(`spacy/lang/sq/stop_words.py`, MIT), which
     credits `andrixh/index-albanian` (MIT). That list is written without 
diacritics; the
     standard-orthography spellings are added so the list also works without 
the normalization
     filter, plus a documented block of Gheg (northern dialect) and colloquial 
forms: the Gheg
     "to be"/"to have" (`âsht`, `kena`, `kan`, `jan`, `ke`), entries with their 
unstressed ë dropped
     (`shum`, `gjith`, `kta`, `ktu`, `nji`) and the common Gheg function words 
(`tash`, `qysh`,
     `kah`, `mas`, `veç`, `hala`, `hiq`, `çka`). The file header records the 
provenance and license.
   - **Gheg**: the northern dialect is in daily use in Kosovo and northern 
Albania, so its systematic
     differences are handled: nasal/long vowels written with circumflex or 
acute (`âsht`, `Malcís`),
     the participle in `-ue/-u/-un` (`punue`, `hapun`), the imperfect in 
`-ojsha`, the genitive in
     `-s` (`shpis`) and the elided clitics (`n'shpi`, `t'ndihmue`).
   - **Normalization**: ë/ç folding is applied before stop words and stemming, 
so the stop list and
     the suffix tables need only the folded spelling.
   
   ### How the rules were validated
   
   - **Dictionary paradigms.** The declension/conjugation tables of 1,680 
Albanian lemmas in the
     English Wiktionary (1,141 nouns, 128 adjectives, 411 verbs) were pulled 
and every form of a
     lemma was stemmed. All forms land on one stem for 95 % of nouns, 86 % of 
adjectives and 55 %
     of verbs; the rest are suppletive or stem-changing words (`njeri/njerëz`, 
`natë/net`,
     `bredh/bridh/brodh`), 2-letter stems, and the admirative mood of 
consonant-stem verbs (`hapka`),
     which is left out on purpose because `-ka/-kan` would cut into `bankë` and 
`Ballkan`. Regular
     `-oj` verbs conflate across all 80+ forms of their table, admirative 
included.
   - **Corpus stress test.** 25 long Albanian Wikipedia articles (~94k tokens, 
16k distinct words)
     and a Qur'an translation (11k distinct words) were stemmed and the largest 
stem buckets
     inspected for wrong conflations; that is where the guards for `-tet`, 
`-ive`, `-së`,
     `-ove/-ova`, `-nte`, `-ne` and `-nim/-nit/-nin` come from.
   - **Regression vocabulary.** `sqlighttestdata.zip` holds 45,687 word/stem 
pairs from those
     sources (`TestAlbanianLightStemFilter.testVocabulary`), in the same format 
as
     `hulighttestdata.zip`.
   - **Idempotency.** `stem(stem(w)) == stem(w)` for every word in that 
vocabulary
     (`testIdempotent` covers the cases that used to break it).
   
   ### Tests
   
   `lucene/analysis/common/src/test/org/apache/lucene/analysis/sq/`:
   
   - `TestAlbanianAnalyzer`: stop words (both spellings), custom stop words, 
reuse, normalization,
     `normalize()`, stem exclusion set, random strings, and sentences from 
Rilindja poetry, Gheg
     literature and everyday Gheg, the Constitution of Kosovo and the Universal 
Declaration of Human
     Rights, Albanian Wikipedia, and a Qur'an translation.
   - `TestAlbanianNormalizer`: diacritics, combining marks, Gheg vowels, the 
three apostrophe code
     points, elided clitics, unchanged words, empty term.
   - `TestAlbanianLightStemFilter`: the full vocabulary, masculine / feminine / 
syncopated / palatal
     / `-itet` / `-izëm` / `-ëm` nouns and the rarer plural classes, `-tor` 
loanwords, `-iv`
     adjectives, `-së`, place names, adjectives, class 1 / `-uaj` / class 2 
verbs, the passive,
     derivation, Gheg verbs and nouns, words in `-o`, short words, idempotency, 
keyword marker,
     empty term.
   - `TestAlbanianNormalizationFilterFactory`, 
`TestAlbanianLightStemFilterFactory`: SPI lookup by
     name and bogus-argument rejection.
   
   ```
   ./gradlew :lucene:analysis:common:test --tests 
"org.apache.lucene.analysis.sq.*"
   :lucene:analysis:common:test (SUCCESS): 51 tests
   ./gradlew :lucene:analysis:common:check
   :lucene:analysis:common:test (SUCCESS): 1960 tests, 18 skipped
   BUILD SUCCESSFUL (checkGoogleJavaFormat, ecjLint, forbiddenApis, 
checkLicenses)
   ```
   
   `:lucene:analysis:common:renderJavadoc` passes as well, and the `prek` 
precommit hooks that apply
   to these files (trailing whitespace, EOF newline, line endings, `typos`) are 
clean; the only
   spell-checker hit was the translator's name Sherif Ahmeti in a test Javadoc, 
which carries a
   `spellchecker:ignore-next-line` directive.
   
   ### Known limits
   
   Irregular plurals with stem changes (`njeri/njerëz`, `mbret/mbretër`) and 
suppletive verbs
   (`shoh/pashë`, `them/tha`) are not conflated; the admirative of 
consonant-stem verbs (`hapka`)
   is left out on purpose. The class 2 imperfect plural, the 2nd person 
`-ni`/`-sh`, the optative,
   `-së`/`-s`, `-ive`, `-et` after `-itet`, `-ve` after a vowel and `-të`/`-t` 
are only removed in
   the contexts listed above, because without the guard they cut into common 
nouns, adjectives and
   place names (`Kuranit`, `Kosovë`, `veçantë`, `e drejtë`, `aktive`, 
`universitet`). It is a light
   stemmer, like `bg` / `hu`.
   
   ### Relation to Lucene.NET
   
   The same analyzer, with the same rule tables, stop word list and 45,687-word 
regression
   vocabulary, was submitted to Lucene.NET as apache/lucenenet#1535. This is a 
line-by-line port of
   that C# code to Java; the only differences are the ones the Java API calls 
for (no
   `StandardFilter`, `Analyzer.normalize()` and 
`TokenFilterFactory.normalize()` overrides instead
   of `IMultiTermAwareComponent`, the factory `NAME` constants and the default 
SPI constructor,
   `module-info` registration). The two implementations are meant to stay in 
sync.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to