Skip to content

Commit

Permalink
Moved utils to morphodict
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Oct 18, 2024
1 parent 926e9a6 commit 2cb7897
Show file tree
Hide file tree
Showing 89 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from functools import cache

from CreeDictionary.utils import shared_res_dir
from CreeDictionary.utils.types import ConcatAnalysis
from morphodict.utils import shared_res_dir
from morphodict.utils.types import ConcatAnalysis

CORPUS_FREQUENCY_FILE = shared_res_dir / "corpus_frequency.txt"

Expand Down
2 changes: 1 addition & 1 deletion src/CreeDictionary/CreeDictionary/paradigm/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ParadigmManager,
ParadigmManagerWithExplicitSizes,
)
from CreeDictionary.utils import shared_res_dir
from morphodict.utils import shared_res_dir
from morphodict.site.util import cache_unless


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
observed_wordforms,
)
from morphodict.relabelling import read_labels
from CreeDictionary.CreeDictionary.utils import url_for_query
from morphodict.utils import url_for_query
from CreeDictionary.morphodict.templatetags.morphodict_orth import orth_tag
from morphodict.lexicon.models import Wordform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from morphodict.relabelling import read_labels
from CreeDictionary.morphodict.templatetags.morphodict_orth import orth_tag
from CreeDictionary.utils.types import FSTTag
from morphodict.utils.types import FSTTag
from crkeng.app.preferences import DisplayMode

