Skip to content

Commit 34f627d

Browse files
author
David Klinger
committedNov 4, 2022
making і & ї and г & ґ count as the same letter
1 parent 187a21e commit 34f627d

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed
 

‎etl/dictionary.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,10 @@ def make_index(self, loc1, loc2, indent=None):
648648
def_words = usage.get_definition_words()
649649
form_words = usage.get_form_words() + re.sub(r"[^\w']+", ' ', word.get_word_no_accent()).strip().split()
650650
for d in def_words:
651-
d = d.lower()
651+
d = d.lower().replace('ї', 'і').replace('ґ', 'г')
652652
word_index[d].add(i)
653653
for f in form_words:
654-
f = f.lower()
654+
f = f.lower().replace('ї', 'і').replace('ґ', 'г')
655655
word_index[f].add(i)
656656

657657
word_index_list = {}

‎index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ var main = (data, increase) => {
302302
const highlightFunc = (t) => {
303303

304304
const find = (word, phrase, literal, mustPreceed) => {
305+
console.log(word, phrase)
305306
const letters = 'abcdefghijklmnopqrstuvwxyzабвгдежзийклмнопрстуфхцчшщъыьэюяєії'
306307
let index = 0;
307308
let parenthesis = 0;
@@ -318,7 +319,7 @@ var main = (data, increase) => {
318319
const beforeClear = isBeginning || !letters.includes(phrase[i - 1].toLowerCase());
319320
const afterClear = isEnd || !letters.includes(phrase[i + 1].toLowerCase());
320321

321-
const isWordMatch = thisLetter.toLowerCase() === word[index];
322+
const isWordMatch = thisLetter.toLowerCase().replaceAll('ї', 'і').replaceAll('ґ', 'г') === word[index];
322323
const isAccent = thisLetter === "́";
323324

324325
if (index === 0) {
@@ -532,10 +533,11 @@ function searchHelper() {
532533
}
533534
let indexes;
534535
const canInclude = fuzzyWords.length === 1 && fuzzyWords[0].replace(/[^a-z]/g, '').length === 0;
535-
for (const word of fuzzyWords) {
536+
for (let word of fuzzyWords) {
536537
if (!word) break;
537538
// generate words containing all searched letters
538539
let wordIndexes;
540+
word = word.replaceAll('ї', 'і').replaceAll('ґ', 'г')
539541
for (const l of new Set(word)) {
540542
if (!wordIndexes) wordIndexes = wordDict[l];
541543
else {
@@ -564,9 +566,10 @@ function searchHelper() {
564566
}
565567
}
566568
console.log(literalWords)
567-
for (const word of literalWords) {
569+
for (let word of literalWords) {
568570
if (!word) break;
569571
// generate words containing all searched letters
572+
word = word.replaceAll('ї', 'і').replaceAll('ґ', 'г')
570573
let wordIndexes;
571574
for (const l of new Set(word)) {
572575
if (!wordIndexes) wordIndexes = wordDict[l];
@@ -607,7 +610,7 @@ function searchHelper() {
607610
else if (l === ')') paren--;
608611
else if (paren === 0) noParen += l;
609612
}
610-
return noParen.toLowerCase().includes(literalRes)
613+
return noParen.toLowerCase().replace('ї', 'і').replace('ґ', 'г').includes(literalRes)
611614
}
612615

613616
const unpack = (y) => {
@@ -624,8 +627,8 @@ function searchHelper() {
624627
let goodData = d3.filter(
625628
allData,
626629
x => (
627-
d3.filter(x.defs, filterFunc) + d3.filter(unpack(x.forms), y => { return y.replaceAll('\u0301', '') === literalRes; } )
628-
).length > 0 || x.word.replaceAll('\u0301', '') === literalRes
630+
d3.filter(x.defs, filterFunc) + d3.filter(unpack(x.forms), y => { return y.replaceAll('\u0301', '').replaceAll('ї', 'і').replaceAll('ґ', 'г') === literalRes; } )
631+
).length > 0 || x.word.replaceAll('\u0301', '').replaceAll('ї', 'і').replaceAll('ґ', 'г') === literalRes
629632
).map(x => x.index)
630633

631634
const _indexes = d3.filter(Array.from(indexes), x => goodData.includes(x))
@@ -660,8 +663,9 @@ function search(changeURL = true) {
660663
const letters = "abcdefghijklmnopqrstuvwxyzабвгдежзийклмнопрстуфхцчшщъыьэюяєіїґ '\""
661664
const oldSearch = searchTerm;
662665
searchTerm = document.querySelector('input#search').value.toLowerCase();
663-
searchTerm = searchTerm.replace('“', '"').replace('”', '"').replace('«', '"').replace('»', '"')
664-
searchTerm = searchTerm.replace('‘', "'").replace('’', "'").replace('‛', "'")
666+
searchTerm = searchTerm.replaceAll('“', '"').replaceAll('”', '"').replaceAll('«', '"').replaceAll('»', '"')
667+
searchTerm = searchTerm.replaceAll('‘', "'").replaceAll('’', "'").replaceAll('‛', "'")
668+
searchTerm = searchTerm.replaceAll('ї', 'і').replaceAll('ґ', 'г') // letter normalization
665669
let newSearchTerm = ''
666670
for (const s of searchTerm) { if (letters.includes(s)) newSearchTerm += s; }
667671
searchTerm = newSearchTerm;

‎index.json

+1-1
Large diffs are not rendered by default.

‎word_dict.json

+1-1
Large diffs are not rendered by default.

‎words.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.