Skip to content

Commit

Permalink
Encoded WordNet POS for relabelling
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Dec 10, 2024
1 parent 41dfe8a commit 1e87189
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% spaceless %}
{% load morphodict_extras %}
{% load relabelling %}
{% if verbose_messages %}
<li class="search-results__result box">
<h3>Messages from search run</h3>
Expand All @@ -12,7 +13,7 @@ <h3>Messages from search run</h3>
<div class="synset" style="background-color: var(--menu-hover-bg-color); border: 4px solid var(--prose-title-color); border-radius:5px; padding: 10px; margin-left:10px; margin-right:10px; margin-top:.5cm; margin-bottom:.5cm;">
<a name="result-synset-{{result.wn_entry.nltk_name}}"></a>
<section class="prose box box--spaced">
<h2 class="prose__section-title">{{result.wn_entry.original_str}} ({{result.wn_entry.pos}})</h2>
<h2 class="prose__section-title">{{result.wn_entry.numbering}}. {{result.wn_entry.original_str}} ({% relabel_one result.wn_entry.paren_pos %})</h2>
<p>
{{result.wn_entry.definition}}
</p>
Expand Down
6 changes: 6 additions & 0 deletions src/morphodict/resources/crk.altlabel.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,9 @@ A+Sg+Title A+Sg Singular, Animate One (awa word) pêyak (awa)
A+Pl+Title A+Pl Plural, Animate Many (awa word) mihcêt (awa)
I+Sg+Title I+Sg Singular, Inanimate One (ôma word) pêyak (ôma)
I+Pl+Title I+Pl Plural, Inanimate Many (ôma word) mihcêt (ôma)

(v) Verb Verb Action word ispayin-itwêwin https://en.wikipedia.org/wiki/Verb
(n) Noun Noun Naming word wîhowin-itwêwin https://en.wikipedia.org/wiki/Noun
(a) Adj Adjective Description word wîhtam-itwêwin https://en.wikipedia.org/wiki/Adjective
(s) AdjSat Adjective Satellite Description word wîhtam-itwêwin https://en.wikipedia.org/wiki/Adjective
(r) Adv Adverb Word that changes another word âhtawêw-itwêwin https://en.wikipedia.org/wiki/Adverb
3 changes: 3 additions & 0 deletions src/morphodict/search/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +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()
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 @@ -155,6 +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()])
get_lemma_freq(wn_results)
for result in wn_results.unsorted_results():
result.relevance_score = result.lemma_freq
Expand Down
4 changes: 4 additions & 0 deletions src/morphodict/search/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class WordnetEntry:

synset: Synset
original_str: str
numbering: Optional[int]

def __init__(self, entry: str | Synset):
if isinstance(entry, str):
Expand Down Expand Up @@ -338,6 +339,9 @@ def heading(self) -> str:

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

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

def synonyms(self) -> list[str]:
return [" ".join(l.name().split("_")) for l in self.synset.lemmas()]
Expand Down

0 comments on commit 1e87189

Please sign in to comment.