Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into blackfoot-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed May 23, 2024
2 parents 3df5276 + b010561 commit 7dbb4c2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
30 changes: 10 additions & 20 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions src/CreeDictionary/API/search/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class _InitialChangeResult(AbstractResult):
@dataclass
class _LexicalEntry:
entry: List[_ReduplicationResult | SerializedWordform | _InitialChangeResult]
text: str
text: Optional[str]
url: str
id: 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 Down Expand Up @@ -501,16 +500,16 @@ def get_lexical_info(
entries.append(entry)
url = "search?q=" + preverb_text
_type = "Preverb"
id = 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 Down Expand Up @@ -548,8 +547,8 @@ def get_lexical_info(
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
2 changes: 1 addition & 1 deletion src/CreeDictionary/search_quality/analyze_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def load_results_file(results_file: PathLike) -> SampleSearchResultsJson:
return search_results


def analyze(results_file, sample_definition: SampleDefinition = None):
def analyze(results_file, sample_definition: SampleDefinition = []):
"""
If sample_definition is None, the default will be used.
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 7dbb4c2

Please sign in to comment.