Skip to content

Commit

Permalink
Don't append classifier and alternates to definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustaf-C committed Nov 15, 2023
1 parent c4ff0ee commit 4dc661e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
25 changes: 7 additions & 18 deletions chinese/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@
)


def get_classifier(hanzi, note):
cs = dictionary.get_classifiers(hanzi)
text = ', '.join(colorize_dict(c) for c in cs)
if text and not has_any_field(config['fields']['classifier'], note):
return '<br>Cl: ' + text
return ''


def fill_classifier(hanzi, note):
cs = dictionary.get_classifiers(hanzi)
text = ', '.join(colorize_dict(c) for c in cs)
Expand All @@ -59,20 +51,17 @@ def fill_classifier(hanzi, note):
return filled


def get_alt(hanzi, note):
def fill_alt(hanzi, note):
alts = dictionary.get_variants(hanzi)
alt = ', '.join(colorize_dict(a) for a in alts)
if alt:
if not has_any_field(config['fields']['alternative'], note):
return '<br>Also written: ' + alt
if get_first(config['fields']['alternative'], note) == '':
set_all(config['fields']['alternative'], note, to=alt)
return ''
filled = False
if alt and has_any_field(config['fields']['alternative'], note):
set_all(config['fields']['alternative'], note, to=alt)
filled = True
return filled


def fill_def(hanzi, note, lang):
classifier = get_classifier(hanzi, note)
alt = get_alt(hanzi, note)
field = {'en': 'english', 'de': 'german', 'fr': 'french'}[lang]
filled = False

Expand All @@ -83,7 +72,6 @@ def fill_def(hanzi, note, lang):
if get_first(config['fields'][field], note) == '':
definition = translate(hanzi, lang).removesuffix('\n<br>')
if definition:
definition += classifier + alt
set_all(config['fields'][field], note, to=definition)
filled = True

Expand Down Expand Up @@ -311,6 +299,7 @@ def update_fields(note, focus_field, fields):

if focus_field in config['fields']['hanzi']:
if copy[focus_field]:
fill_alt(hanzi, copy)
fill_all_defs(hanzi, copy)
fill_classifier(hanzi, copy)
fill_transcript(hanzi, copy)
Expand Down
19 changes: 4 additions & 15 deletions tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,27 +440,16 @@ def test_trailing_new_line_removed(self):

class FillAllDefs(Base):

def test_no_classifier_field(self):
def test_fill_all_defs(self):
note = dict.fromkeys(['English', 'German', 'French'], '')
classifier = (
'<span class="tone1"><ruby>家<rt>jiā</rt></ruby></span>, '
'<span class="tone4"><ruby>個<rt>gè</rt></ruby></span>|'
'<span class="tone4">个</span>'
)
english = ' \tlibrary<br>Cl: ' + classifier
german = ' \tBibliothek (S, Lit)<br>Cl: ' + classifier
french = ' \tbibliothèque (lieu)<br>Cl: ' + classifier
english = ' \tlibrary'
german = ' \tBibliothek (S, Lit)'
french = ' \tbibliothèque (lieu)'
self.assertEqual(fill_all_defs('图书馆', note), 3)
self.assertEqual(note['English'], english)
self.assertEqual(note['French'], french)
self.assertEqual(note['German'], german)

def test_classifier_field(self):
note = dict.fromkeys(['Classifier', 'English'], '')
self.assertEqual(fill_all_defs('图书馆', note), 1)
self.assertEqual(note['Classifier'], '')
self.assertEqual(note['English'], ' \tlibrary')


class FillClassifier(Base):
def test_fill_classifier(self):
Expand Down

0 comments on commit 4dc661e

Please sign in to comment.