Skip to content

Commit

Permalink
Changes to make wordnet search inflect
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Dec 20, 2024
1 parent 2fac540 commit a81453d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/morphodict/search/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def wordnet_search(query: Query) -> list[tuple[WordnetEntry, SearchResults]] | N
get_lemma_freq(wn_results)
for result in wn_results.unsorted_results():
result.relevance_score = result.lemma_freq
if wordnet_search.analyzed_query:
# Then it is an inflected query that should be Espt-Search based
espt_search = EsptSearch(query, wn_results)
espt_search.convert_search_query_to_espt()
espt_search.inflect_search_results()
find_pos_matches(espt_search, wn_results)
results.append((wn_entry, wn_results))
return results

Expand Down
18 changes: 14 additions & 4 deletions src/morphodict/search/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
from morphodict.search.query import Query
from nltk.corpus import wordnet
from morphodict.lexicon.models import WordNetSynset
from morphodict.phrase_translate.types import PhraseAnalyzedQuery


class WordNetSearch:
synsets: list[WordNetSynset]
analyzed_query: PhraseAnalyzedQuery | None

def __init__(self, query: Query):
canonical_query = "_".join(query.query_terms)
self.analyzed_query = None
inflected = PhraseAnalyzedQuery(" ".join(query.query_terms))
if 1 < len(query.query_terms) and inflected.filtered_query:
canonical_query = inflected.filtered_query.split(" ")
self.analyzed_query = inflected
else:
canonical_query = query.query_terms
lemmas = wordnet.synsets("_".join(canonical_query))
candidate_infinitive = [x.removesuffix("s") for x in canonical_query]
if lemmas != candidate_infinitive:
lemmas.extend(wordnet.synsets("_".join(candidate_infinitive)))
self.synsets = list(
WordNetSynset.objects.filter(
name__in=produce_entries(
" ".join(query.query_terms), wordnet.synsets(canonical_query)
)
name__in=produce_entries(" ".join(canonical_query), lemmas)
)
)

Expand Down

0 comments on commit a81453d

Please sign in to comment.