Skip to content

Commit

Permalink
Check if word is in Lexique383 beforehand.
Browse files Browse the repository at this point in the history
  • Loading branch information
SekouDiaoNlp committed Aug 24, 2023
1 parent dddf733 commit e28e5c1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pylexique/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def convert_to_dict(obj: LexItem) -> Dict[str, Union[str, float, int, bool]]:
def _display_results(console: Console, results: DefaultDict[str, List[Union[LexItem, List[LexItem]]]], output: str) -> None:
"""Display lexical results using rich tables."""
for word, elements in results.items():
if not elements:
console.print(f"The word {word} was not found in Lexique383.")
continue
table = Table(title=f"Lexical Information for '{word}'", show_header=True)
table.add_column("Attribute", style="bold")

Expand Down Expand Up @@ -122,10 +125,13 @@ def _get_results(lexique: Lexique383, words: Sequence[str], all_forms: bool) ->
"""Get lexical results for the provided words."""
results: defaultdict[str, List[Union[LexItem, List[LexItem]]]] = DefaultDict(list)
for word in words:
if all_forms:
results[word].append(lexique.get_all_forms(word))
if word in lexique.lexique:
if all_forms:
results[word].append(lexique.get_all_forms(word))
else:
results[word].append(lexique.lexique[word])
else:
results[word].append(lexique.lexique[word])
results[word] = False
return results

if __name__ == "__main__":
Expand Down

0 comments on commit e28e5c1

Please sign in to comment.