Common#
- ingredient_parser._common.consume(iterator: Iterator, n: int | None) None[source]#
Advance the iterator n-steps ahead. If n is none, consume entirely.
See consume from https://docs.python.org/3/library/itertools.html#itertools-recipes
- Parameters:
Examples
>>> it = iter(range(10)) >>> consume(it, 3) >>> next(it) 3
>>> it = iter(range(10)) >>> consume(it, None) >>> next(it) StopIteration
- ingredient_parser._common.download_nltk_resources() None[source]#
Check if required nltk resources can be found and if not, download them.
- ingredient_parser._common.group_consecutive_idx(idx: list[int]) Generator[Iterator[int], None, None][source]#
Yield groups of consecutive indices.
Given a list of integers, yield groups of integers where the value of each in a group is adjacent to the previous element’s value.
- Parameters:
- Yields:
Examples
>>> groups = group_consecutive_idx([0, 1, 2, 4, 5, 6, 8, 9]) >>> [list(g) for g in groups] [[0, 1, 2], [4, 5, 6], [8, 9]]
- ingredient_parser._common.is_float(value: str) bool[source]#
Check if value can be converted to a float.
- Parameters:
- value
str Value to check.
- value
- Returns:
- bool
True if the value can be converted to float, else False.
Examples
>>> is_float("3") True
>>> is_float("2.5") True
>>> is_float("1-2") False
- ingredient_parser._common.is_range(value: str) bool[source]#
Check if value is a range e.g. 100-200.
Examples
>>> is_range("1-2") True
>>> is_float("100-500") True
>>> is_float("1") False
- ingredient_parser._common.show_model_card(lang: str = 'en') None[source]#
Open model card for specified language in default application.
- Parameters:
- lang
str,optional Selected language to open model card for.
- lang
- Raises:
FileNotFoundErrorRaised if model card not found at expected path.
ValueErrorRaised if unsupported language provided in lang argument.