blockspeiser/Sefaria-Project — pull request #85 by jdotjdot (2014-04-09 00:47:45+00:00)
Title: Hebdev mergeupstream

I've updated the `encode_hebrew_numeral` and `decode_hebrew_numeral` functions in `texts.py` to allow for more robust encoding and decoding, as well as support for larger numbers, including above 1000. I have moved this code into a new file called `hebrew.py`, which is imported from `texts.py` to preserve any existing function calls.

These functions also offer the option for "pretty" or "non-pretty" encoding, e.g., `כ״ג` or `כג`.

I've also provided tests, in the new `sefaria/tests/` folder.

Assumptions
====
Due to lack of conventions for large numbers, I've made some assumptions that may have to be changed depending on design decisions:
1. For numbers up to 1199, I use a form like `תתשצ״ט`.
2. For >=1200, rather than use `תת״ת`, I use a form letter+geresh, taking inspiration from how years are written (example: `ה׳תשס״ד`). Thus, 1221 would look like `א׳רכ״א`.
+ This can lead to ambiguity that already exists in this numbering system (is `ה׳` 5 or 5000?)
+ For numbers that are a single thousand, I'd recommend manually writing `אלף` or coming up with another convention.

3. For numbers >=1,000,000, though not officially supported here, I use multiple gershayim to block off each thousands block. For example, 1,000,001 is `א׳׳א` (note that's two individual geresh characters).

Future
====
Sefaria perek and pasuk numbers could use these functions, particularly for pretty encoding. Alternatively, they could be rewritten in Javascript for use client-side.

I was also considering creating a `HebrewNumber` class that would `__repr__` as Hebrew unicode (with an option to display as regular Arabic numerals as well), but would also have the general math functions like `__add__` implemented such that you could add two hebrew numbers together with no problem. This would look like:

```python
>>> a = HebrewNumber(45)
>>> print a
מ״ה
>>> print a + 5
נ׳
```