Skip to content

Commit

Permalink
Minor formatting and types
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Dec 19, 2024
1 parent 1363668 commit ad65196
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/morphodict/frontend/templatetags/morphodict_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ def previous(some_list, current_index):

@register.filter(name="has_previous")
def has_previous(some_list, current_index):
return current_index > 0
return current_index > 0
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def migrate_from_linguistinfo(apps, schema_editor):
rapidwords = {
rw for l in wf.linguist_info["rw_indices"].values() for rw in l
}
elif isinstance(wf.linguist_info["rw_indices"],list):
elif isinstance(wf.linguist_info["rw_indices"], list):
rapidwords = [rw for rw in wf.linguist_info["rw_indices"]]
else:
continue
Expand Down
24 changes: 9 additions & 15 deletions src/morphodict/lexicon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,22 @@ class Wordform(models.Model):
""",
)

rw_indices = models.CharField(
max_length=2048,
blank=True,
null=True,
rapidwords = models.ManyToManyField(
RapidWords,
related_name="wordforms",
help_text="""
RapidWords indices for an entry, separated by a semicolon
RapidWords indices for an entry
""",
)

rapidwords = models.ManyToManyField(RapidWords, related_name="wordforms")

wn_synsets = models.CharField(
max_length=2048,
blank=True,
null=True,
synsets = models.ManyToManyField(
WordNetSynset,
related_name="wordforms",
help_text="""
WordNet synsets for an entry, separated by a semicolon
""",
WordNet synsets for an entry
""",
)

synsets = models.ManyToManyField(WordNetSynset, related_name="wordforms")

import_hash = models.CharField(
max_length=MAX_WORDFORM_LENGTH,
null=True,
Expand Down
6 changes: 3 additions & 3 deletions src/morphodict/phrase_translate/fst.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, thing_to_lookup, result_list):
)


def foma_lookup(fst, thing_to_lookup):
def foma_lookup(fst, thing_to_lookup) -> str:
# Caution: Python `foma.FST.apply_up` and `foma.FST.apply_down` do not cache
# the FST object built by the C-language `apply_init()` function in libfoma,
# so they are about 100x slower than calling the C-language `apply_up` and
Expand All @@ -58,11 +58,11 @@ def foma_lookup(fst, thing_to_lookup):
return l[0].decode("UTF-8")


def inflect_target_noun_phrase(tagged_phrase):
def inflect_target_noun_phrase(tagged_phrase) -> str:
return foma_lookup(eng_noun_entry_to_inflected_phrase_fst(), tagged_phrase)


def inflect_target_verb_phrase(tagged_phrase):
def inflect_target_verb_phrase(tagged_phrase) -> str:
return foma_lookup(eng_verb_entry_to_inflected_phrase_fst(), tagged_phrase)


Expand Down
2 changes: 1 addition & 1 deletion src/morphodict/phrase_translate/to_source/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __str__(self):

def translate_single_definition(
inflected_wordform, lemma_definition, stats: TranslationStats
):
) -> str | None:
stats.wordforms_examined += 1

assert inflected_wordform.analysis
Expand Down
4 changes: 3 additions & 1 deletion src/morphodict/phrase_translate/to_target/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger(__name__)


def inflect_target_language_phrase(analysis, lemma_definition):
def inflect_target_language_phrase(analysis, lemma_definition) -> str | None:
if isinstance(analysis, tuple):
analysis = RichAnalysis(analysis)
cree_wordform_tag_list = (
Expand All @@ -38,3 +38,5 @@ def inflect_target_language_phrase(analysis, lemma_definition):
phrase = inflect_target_verb_phrase(tagged_phrase)
logger.debug("phrase = %s\n", phrase)
return phrase.strip()

return None
6 changes: 3 additions & 3 deletions src/morphodict/search/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def wordnet_search(query: Query) -> list[tuple[WordnetEntry, SearchResults]] | N
# Wordnet search was successful _at the wordnet level_
# Now we must collect the results
results = []
synsets: dict[str, list[WordnetEntry]]= dict()
synsets: dict[str, list[WordnetEntry]] = dict()
for synset in wordnet_search.synsets:
wn_results = SearchResults()
wn_results.sort_function = lambda x: 0 - x.lemma_freq if x.lemma_freq else 0
Expand All @@ -156,8 +156,8 @@ def wordnet_search(query: Query) -> list[tuple[WordnetEntry, SearchResults]] | N
wn_results.add_result(r)
wn_entry = WordnetEntry(synset.name)
wn_entry.original_str = " ".join(query.query_terms)
synsets.setdefault(wn_entry.pos(),[]).append(wn_entry)
wn_entry.numbering=len(synsets[wn_entry.pos()])
synsets.setdefault(wn_entry.pos(), []).append(wn_entry)
wn_entry.numbering = len(synsets[wn_entry.pos()])
get_lemma_freq(wn_results)
for result in wn_results.unsorted_results():
result.relevance_score = result.lemma_freq
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 @@ -339,7 +339,7 @@ def heading(self) -> str:

def pos(self) -> str:
return self.synset.pos()

def paren_pos(self) -> str:
return f"({self.synset.pos()})"

Expand All @@ -354,7 +354,7 @@ def ranking(self) -> int:

def nltk_name(self) -> str:
return self.synset.name()

def sources(self) -> list[str]:
return ["WN"]

Expand Down

0 comments on commit ad65196

Please sign in to comment.