Skip to content

Commit

Permalink
Updated tests and presentation.py to pass some tests.
Browse files Browse the repository at this point in the history
I took the predeclared types as the expected behaviour.  For
underspecified portions, I assumed behaviour in the presentation template as the truth (what
django is assuming to present results), which means that the tests were
wrong (missed a list level, which is iterated through on the
presentation layer)
  • Loading branch information
fbanados committed May 15, 2024
1 parent fd18e88 commit 5e845a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
35 changes: 17 additions & 18 deletions src/CreeDictionary/API/search/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _LexicalEntry:
entry: List[_ReduplicationResult | SerializedWordform | _InitialChangeResult]
text: Optional[str]
url: str
id: Optional[str]
id: str | int | None
type: LexicalEntryType
original_tag: FSTTag

Expand Down Expand Up @@ -173,9 +173,10 @@ def __init__(
show_emoji=self._show_emoji,
)

self.preverbs = [
lexical_entry["entry"]
self.preverbs: List[SerializedWordform]= [
cast(SerializedWordform, entry)
for lexical_entry in self.lexical_info
for entry in lexical_entry["entry"]
if lexical_entry["type"] == "Preverb"
]
self.reduplication = [
Expand Down Expand Up @@ -453,22 +454,20 @@ def get_lexical_info(
animate_emoji: str,
show_emoji: str,
dict_source: list,
) -> List:
) -> List[dict] :
if not result_analysis:
return []

result_analysis_tags = result_analysis.prefix_tags
first_letters = extract_first_letters(result_analysis)

lexical_info: List = []
lexical_info: List[_LexicalEntry] = []

for i, tag in enumerate(result_analysis_tags):
preverb_result: Optional[Preverb] = None
reduplication_string: Optional[str] = None
_type: Optional[LexicalEntryType] = None
entry: Optional[
_ReduplicationResult | SerializedWordform | _InitialChangeResult
] = None
entry = None

if tag in ["RdplW+", "RdplS+"]:
reduplication_string = generate_reduplication_string(
Expand All @@ -488,7 +487,7 @@ def get_lexical_info(
# get the actual wordform object and
# make sure the result we return is an IPV
if preverb_results:
entries: List[_ReduplicationResult | SerializedWordform | _InitialChangeResult] = []
entries = []
for preverb in preverb_results:
lexicon_result = Wordform.objects.get(id=preverb.wordform_id)
if lexicon_result:
Expand All @@ -501,16 +500,16 @@ def get_lexical_info(
entries.append(entry)
url = "search?q=" + preverb_text
_type = "Preverb"
id : Optional[str] = str(cast(SerializedWordform, entries[0])["id"])
id: Optional[int] = entries[0]["id"]
result = _LexicalEntry(
entry=entries,
entry=cast(Any, entries),
text=preverb_text,
url=url,
id=id,
type=_type,
original_tag=tag,
)
lexical_info.append(serialize_lexical_entry(result))
lexical_info.append(result)
else:
# Can't find a match for the preverb in the database.
# This happens when searching against the test database for
Expand All @@ -533,23 +532,23 @@ def get_lexical_info(
).serialize()
_type = "Reduplication"
if entry and _type != "Preverb" and _type is not None:
url = cast(SerializedWordform, entry).get("lemma_url")
url = entry.get("lemma_url")
id = None
try:
id = str(cast(SerializedWordform, entry)["id"])
id = entry[0]["id"]
except:
id = None
entries = [entry]
entry = [entry]
result = _LexicalEntry(
entry=entries,
entry=entry,
text=reduplication_string,
url=url,
id=id,
type=_type,
original_tag=tag,
)
lexical_info.append(serialize_lexical_entry(result))
return lexical_info
lexical_info.append(result)
return [serialize_lexical_entry(entry) for entry in lexical_info]


def extract_first_letters(analysis: RichAnalysis) -> List[str]:
Expand Down
4 changes: 2 additions & 2 deletions src/CreeDictionary/tests/API_tests/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_search_words_with_reduplication():
search_result = results.pop()

assert len(search_result.lexical_info) == 1
assert search_result.lexical_info[0]["entry"]["text"] == "na-"
assert search_result.lexical_info[0]["entry"][0]["text"] == "na-"
assert search_result.lexical_info[0]["type"] == "Reduplication"


Expand All @@ -241,7 +241,7 @@ def test_search_words_with_inital_change():
search_result = results.pop()

assert len(search_result.lexical_info) == 1
assert search_result.lexical_info[0]["entry"]["text"] == " "
assert search_result.lexical_info[0]["entry"][0]["text"] == " "
assert search_result.lexical_info[0]["type"] == "Initial Change"


Expand Down

0 comments on commit 5e845a8

Please sign in to comment.