Normalize unicode signs
This commit is contained in:
parent
80594cd38c
commit
390deb4203
2 changed files with 4 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ def extract_numbers(text: str) -> list[float]:
|
|||
parenthesised negatives. Numbers qualified by a scale word ("1.2 million")
|
||||
contribute both the raw and the scaled value, so either phrasing can match.
|
||||
"""
|
||||
text = text.replace("−", "-") # normalize the typographic minus sign
|
||||
numbers: list[float] = []
|
||||
for token in _NUMBER_RE.findall(text):
|
||||
value = _to_float(token)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ class TestExtractNumbers:
|
|||
def test_parenthesised_negative(self) -> None:
|
||||
assert extract_numbers("loss of (123)") == [-123.0]
|
||||
|
||||
def test_unicode_minus(self) -> None:
|
||||
assert extract_numbers("a change of −1.9 million") == [-1.9, -1.9e6]
|
||||
|
||||
def test_scale_word_adds_scaled_and_raw(self) -> None:
|
||||
numbers = extract_numbers("revenue of 1.2 billion")
|
||||
assert 1.2 in numbers
|
||||
|
|
|
|||
Loading…
Reference in a new issue