logger = logging.getLogger(__name__)
Expand Down
18 changes: 0 additions & 18 deletions src/CreeDictionary/CreeDictionary/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,3 @@
Utilities that depend on the CreeDictionary Django application.
"""

from urllib.parse import ParseResult, urlencode, urlunparse

from django.urls import reverse


def url_for_query(user_query: str) -> str:
"""
Produces a relative URL to search for the given user query.
"""
parts = ParseResult(
scheme="",
netloc="",
params="",
path=reverse("cree-dictionary-search"),
query=urlencode((("q", user_query),)),
fragment="",
)
return urlunparse(parts)
2 changes: 1 addition & 1 deletion src/CreeDictionary/CreeDictionary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from .paradigm.manager import ParadigmDoesNotExistError
from .paradigm.panes import Paradigm, WordformCell
from .utils import url_for_query
from morphodict.utils import url_for_query

# The index template expects to be rendered in the following "modes";
# The mode dictates which variables MUST be present in the context.
Expand Down
2 changes: 1 addition & 1 deletion src/CreeDictionary/morphodict/paradigms.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# todo:
1# todo:
# define a specification that other language specific apps implement to produce paradigms.
2 changes: 1 addition & 1 deletion src/CreeDictionary/phrase_translate/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
verb_wordform_to_phrase,
)

from CreeDictionary.utils.shared_res_dir import shared_fst_dir
from morphodict.utils.shared_res_dir import shared_fst_dir

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
translate_single_definition,
TranslationStats,
)
from CreeDictionary.utils.english_keyword_extraction import stem_keywords
from morphodict.utils.english_keyword_extraction import stem_keywords
from morphodict.analysis import RichAnalysis, strict_generator
from morphodict.lexicon import DEFAULT_IMPORTJSON_FILE
from morphodict.lexicon.management.commands.buildtestimportjson import entry_sort_key
Expand Down
4 changes: 2 additions & 2 deletions src/morphodict/lexicon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from django.urls import reverse
from django.utils.functional import cached_property

from morphodict.search.serializer import SerializedDefinition
from CreeDictionary.utils import (
from morphodict.utils.serializer import SerializedDefinition
from morphodict.utils import (
shared_res_dir,
)
from morphodict.analysis import RichAnalysis
Expand Down
4 changes: 2 additions & 2 deletions src/morphodict/relabelling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from django.conf import settings

from CreeDictionary.utils import shared_res_dir
from CreeDictionary.utils.types import FSTTag, Label, cast_away_optional
from morphodict.utils import shared_res_dir
from morphodict.utils.types import FSTTag, Label, cast_away_optional
from morphodict.site.util import cache_unless


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/morphodict/search/affix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from django.conf import settings

from morphodict.lexicon.models import Wordform, TargetLanguageKeyword
from CreeDictionary.utils import get_modified_distance
from CreeDictionary.utils.cree_lev_dist import remove_cree_diacritics
from morphodict.utils import get_modified_distance
from morphodict.utils.cree_lev_dist import remove_cree_diacritics
from morphodict.lexicon.util import to_source_language_keyword
from .types import (
InternalForm,
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/search/glossary_count.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from CreeDictionary.utils import shared_res_dir
from morphodict.utils import shared_res_dir

DOCUMENT_FREQUENCY = {}

Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/search/lemma_freq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from CreeDictionary.utils import shared_res_dir
from morphodict.utils import shared_res_dir

LEMMA_FREQUENCY = {}

Expand Down
4 changes: 2 additions & 2 deletions src/morphodict/search/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from django.db.models import Q

from CreeDictionary.utils import (
from morphodict.utils import (
get_modified_distance,
)
from CreeDictionary.utils.english_keyword_extraction import stem_keywords
from morphodict.utils.english_keyword_extraction import stem_keywords
from morphodict.analysis import (
strict_generator,
rich_analyze_relaxed,
Expand Down
7 changes: 3 additions & 4 deletions src/morphodict/search/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

from morphodict.search import core, types
from morphodict.relabelling import read_labels, LABELS
from CreeDictionary.utils import get_modified_distance
from CreeDictionary.utils.fst_analysis_parser import partition_analysis
from morphodict.utils.fst_analysis_parser import partition_analysis
from morphodict.search.types import Preverb, LinguisticTag, linguistic_tag_from_fst_tags
from CreeDictionary.utils.types import ConcatAnalysis, FSTTag, Label
from morphodict.utils.types import ConcatAnalysis, FSTTag, Label
from crkeng.app.preferences import (
DisplayMode,
AnimateEmoji,
Expand All @@ -22,7 +21,7 @@
from morphodict.analysis import RichAnalysis
from morphodict.lexicon.models import Wordform, SourceLanguageKeyword

from morphodict.search.serializer import (
from morphodict.utils.serializer import (
SerializedDefinition,
SerializedWordform,
SerializedLinguisticTag,
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/search/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from morphodict.search.query import CvdSearchType
from morphodict.search.types import Result
from morphodict.search.util import first_non_none_value
from CreeDictionary.utils.types import cast_away_optional
from morphodict.utils.types import cast_away_optional

CREE_LONG_VOWEL = re.compile("[êîôâēīōā]")

Expand Down
4 changes: 2 additions & 2 deletions src/morphodict/search/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from enum import Enum
from typing import NewType, Optional, Protocol, cast, Iterable, Tuple

from morphodict.search.serializer import SerializedLinguisticTag
from CreeDictionary.utils.types import FSTTag, Label
from morphodict.utils.serializer import SerializedLinguisticTag
from morphodict.utils.types import FSTTag, Label
from morphodict.lexicon.models import Wordform, wordform_cache
from morphodict.search import ranking
from morphodict.relabelling import LABELS
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/search_quality/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import TypedDict

from morphodict.search.serializer import SerializedSearchResult
from morphodict.utils.serializer import SerializedSearchResult


class SearchResult(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/search_quality/analyze_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from os import PathLike
from typing import cast, TypedDict, Optional

from morphodict.search.serializer import SerializedSearchResult
from morphodict.utils.serializer import SerializedSearchResult
from . import DEFAULT_SAMPLE_FILE, SampleSearchResultsJson
from .sample import load_sample_definition, SampleDefinition

Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from string import printable as ascii_printable

import pytest
from CreeDictionary.CreeDictionary.utils import url_for_query
from morphodict.utils import url_for_query


@pytest.mark.parametrize("query", ["awa", "wâpamêw", "ᐚᐸᒣᐤ"])
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/tests/utils_tests/test_cree_lev_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from hypothesis import assume, example, given
from hypothesis.strategies import text
from Levenshtein import distance
from CreeDictionary.utils import get_modified_distance
from morphodict.utils import get_modified_distance


@given(text(alphabet=ascii_letters), text(alphabet=ascii_letters))
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/tests/utils_tests/test_profiling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from CreeDictionary.utils.profiling import timed
from morphodict.utils.profiling import timed


def test_timed_decorator(capsys):
Expand Down
18 changes: 18 additions & 0 deletions src/morphodict/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
from .cree_lev_dist import get_modified_distance
from .shared_res_dir import shared_res_dir
from urllib.parse import ParseResult, urlencode, urlunparse

from django.urls import reverse


def url_for_query(user_query: str) -> str:
"""
Produces a relative URL to search for the given user query.
"""
parts = ParseResult(
scheme="",
netloc="",
params="",
path=reverse("cree-dictionary-search"),
query=urlencode((("q", user_query),)),
fragment="",
)
return urlunparse(parts)
2 changes: 1 addition & 1 deletion src/morphodict/utils/fst_analysis_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import List, Tuple

from CreeDictionary.utils.types import FSTLemma, FSTTag
from morphodict.utils.types import FSTLemma, FSTTag

analysis_pattern = re.compile(
r"(?P<category>\+N\+A(\+D(?=\+))?|\+N\+I(\+D(?=\+))?|\+V\+AI|\+V\+T[AI]|\+V\+II|(\+Num)?\+Ipc|\+Pron).*?$"
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/utils/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from typing_extensions import Literal, TypedDict

from CreeDictionary.utils.types import FSTTag
from morphodict.utils.types import FSTTag


class SerializedDefinition(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/utils/shared_res_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from pathlib import Path

shared_res_dir: Path = Path(__file__).parent.parent / "res"
shared_res_dir: Path = Path(__file__).parent.parent / "resources"

shared_fst_dir = shared_res_dir / "fst"

0 comments on commit 2cb7897

Please sign in to comment.