Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/extractnumber incompatibility #77

Merged
merged 3 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lingua_franca/lang/parse_da.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
'million': 1000000
}


def extractnumber_da(text):
# TODO: short_scale and ordinals don't do anything here.
# The parameters are present in the function signature for API compatibility
# reasons.
def extractnumber_da(text, short_scale=True, ordinals=False):
"""
This function prepares the given text for parsing by making
numbers consistent, getting rid of contractions, etc.
Expand Down Expand Up @@ -151,10 +153,7 @@ def extractnumber_da(text):

break

if not val:
return False

return val
return val or False


def extract_datetime_da(string, currentDate, default_time):
Expand Down
11 changes: 5 additions & 6 deletions lingua_franca/lang/parse_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@
'million': 1000000
}


def extractnumber_de(text):
# TODO: short_scale and ordinals don't do anything here.
# The parameters are present in the function signature for API compatibility
# reasons.
def extractnumber_de(text, short_scale=True, ordinals=False):
"""
This function prepares the given text for parsing by making
numbers consistent, getting rid of contractions, etc.
Expand Down Expand Up @@ -156,10 +158,7 @@ def extractnumber_de(text):

break

if not val:
return False

return val
return val or False


def extract_datetime_de(string, currentDate, default_time):
Expand Down
5 changes: 1 addition & 4 deletions lingua_franca/lang/parse_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ def extractnumber_es(text, short_scale=True, ordinals=False):
break
count += 1

if result is None:
return False

# Return the $str with the number related words removed
# (now empty strings, so strlen == 0)
# aWords = [word for word in aWords if len(word) > 0]
Expand All @@ -190,7 +187,7 @@ def extractnumber_es(text, short_scale=True, ordinals=False):
if dec == "0":
result = int(integer)

return result
return result or False


# TODO Not parsing 'cero'
Expand Down
12 changes: 5 additions & 7 deletions lingua_franca/lang/parse_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,10 @@ def number_ordinal_fr(words, i):

return None


def extractnumber_fr(text):
# TODO: short_scale and ordinals don't do anything here.
# The parameters are present in the function signature for API compatibility
# reasons.
def extractnumber_fr(text, short_scale=True, ordinals=False):
"""Takes in a string and extracts a number.
Args:
text (str): the string to extract a number from
Expand Down Expand Up @@ -465,11 +467,7 @@ def extractnumber_fr(text):
else:
result = val

# if result == False:
if not result:
return normalize_fr(text, True)

return result
return result or False


def extract_datetime_fr(string, currentDate, default_time):
Expand Down
11 changes: 5 additions & 6 deletions lingua_franca/lang/parse_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def isFractional_pt(input_str):

return False


def extractnumber_pt(text):
# TODO: short_scale and ordinals don't do anything here.
# The parameters are present in the function signature for API compatibility
# reasons.
def extractnumber_pt(text, short_scale=True, ordinals=False):
"""
This function prepares the given text for parsing by making
numbers consistent, getting rid of contractions, etc.
Expand Down Expand Up @@ -179,9 +181,6 @@ def extractnumber_pt(text):
break
count += 1

if result is None:
return False

# Return the $str with the number related words removed
# (now empty strings, so strlen == 0)
# aWords = [word for word in aWords if len(word) > 0]
Expand All @@ -192,7 +191,7 @@ def extractnumber_pt(text):
if dec == "0":
result = int(integer)

return result
return result or False


class PortugueseNormalizer(Normalizer):
Expand Down
11 changes: 5 additions & 6 deletions lingua_franca/lang/parse_sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
from dateutil.relativedelta import relativedelta
from .parse_common import is_numeric, look_for_fractions


def extractnumber_sv(text):
# TODO: short_scale and ordinals don't do anything here.
# The parameters are present in the function signature for API compatibility
# reasons.
def extractnumber_sv(text, short_scale=True, ordinals=False):
"""
This function prepares the given text for parsing by making
numbers consistent, getting rid of contractions, etc.
Expand Down Expand Up @@ -117,10 +119,7 @@ def extractnumber_sv(text):

break

if not val:
return False

return val
return val or False


def extract_datetime_sv(string, currentDate, default_time):
Expand Down
3 changes: 1 addition & 2 deletions test/test_parse_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def test_extractnumber_fr(self):
2.02)
self.assertEqual(extract_number("ça fait virgule 2 cm", lang="fr-fr"),
0.2)
self.assertEqual(extract_number("point du tout", lang="fr-fr"),
"point tout")
self.assertEqual(extract_number("point du tout", lang="fr-fr"), False)
self.assertEqual(extract_number("32.00 secondes", lang="fr-fr"), 32)
self.assertEqual(extract_number("mange trente-et-une bougies",
lang="fr-fr"), 31)
Expand Down