5 ms·
In Pint you can define custom units in a unit registry. So you make your complex unit out of predefined units and the underlying unit conversion is built-in. Pi
by gillesjacobs 3y ago
In Pint you can define custom units in a unit registry. So you make your complex unit out of predefined units and the underlying unit conversion is built-in. Pint also works with pandas/numpy so you you get vectorized operations too for performance.
- shalmanese 3y agoWell, I get how mathematically you do it, I'm talking about how to make it contextually aware like the OP. A sentence like "The latest generation doubled MPG from 15 MPG to 30 MPG" should be localized to "The latest generation halved L/100km from 16 L/100km to 7.8 L/100km".
- gillesjacobs 3y agoThe unit registry maps units to locales (eg EN_US, DE_DE, NL_BE) you pass the configured locale to your getter call for the unit. If you need unit strings, you can pass the locale to the string formatter.
- shalmanese 3y agoI feel like we're talking cross purposes. A sentence like "MPG increased by 20%" should be translated to "L/100km decreased by 16.6%", a sentence like "MPG increase by 5" is untranslatable without more context. I understand if you are getting a human to translate each sentence you can just point them to the right phrases but my understanding is that you're translating text in bulk via machine translation. For scales in which the conversion is linear and the starting point is zero, this task is relatively trivial. For scales like temp where the zero points are different, you need to treat deltas different from absolute values. For scales where one is the inverse of the other, there's a lot of very tricky edge cases that make machine translation hard.