Skip to content

Commit

Permalink
Merge pull request #6084 from mzimandl/kw-fixes
Browse files Browse the repository at this point in the history
fix empty keywords results
  • Loading branch information
tomachalek authored Jan 8, 2024
2 parents cde9826 + a168b7e commit bea28c4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
17 changes: 11 additions & 6 deletions lib/bgcalc/keywords/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ async def keywords(corp: KCorpus, ref_corp: KCorpus, args: KeywordsFormArgs, max
attrfreq=attrfreq)
words = [x[0] for x in wl_items]

# in case no words are found return empty result
# (empty whitelist in keywords would return all words from focus corpus)
if len(words) == 0:
return []

simple_n = 1.0 # this does not apply for CNC-custom manatee-open keywords
keyword = Keyword(
corp.unwrap(), ref_corp.unwrap(), c_wl, rc_wl,
Expand All @@ -153,13 +158,13 @@ async def keywords(corp: KCorpus, ref_corp: KCorpus, args: KeywordsFormArgs, max
s = s[:-2]

if manatee_is_custom_cnc():
freqs = kw.get_freqs(2 * len([]) + 4 + 4) # 1 additional slot for size effect
freqs = kw.get_freqs(2 * len([]) + 4 + 4) # 4 additional score slots
results.append(CNCKeywordLine(
item=s,
score=filter_nan(freqs[4], 3),
logL=filter_nan(freqs[5], 3),
chi2=filter_nan(freqs[6], 3),
din=filter_nan(float(freqs[7]), 5),
score=filter_nan(freqs[4], 3), # manatee score
logL=filter_nan(freqs[5], 3), # additional logL score
chi2=filter_nan(freqs[6], 3), # additional chi2 score
din=filter_nan(float(freqs[7]), 5), # additional din score
frq1=int(freqs[0]),
frq2=int(freqs[1]),
rel_frq1=filter_nan(float(freqs[2]), 5),
Expand All @@ -170,7 +175,7 @@ async def keywords(corp: KCorpus, ref_corp: KCorpus, args: KeywordsFormArgs, max
freqs = kw.get_freqs(2 * len([]) + 4)
results.append(KeywordLine(
item=s,
score=filter_nan(kw.score, 3),
score=filter_nan(kw.score, 3), # manatee score
frq1=int(freqs[0]),
frq2=int(freqs[1]),
rel_frq1=filter_nan(float(freqs[2]), 5),
Expand Down
3 changes: 2 additions & 1 deletion public/files/js/translations/messages.cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@
"kwords__save_form_label": "Uložit klíčová slova",
"kwords__undefined_value": "N/A",
"kwords__undefined_value_explained": "Z důvodu nulové frekvence v referenčním korpusu nelze aplikovat příslušný výpočet",
"kwords__max_list_size_explained_{limit}": "Seznam je omezen na maximálně {limit, plural, one{# položku} few{# položky} other{# položek}}"
"kwords__max_list_size_explained_{limit}": "Seznam je omezen na maximálně {limit, plural, one{# položku} few{# položky} other{# položek}}",
"kwords__no_result": "Žádný odpovídající výsledek"
}
}
3 changes: 2 additions & 1 deletion public/files/js/translations/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@
"kwords__save_form_label": "Save keywords",
"kwords__undefined_value": "N/A",
"kwords__undefined_value_explained": "Due to the zero frequency in the reference corpus, the corresponding calculation cannot be applied",
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}}"
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}}",
"kwords__no_result": "No matching result"
}
}
3 changes: 2 additions & 1 deletion public/files/js/translations/messages.sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@
"kwords__save_form_label": "Save keywords UNTRANSLATED",
"kwords__undefined_value": "N/A",
"kwords__undefined_value_explained": "Due to the zero frequency in the reference corpus, the corresponding calculation cannot be applied UNTRANSLATED",
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}} UNTRANSLATED"
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}} UNTRANSLATED",
"kwords__no_result": "Ni rezultatov"
}
}
9 changes: 5 additions & 4 deletions public/files/js/translations/messages.szl.json
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,9 @@
"wordlist__minfreq_err": "Musi być użyty numer srogszy ôd zera",
"wordlist__ml_not_avail": "Niydostympne",
"wordlist__add_attr": "Przidej atrybut",
"wordlist__no_result_for_{wlpat}": "No matching result for \"{wlpat}\"",
"wordlist__create_filter_list": "Create",
"wordlist__use_ctrl_enter_for_newline": "To enter a new line, use Ctrl+ENTER",
"wordlist__no_result_for_{wlpat}": "No matching result for \"{wlpat}\" UNTRANSLATED",
"wordlist__create_filter_list": "Create UNTRANSLATED",
"wordlist__use_ctrl_enter_for_newline": "To enter a new line, use Ctrl+ENTER UNTRANSLATED",
"wordlist__pattern_empty_err": "Search pattern and/or filter words must be entered UNTRANSLATED",
"wordlist__ask_empty_pattern": "An empty query will return all the words from the corpus. Continue? UNTRANSLATED",
"wordlist__failed_to_precalculate": "Failed to create auxiliary data required for the frequency distribution calculation. Please try again later or contact system administrator. UNTRANSLATED",
Expand Down Expand Up @@ -960,6 +960,7 @@
"kwords__save_form_label": "Save keywords UNTRANSLATED",
"kwords__undefined_value": "N/A",
"kwords__undefined_value_explained": "Due to the zero frequency in the reference corpus, the corresponding calculation cannot be applied UNTRANSLATED",
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}} UNTRANSLATED"
"kwords__max_list_size_explained_{limit}": "The result list is limited to at most {limit, plural, one{# item} few{# items} other{# items}} UNTRANSLATED",
"kwords__no_result": "No matching result"
}
}
5 changes: 5 additions & 0 deletions public/files/js/views/keywords/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export function init({

const buildQ = (value:string) => `aword,[${props.attr}="${value}"]`;

if (props.data.length === 0) {
return <S.KeywordsResult>
<p className="no-result">{he.translate('kwords__no_result')}</p>
</S.KeywordsResult>
}
return (
<S.KeywordsResult>

Expand Down
7 changes: 7 additions & 0 deletions public/files/js/views/keywords/result/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export const KeywordsResult = styled.form`
.data {
margin: 1em;
}
.no-result {
margin: 1em;
padding-top: 2em;
padding-bottom: 2em;
font-size: 120%;
}
`;

// ------------------- <PaginatorWrapper /> -------------
Expand Down

0 comments on commit bea28c4

Please sign in to comment.