From 9a280695b413d9a2e91a75865abe2ac33c38bfd2 Mon Sep 17 00:00:00 2001 From: Jolene Poulin Date: Wed, 1 Feb 2023 16:58:08 -0700 Subject: [PATCH 1/4] checkpoint: adding standardized version --- frontend/js/orthography.js | 3 +++ .../components/definition__elaboration.html | 20 +++++-------------- src/crkLacombeeng/app/__init__.py | 0 src/crkLacombeeng/site/settings.py | 5 +++-- .../management/commands/importjsondict.py | 2 +- src/morphodict/lexicon/models.py | 2 +- src/morphodict/site/base_dir_setup.py | 2 +- 7 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 src/crkLacombeeng/app/__init__.py diff --git a/frontend/js/orthography.js b/frontend/js/orthography.js index 8773cbbee..27af211aa 100644 --- a/frontend/js/orthography.js +++ b/frontend/js/orthography.js @@ -8,6 +8,8 @@ const AVAILABLE_ORTHOGRAPHIES = new Set([ "Latn", "Latn-x-macron", "CMRO", + "Standardized", + "Original", ]); /** @@ -32,6 +34,7 @@ export function registerEventListener(csrfToken) { * Changes the orthography of EVERYTHING on the page. */ export function changeOrth(which) { + console.log(AVAILABLE_ORTHOGRAPHIES) if (!AVAILABLE_ORTHOGRAPHIES.has(which)) { throw new Error(`tried to switch to unknown orthography: ${which}`); } diff --git a/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/definition__elaboration.html b/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/definition__elaboration.html index a28476c0d..0b81418a3 100644 --- a/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/definition__elaboration.html +++ b/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/definition__elaboration.html @@ -38,12 +38,12 @@ {% if show_ic != "no" %} {{ lemma.inflectional_category }} {% endif %} + {% if lemma.show_emoji %} + + {{ emoji }}   + + {% endif %} {% if display_options.mode == 'linguistic' %} - {% if lemma.show_emoji %} - - {{ emoji }}   - - {% endif %} {% if lemma.inflectional_category_linguistic %} {{ lemma.inflectional_category_linguistic }} ({{ lemma.inflectional_category }}) @@ -58,11 +58,6 @@ {% endif %} {% if display_options.mode == 'english' %} - {% if lemma.show_emoji %} - - {{ emoji }}   - - {% endif %} {% if lemma.inflectional_category_linguistic %} {% relabel_plain_english lemma.inflectional_category %} @@ -77,11 +72,6 @@ {% endif %} {% if display_options.mode == 'source_language' %} - {% if lemma.show_emoji %} - - {{ emoji }}   - - {% endif %} {% if lemma.inflectional_category_linguistic %} {% relabel_source lemma.inflectional_category %} diff --git a/src/crkLacombeeng/app/__init__.py b/src/crkLacombeeng/app/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/crkLacombeeng/site/settings.py b/src/crkLacombeeng/site/settings.py index 0d3e71bf7..2f91aacfc 100644 --- a/src/crkLacombeeng/site/settings.py +++ b/src/crkLacombeeng/site/settings.py @@ -43,8 +43,9 @@ MORPHODICT_PREVIEW_WARNING = False MORPHODICT_ORTHOGRAPHY = { - "default": "Latn", + "default": "Original", "available": { - "Latn": {"name": "Latin"}, + "Original": {"name": "Original", "converter": "crkLacombeeng.app.orthography.to_original"}, + "Standardized": {"name": "Standardized", "converter": "crkLacombeeng.app.orthography.to_standardized"} }, } diff --git a/src/morphodict/lexicon/management/commands/importjsondict.py b/src/morphodict/lexicon/management/commands/importjsondict.py index 8a28474f2..bd7816446 100644 --- a/src/morphodict/lexicon/management/commands/importjsondict.py +++ b/src/morphodict/lexicon/management/commands/importjsondict.py @@ -350,7 +350,7 @@ def run(self): slug=entry["slug"], rw_domains=rw_domains, rw_indices=rw_indices, - wn_synsets=wn_synsets, + wn_synsets_string=wn_synsets, is_lemma=True, linguist_info=entry.get("linguistInfo", {}), import_hash=freshness_check.importjson_hash_for_slug(entry["slug"]), diff --git a/src/morphodict/lexicon/models.py b/src/morphodict/lexicon/models.py index 4b2ee3d19..2121aa0eb 100644 --- a/src/morphodict/lexicon/models.py +++ b/src/morphodict/lexicon/models.py @@ -132,7 +132,7 @@ class Wordform(models.Model): """ ) - wn_synsets = models.CharField( + wn_synsets_string = models.CharField( max_length=2048, blank=True, null=True, diff --git a/src/morphodict/site/base_dir_setup.py b/src/morphodict/site/base_dir_setup.py index bd9446d7b..0bd7d84ad 100644 --- a/src/morphodict/site/base_dir_setup.py +++ b/src/morphodict/site/base_dir_setup.py @@ -18,6 +18,6 @@ def get_base_dir() -> Path: def set_base_dir(dir: Path): global _base_dir - # assert _base_dir is None, "base_dir is already set!" + assert _base_dir is None, "base_dir is already set!" assert dir.is_dir() _base_dir = dir From e2175f366769257e1d530a8692401ce149458fbd Mon Sep 17 00:00:00 2001 From: Jolene Poulin Date: Fri, 3 Feb 2023 11:33:36 -0700 Subject: [PATCH 2/4] feat: convert definition in case they're different --- .../components/search-result.html | 2 +- .../templatetags/morphodict_orth.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/search-result.html b/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/search-result.html index 5b9477c9c..771bc3bf4 100644 --- a/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/search-result.html +++ b/src/CreeDictionary/CreeDictionary/templates/CreeDictionary/components/search-result.html @@ -57,7 +57,7 @@ {# These are the definitions for the inflection (non-lemma), could be empty #}
    {% for def in result.definitions %} -
  1. {{ def.text }} +
  2. {% convert def.text %} {% include "CreeDictionary/components/citations.html" with dictionary_sources=def.source_ids %}
  3. {% endfor %} diff --git a/src/CreeDictionary/morphodict/templatetags/morphodict_orth.py b/src/CreeDictionary/morphodict/templatetags/morphodict_orth.py index e7f22075e..478af3496 100644 --- a/src/CreeDictionary/morphodict/templatetags/morphodict_orth.py +++ b/src/CreeDictionary/morphodict/templatetags/morphodict_orth.py @@ -2,6 +2,7 @@ from django.conf import settings from django.utils.html import format_html +from morphodict.lexicon.models import Definition from ..orthography import ORTHOGRAPHY register = template.Library() @@ -74,3 +75,25 @@ def current_orthography_name(context): # Determine the currently requested orthography: request_orth = ORTHOGRAPHY.from_request(context.request) return ORTHOGRAPHY.name_of(request_orth) + + +@register.simple_tag(name="convert", takes_context=True) +def convert_to_standardized(context, definition: str): + if settings.MORPHODICT_DICTIONARY_NAME == "Lacombe": + orth = context.request.COOKIES.get("orth") + if orth == "Original": + return definition + d = Definition.objects.filter(text=definition).first() + if not d: + return definition + wf = d.wordform + if not wf: + return definition + + if wf.linguist_info: + if "standardized" in wf.linguist_info: + return wf.linguist_info["standardized"]["senses"][0]["definition"] + else: + return definition + + return definition From eff8ade256b557032961f9ced373e19c54ff75c0 Mon Sep 17 00:00:00 2001 From: Jolene Poulin Date: Fri, 3 Feb 2023 16:03:45 -0700 Subject: [PATCH 3/4] remove: console log --- frontend/js/orthography.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/js/orthography.js b/frontend/js/orthography.js index 27af211aa..32ebb5805 100644 --- a/frontend/js/orthography.js +++ b/frontend/js/orthography.js @@ -34,7 +34,6 @@ export function registerEventListener(csrfToken) { * Changes the orthography of EVERYTHING on the page. */ export function changeOrth(which) { - console.log(AVAILABLE_ORTHOGRAPHIES) if (!AVAILABLE_ORTHOGRAPHIES.has(which)) { throw new Error(`tried to switch to unknown orthography: ${which}`); } From a523fb49d06918d05bafa9a1acb5e60a219cb12a Mon Sep 17 00:00:00 2001 From: Jolene Poulin Date: Fri, 3 Feb 2023 16:11:08 -0700 Subject: [PATCH 4/4] remove: line causing tests to break --- src/morphodict/site/base_dir_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/morphodict/site/base_dir_setup.py b/src/morphodict/site/base_dir_setup.py index 0bd7d84ad..bd9446d7b 100644 --- a/src/morphodict/site/base_dir_setup.py +++ b/src/morphodict/site/base_dir_setup.py @@ -18,6 +18,6 @@ def get_base_dir() -> Path: def set_base_dir(dir: Path): global _base_dir - assert _base_dir is None, "base_dir is already set!" + # assert _base_dir is None, "base_dir is already set!" assert dir.is_dir() _base_dir = dir