Skip to content

Commit

Permalink
rename argument
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 26, 2022
1 parent d595559 commit c068466
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 67 deletions.
42 changes: 21 additions & 21 deletions lingua_franca/lang/parse_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ def normalize_en(text, remove_articles=True):
return EnglishNormalizer().normalize(text, remove_articles)


def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token=""):
def extract_timespan_en(text, unit=TimespanUnit.TIMEDELTA, replace_token=""):
"""
Convert an english phrase into a number of seconds
Convert things like:
Expand All @@ -1701,7 +1701,7 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="
(300, "set a timer for").
Args:
text (str): string containing a duration
resolution (TimespanUnit): format to return extracted duration on
unit (TimespanUnit): format to return extracted duration on
replace_token (str): string to replace consumed words with
Returns:
(timedelta, str):
Expand Down Expand Up @@ -1730,7 +1730,7 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="
_replace_token = (replace_token + " " + replace_token) \
if replace_token else ""

if resolution == TimespanUnit.TIMEDELTA:
if unit == TimespanUnit.TIMEDELTA:
si_units = {
'microseconds': None,
'milliseconds': None,
Expand Down Expand Up @@ -1777,10 +1777,10 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="
else:
si_units[unit] = value
duration = timedelta(**si_units) if any(si_units.values()) else None
elif resolution in [TimespanUnit.RELATIVEDELTA,
TimespanUnit.RELATIVEDELTA_APPROXIMATE,
TimespanUnit.RELATIVEDELTA_FALLBACK,
TimespanUnit.RELATIVEDELTA_STRICT]:
elif unit in [TimespanUnit.RELATIVEDELTA,
TimespanUnit.RELATIVEDELTA_APPROXIMATE,
TimespanUnit.RELATIVEDELTA_FALLBACK,
TimespanUnit.RELATIVEDELTA_STRICT]:
relative_units = {
'microseconds': None,
'seconds': None,
Expand Down Expand Up @@ -1831,7 +1831,7 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="

# microsecond, month, year must be ints
relative_units["microseconds"] = int(relative_units["microseconds"])
if resolution == TimespanUnit.RELATIVEDELTA_FALLBACK:
if unit == TimespanUnit.RELATIVEDELTA_FALLBACK:
for unit in ["months", "years"]:
value = relative_units[unit]
_leftover, _ = math.modf(value)
Expand All @@ -1843,7 +1843,7 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="
TimespanUnit.TIMEDELTA,
replace_token)
relative_units[unit] = int(value)
elif resolution == TimespanUnit.RELATIVEDELTA_APPROXIMATE:
elif unit == TimespanUnit.RELATIVEDELTA_APPROXIMATE:
_leftover, year = math.modf(relative_units["years"])
relative_units["months"] += 12 * _leftover
relative_units["years"] = int(year)
Expand Down Expand Up @@ -1902,33 +1902,33 @@ def extract_timespan_en(text, resolution=TimespanUnit.TIMEDELTA, replace_token="
microseconds += value * 1000 * 1000 * 60 * 60 * 24 * \
DAYS_IN_1_YEAR * 1000

if resolution == TimespanUnit.TOTAL_MICROSECONDS:
if unit == TimespanUnit.TOTAL_MICROSECONDS:
duration = microseconds
elif resolution == TimespanUnit.TOTAL_MILLISECONDS:
elif unit == TimespanUnit.TOTAL_MILLISECONDS:
duration = microseconds / 1000
elif resolution == TimespanUnit.TOTAL_SECONDS:
elif unit == TimespanUnit.TOTAL_SECONDS:
duration = microseconds / (1000 * 1000)
elif resolution == TimespanUnit.TOTAL_MINUTES:
elif unit == TimespanUnit.TOTAL_MINUTES:
duration = microseconds / (1000 * 1000 * 60)
elif resolution == TimespanUnit.TOTAL_HOURS:
elif unit == TimespanUnit.TOTAL_HOURS:
duration = microseconds / (1000 * 1000 * 60 * 60)
elif resolution == TimespanUnit.TOTAL_DAYS:
elif unit == TimespanUnit.TOTAL_DAYS:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24)
elif resolution == TimespanUnit.TOTAL_WEEKS:
elif unit == TimespanUnit.TOTAL_WEEKS:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 * 7)
elif resolution == TimespanUnit.TOTAL_MONTHS:
elif unit == TimespanUnit.TOTAL_MONTHS:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 *
DAYS_IN_1_MONTH)
elif resolution == TimespanUnit.TOTAL_YEARS:
elif unit == TimespanUnit.TOTAL_YEARS:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 *
DAYS_IN_1_YEAR)
elif resolution == TimespanUnit.TOTAL_DECADES:
elif unit == TimespanUnit.TOTAL_DECADES:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 *
DAYS_IN_1_YEAR * 10)
elif resolution == TimespanUnit.TOTAL_CENTURIES:
elif unit == TimespanUnit.TOTAL_CENTURIES:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 *
DAYS_IN_1_YEAR * 100)
elif resolution == TimespanUnit.TOTAL_MILLENNIUMS:
elif unit == TimespanUnit.TOTAL_MILLENNIUMS:
duration = microseconds / (1000 * 1000 * 60 * 60 * 24 *
DAYS_IN_1_YEAR * 1000)
else:
Expand Down
4 changes: 2 additions & 2 deletions lingua_franca/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def extract_duration(text, lang=''):

@localized_function(run_own_code_on=[FunctionNotLocalizedError])
def extract_timespan(text,
resolution=TimespanUnit.TIMEDELTA,
unit=TimespanUnit.TIMEDELTA,
replace_token="", lang=''):
""" Convert an english phrase into a number of seconds
Expand Down Expand Up @@ -159,7 +159,7 @@ def extract_timespan(text,
be None if no duration is found. The text returned
will have whitespace stripped from the ends.
"""
if resolution == TimespanUnit.TIMEDELTA and replace_token == "":
if unit == TimespanUnit.TIMEDELTA and replace_token == "":
return extract_duration(text, lang)
raise FunctionNotLocalizedError(f"extract_timespan not implemented for {lang}")

Expand Down
Loading

0 comments on commit c068466

Please sign in to comment.