Skip to content

Commit

Permalink
edited the number pattern regex to allow for a unicode fraction inste… (
Browse files Browse the repository at this point in the history
#160)

* edited the number pattern regex to allow for a unicode fraction instead of a required digit

* Fixed allowing a unicode fraction as the sole number

* Added a test for measurements containing purely unicode fractions

* Modify pipfile

* fixed merge issues of main branch, has unicode fractions test

Co-authored-by: Niels Mündler <n.muendler@web.de>
Co-authored-by: Niels Mündler <n.muendler@tum.de>
  • Loading branch information
3 people committed Sep 30, 2020
1 parent 9e627db commit b1802ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion quantulum3/_lang/en_US/tests/quantities.json
Original file line number Diff line number Diff line change
Expand Up @@ -1316,5 +1316,36 @@
"uncertainty": null
}
]
},
{
"req": "There is a ⅓ cup of sauce and ½ tbsp of salt in this recipe.",
"res": [
{
"value": 0.3333333333333333,
"unit": "cup",
"surface": "⅓ cup",
"entity": "volume",
"dimensions": [
{
"base": "length",
"power": 3
}
],
"uncertainty": null
},
{
"value": 0.5,
"unit": "tablespoon",
"surface": "½ tbsp",
"entity": "volume",
"dimensions": [
{
"base": "length",
"power": 3
}
],
"uncertainty": null
}
]
}
]
]
2 changes: 1 addition & 1 deletion quantulum3/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def operators(lang="en_US"):
NUM_PATTERN = r"""
(?{number} # required number
[+-]? # optional sign
\.?\d+ # required digits
(\.?\d+|[{unicode_fract}]) # required digits or unicode fraction
(?:[{grouping}]\d{{3}})* # allowed grouping
(?{decimals}[{decimal_operators}]\d+)? # optional decimals
)
Expand Down

0 comments on commit b1802ef

Please sign in to comment.