Class: Kotoshu::Language::Normalizer::Hebrew
- Defined in:
- lib/kotoshu/language/normalizer/hebrew.rb
Overview
Normalizer for Hebrew script.
Modern Hebrew is typically written without niqqud (vowel points); spell-checking dictionaries store the bare consonant form. This normalizer:
- Applies NFC composition.
- Strips niqqud (U+05B0..U+05BC range, plus geresh/gershayim when used as vowel marks — keeps them when used as punctuation).
- Optionally strips dagesh (U+05BC) — a dot inside a letter that affects pronunciation but is not represented in bare dictionary entries.
- Normalizes the maqaf (U+05BE, Hebrew hyphen) to ASCII hyphen for consistent tokenization.
Constant Summary collapse
- NIKKUD_AND_CANTILLATION =
Niqqud + cantillation marks. Hebrew points range U+0591 (etnahta) through U+05BD (meteg). Plus geresh (U+05F3), gershayim (U+05F4) when used as accents. Plus paseq (U+05C0), sof-pasuq (U+05C3), upper dot (U+05C4), lower dot (U+05C5), qamats qatan (U+05C7), and raph (U+05BF). Shin dot (U+05C1) and sin dot (U+05C2) are included so שׁ and שׂ both normalize to ש. Dagesh (U+05BC) is handled separately so callers can keep it.
/[֑-ֻֽֿ׀-ׇׂׅׄ]/- DAGESH =
"ּ"- MAQAF =
"־"
Instance Method Summary collapse
-
#initialize(strip_dagesh: true, normalize_maqaf: true) ⇒ Hebrew
constructor
A new instance of Hebrew.
-
#normalize(text, _options = {}) ⇒ String
Normalize text: NFC + niqqud stripping + optional dagesh stripping + maqaf normalization.
- #normalize_word(word) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(strip_dagesh: true, normalize_maqaf: true) ⇒ Hebrew
Returns a new instance of Hebrew.
44 45 46 47 |
# File 'lib/kotoshu/language/normalizer/hebrew.rb', line 44 def initialize(strip_dagesh: true, normalize_maqaf: true) @strip_dagesh = strip_dagesh @normalize_maqaf = normalize_maqaf end |
Instance Method Details
#normalize(text, _options = {}) ⇒ String
Normalize text: NFC + niqqud stripping + optional dagesh stripping + maqaf normalization. Skips Base's downcase step because Hebrew has no case.
56 57 58 59 60 61 62 63 64 |
# File 'lib/kotoshu/language/normalizer/hebrew.rb', line 56 def normalize(text, = {}) return "" if text.nil? || text.empty? result = text.unicode_normalize(:nfc) result = result.gsub(NIKKUD_AND_CANTILLATION, "") result = result.delete(DAGESH) if @strip_dagesh result = result.tr(MAQAF, "-") if @normalize_maqaf result.strip end |
#normalize_word(word) ⇒ Object
66 67 68 |
# File 'lib/kotoshu/language/normalizer/hebrew.rb', line 66 def normalize_word(word) normalize(word) end |