Hebrew
Let’s see how far can we get using Hebrew:
NLTK
The first good sign comes from NLTK, running the command:
>>> nltk.corpus.udhr.fileids()
returns as part of its output:
'Hebrew_Ivrit-Hebrew', 'Hebrew_Ivrit-UTF8'
Getting the Text
But sadly, the API chosen at the beginning does not provide a bible in Hebrew.
For a site that provides so wide a variety of Bible versions in several languages, there must be a very good set of reasons why Hebrew is not present; I can only blame myself for not checking that while picking a source.
To find a way to make the basic analysis in Hebrew, here are some interesting findings:
Other APIs produces the following:
({"book":[{"book_ref":"Ge","book_name":"Genesis","book_nr":"1","chapter_nr":"1","chapter":{"1":{"verse_nr":"1","verse":"\u05d1\u05bc\u05b0\u05e8\u05b5\u05d0\u05e9\u05c1\u05b4\u05d9\u05ea \u05d1\u05bc\u05b8\u05e8\u05b8\u05d0 \u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u05d9\u05dd \u05d0\u05b5\u05ea \u05d4\u05b7\u05e9\u05c1\u05bc\u05b8\u05de\u05b7\u05d9\u05b4\u05dd \u05d5\u05b0\u05d0\u05b5\u05ea \u05d4\u05b8\u05d0\u05b8\u05e8\u05b6\u05e5\u05c3\r\n"}}}],"direction":"RTL","type":"verse","version":"wlc"});
Where “\u05d1” is Unicode for the Hebrew letter “Bet”, so it would be better to first see whether NLTK can process the text in this format.
With this, we could follow the same path as with the English analysis: Build some scripts and retrieve all the text to local storage for processing.
Stricking Gold : Sefaria
In the search of an API Service from where to retrieve the text of the Scriptures in Hebrew, I found Sefaria a project which aside from providing an API, allows you to download a dump of all their content as a mongo database !!!
. We are talking at least 2GB of text content including
- Articles in English and Hebrew
- The scriptures in Hebrew: 3 versions: “Tanach with Ta’amei Hamikra”, “Tanach with Text Only”, “Tanach with Nikkud”
- Web pages
- Linking between content, including translations.
- A lot more …
So this looks to me as a Gold Mine in terms of Semantic Information.
So let’s start mining, this is going to involve some good amount of work but I think it’s worth it.
Step 1 : Loading the Database
Installing mongo was not a problem. After that, while trying the database restoring command is where the problems began: it seems like my 1GB-RAM-20GB-disk-free-tier humble instance of EC2-AWS didn’t have the memory to handle the restoring process. Instead of paying for more memory, creating a swap file to be used by the system as additional memory allowed the restoring to start running:
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
But each time the process would just get stuck at some point, processing power? the memory still not enough? space in the disk?
So as an alternative let us just try and load what we need right now: the texts
mongorestore --drop -d sefaria -c texts ./texts.bson
Again. the process stops adding data at around 50% before dying out.
Even with this error, the data restored is accessible, so I will start the analysis on the books I have available, with any luck all the books of the Bible might be there.
Decision time: Should I use the Text-only version or the one with nikkud?
Since nikkud is, as far as I know, mostly a pronunciation help, and right now I’m more interested in meaning than in pronunciation, let’s go for the plain-text version.
This is how it looks like to retrieve the text for a whole book:
> use sefaria
switched to db sefaria
> db.texts.find({ language: "he", title: /^Obadiah/ }, { title: 1, versionTitle: 1})
{ "_id" : ObjectId("5497bfb2fbfba238003bd223"), "versionTitle" : "Tanach with Ta'amei Hamikra", "title" : "Obadiah" }
{ "_id" : ObjectId("5497c115fbfba238003c2d01"), "versionTitle" : "Tanach with Text Only", "title" : "Obadiah" }
{ "_id" : ObjectId("5497c2b7fbfba238003c87de"), "versionTitle" : "Tanach with Nikkud", "title" : "Obadiah" }
> db.texts.find({ _id: ObjectId("5497c115fbfba238003c2d01") })
>
which returns the following JSON:
{
"_id": ObjectId("5497c115fbfba238003c2d01"),
"chapter": [
[
"חזון עבדיה כה־אמר אדני יהוה לאדום שמועה שמענו מאת יהוה וציר בגוים שלח קומו ונקומה עליה למלחמה",
"הנה קטן נתתיך בגוים בזוי אתה מאד",
"זדון לבך השיאך שכני בחגוי־סלע מרום שבתו אמר בלבו מי יורדני ארץ",
"אם־תגביה כנשר ואם־בין כוכבים שים קנך משם אורידך נאם־יהוה",
"אם־גנבים באו־לך אם־שודדי לילה איך נדמיתה הלוא יגנבו דים אם־בצרים באו לך הלוא ישאירו עללות",
"איך נחפשו עשו נבעו מצפניו",
"עד־הגבול שלחוך כל אנשי בריתך השיאוך יכלו לך אנשי שלמך לחמך ישימו מזור תחתיך אין תבונה בו",
"הלוא ביום ההוא נאם־יהוה והאבדתי חכמים מאדום ותבונה מהר עשו",
"וחתו גבוריך תימן למען יכרת־איש מהר עשו מקטל",
"מחמס אחיך יעקב תכסך בושה ונכרת לעולם",
"ביום עמדך מנגד ביום שבות זרים חילו ונכרים באו שערו [שעריו] ועל־ירושלם ידו גורל גם־אתה כאחד מהם",
"ואל־תרא ביום־אחיך ביום נכרו ואל־תשמח לבני־יהודה ביום אבדם ואל־תגדל פיך ביום צרה",
"אל־תבוא בשער־עמי ביום אידם אל־תרא גם־אתה ברעתו ביום אידו ואל־תשלחנה בחילו ביום אידו",
"ואל־תעמד על־הפרק להכרית את־פליטיו ואל־תסגר שרידיו ביום צרה",
"כי־קרוב יום־יהוה על־כל־הגוים כאשר עשית יעשה לך גמלך ישוב בראשך",
"כי כאשר שתיתם על־הר קדשי ישתו כל־הגוים תמיד ושתו ולעו והיו כלוא היו",
"ובהר ציון תהיה פליטה והיה קדש וירשו בית יעקב את מורשיהם",
"והיה בית־יעקב אש ובית יוסף להבה ובית עשו לקש ודלקו בהם ואכלום ולא־יהיה שריד לבית עשו כי יהוה דבר",
"וירשו הנגב את־הר עשו והשפלה את־פלשתים וירשו את־שדה אפרים ואת שדה שמרון ובנימן את־הגלעד",
"וגלת החל־הזה לבני ישראל אשר־כנענים עד־צרפת וגלת ירושלם אשר בספרד ירשו את ערי הנגב",
"ועלו מושעים בהר ציון לשפט את־הר עשו והיתה ליהוה המלוכה"
]
],
"status": "locked",
"versionTitle": "Tanach with Text Only",
"license": "Public Domain",
"language": "he",
"title": "Obadiah",
"licenseVetted": true,
"versionSource": "http://www.tanach.us/Tanach.xml",
"versionTitleInHebrew": "תנ״ך - טקסט בלבד"
}
Tokenizing
Well, there’s no Hebrew tokenizer in my NLTK installation :
tokenizers/punkt/czech.pickle
tokenizers/punkt/danish.pickle
tokenizers/punkt/dutch.pickle
tokenizers/punkt/english.pickle
tokenizers/punkt/estonian.pickle
tokenizers/punkt/finnish.pickle
tokenizers/punkt/french.pickle
tokenizers/punkt/german.pickle
tokenizers/punkt/greek.pickle
tokenizers/punkt/italian.pickle
tokenizers/punkt/norwegian.pickle
tokenizers/punkt/polish.pickle
tokenizers/punkt/portuguese.pickle
tokenizers/punkt/russian.pickle
tokenizers/punkt/slovene.pickle
tokenizers/punkt/spanish.pickle
tokenizers/punkt/swedish.pickle
tokenizers/punkt/turkish.pickle
Nevertheless, the general tokenizer seems to works just fine, it takes just the spaces I guess. And with that, we can just use practically the same code used before.
these scripts are available inside the “Hebrew” folder of the Scripts Source Code
running f_b_tokenize_documents.py all the books of the Tanach are processed and reports the following:
Exodus 41
Joshua 25
II Kings 26
Hosea 15
Micah 8
Nahum 4
Habakkuk 4
Zephaniah 4
Haggai 3
Zechariah 15
Malachi 4
I Chronicles 30
Proverbs 32
Daniel 13
Leviticus 28
Judges 22
I Kings 23
Ezekiel 49
Jonah 5
Job 43
Song of Songs 9
Nehemiah 14
Numbers 37
I Samuel 32
Isaiah 67
Joel 5
Obadiah 2
Psalms 151
Ecclesiastes 13
Lamentations 6
Esther 11
Genesis 51
Deuteronomy 35
II Samuel 25
Jeremiah 53
Amos 10
II Chronicles 37
Ruth 5
Ezra 11
Resulting in 70226 distinct word tokens, almost 162% of the 43518 we found for the English version. This is the count before removing stop words.
After removing the stop words we are left with 69907
After that, we can run f_e_print_word_frequency_by_book.py
and we get the following reports
Global
In English, the top 5 words were: Lord, shall, said, God, Israel
In Hebrew we have (translated): “I Am”=Yahweh, which, God, man, said
('יהוה', 98805)
('אשר', 57580)
('אלהים', 20747)
('איש', 13775)
('ויאמר', 13555)
('אדני', 12519)
('לאמר', 10877)
('אלהי', 10664)
('ליהוה', 10548)
('אלי', 10502)
('מלך', 8782)
('המלך', 8339)
('אתו', 8337)
('הארץ', 8249)
('משה', 7395)
('יהודה', 7216)
('אליו', 7167)
('נפשי', 6757)
('ההוא', 6702)
('עשה', 6668)
('מצרים', 6404)
('צבאות', 6339)
('הנה', 6220)
('דוד', 6127)
('עלי', 5943)
('אליך', 5808)
('אלהיך', 5740)
('אנכי', 5268)
('והנה', 5030)
('ואין', 4720)
('העם', 4654)
('הכהן', 4621)
('ארץ', 4620)
('כה', 4559)
('נתן', 4482)
('ימים', 4449)
('מפני', 4358)
('יעקב', 4356)
('שאול', 4250)
('תחת', 4226)
('רשעים', 4197)
('אל־משה', 4005)
('עליך', 3948)
('את־יהוה', 3934)
('אלף', 3836)
('המה', 3780)
('האלהים', 3742)
('לדוד', 3699)
('שלמה', 3671)
('דבר־יהוה', 3626)
('ירושלם', 3598)
('מארץ', 3590)
('השמים', 3570)
('גוים', 3438)
('בנו', 3381)
('בך', 3374)
('נאם־יהוה', 3361)
('רשע', 3336)
('עליהם', 3336)
('מזמור', 3253)
('עמו', 3245)
('אל־יהוה', 3220)
('מאות', 3214)
('רעה', 3193)
('אלהינו', 3155)
('עשו', 3144)
('אליהם', 3105)
('אבי', 3094)
('זהב', 3080)
('פרעה', 3018)
('עמך', 2957)
('ויהי', 2952)
('רבים', 2930)
('והיה', 2924)
('בנים', 2910)
('הנני', 2877)
('דברי', 2868)
('עמי', 2866)
('ויאמרו', 2838)
('לבני', 2789)
('משפט', 2750)
('אברהם', 2747)
('כה־אמר', 2742)
('קול', 2730)
('ויבא', 2708)
('רוח', 2693)
('צדיק', 2674)
('במדבר', 2674)
('לבית', 2649)
('אהרן', 2647)
('עמים', 2632)
('דויד', 2613)
('פני', 2612)
('בני־ישראל', 2605)
('לבי', 2580)
('לחם', 2562)
('עולם', 2548)
('נאם', 2535)
('וישב', 2525)
('אשה', 2520)
('עשרים', 2514)
('שמך', 2509)
('שמע', 2492)
('ביהוה', 2489)
('שמו', 2483)
('מאת', 2468)
('נתתי', 2451)
('פניך', 2445)
('ביד', 2444)
('עשר', 2430)
('יחדו', 2425)
('סביב', 2416)
('ישב', 2402)
('על־כן', 2398)
('על־פני', 2393)
('עליה', 2387)
('צוה', 2382)
('בי', 2341)
('ידו', 2334)
('יצא', 2333)
('העיר', 2319)
('שמים', 2317)
('לאלהים', 2316)
('ובין', 2286)
('עיני', 2273)
('ממני', 2236)
('אתי', 2211)
('לפניך', 2204)
('בעיני', 2196)
('ידי', 2192)
('פלשתים', 2183)
('עלה', 2176)
('למלך', 2174)
('אש', 2129)
('ושם', 2079)
('את־הארץ', 2067)
('ויבאו', 2054)
('וילך', 2041)
('שבע', 2021)
('ויקרא', 2020)
('עשרה', 2006)
('אלהם', 1995)
('יהושע', 1985)
('ואמר', 1975)
('ואתה', 1972)
('בהם', 1953)
('ראשי', 1950)
('מדבר', 1941)
('הבית', 1940)
('אלהיכם', 1926)
('וישבו', 1923)
('עשית', 1902)
('האדם', 1890)
('מועד', 1882)
('ואשר', 1880)
('ואמרת', 1872)
('השדה', 1868)
('האיש', 1864)
('שמה', 1862)
('בהר', 1854)
('ידך', 1849)
('שמואל', 1847)
('לעם', 1844)
('הלך', 1842)
('שלח', 1838)
('מואב', 1808)
('בבקר', 1808)
('הוליד', 1804)
('יעשה', 1797)
('כי־אני', 1796)
('חמשה', 1796)
('בחרב', 1796)
('מיד', 1795)
('שרי', 1792)
('יתן', 1791)
('הכהנים', 1788)
('ראה', 1782)
('עתה', 1782)
By Book
Book | Word(freq) | Word(freq) | Word(freq) |
---|---|---|---|
Amos | אדני(89) | על־שלשה(69) | ועל־ארבעה(69) |
Daniel | דניאל(304) | ואמר(235) | דנה(191) |
Deuteronomy | אשר(7333) | אלהיך(3954) | נתן(1037) |
Ecclesiastes | תחת(247) | האלהים(185) | האדם(156) |
Esther | אשר(320) | אסתר(192) | המן(156) |
Exodus | משה(3506) | אשר(3254) | מצרים(2526) |
Ezekiel | אדני(5143) | אשר(5058) | אלי(2707) |
Ezra | אשר(133) | מלכא(122) | עשרים(113) |
Genesis | אלהים(5110) | יהוה(3949) | ויאמר(2824) |
Habakkuk | רשע(7) | תביט(6) | קריה(6) |
Haggai | צבאות(15) | העם(9) | הנביא(8) |
Hosea | יהוה(108) | יהודה(73) | עתה(70) |
I Chronicles | בנו(1550) | דויד(1444) | יהוה(1049) |
I Kings | המלך(1703) | יהוה(1697) | שלמה(1554) |
I Samuel | שאול(2473) | אשר(1923) | שמואל(1813) |
II Chronicles | יהוה(3046) | שלמה(1831) | המלך(1425) |
II Kings | ויאמר(1935) | אשר(1600) | מלך(1349) |
II Samuel | אשר(1440) | המלך(1382) | ויאמר(1269) |
Isaiah | אשר(3239) | צבאות(2639) | ההוא(2107) |
Jeremiah | אשר(6407) | יהודה(3028) | נאם־יהוה(2787) |
Job | עלי(649) | אלוה(533) | יהוה(383) |
Joel | אלהיכם(21) | אכל(19) | משרתי(15) |
Jonah | הים(20) | יונה(17) | אליו(16) |
Joshua | יהושע(1639) | אשר(1576) | הירדן(556) |
Judges | אשר(1135) | איש(699) | ויאמר(595) |
Lamentations | אדני(48) | אשר(30) | מנחם(25) |
Leviticus | הכהן(2240) | יהוה(2075) | אתו(934) |
Malachi | צבאות(23) | ואמרתם(14) | שמי(12) |
Micah | יעקב(40) | יושבת(35) | עמי(32) |
Nahum | כלה(9) | ואין(9) | נקם(6) |
Nehemiah | החזיק(286) | מאות(177) | המלך(167) |
Numbers | אשר(2951) | משה(1978) | אל־משה(1626) |
Obadiah | יהוה(3) | ציון(2) | מהר(2) |
Proverbs | רשעים(591) | חכמה(473) | רשע(404) |
Psalms | אלהים(11063) | נפשי(5750) | אלהי(4601) |
Ruth | אשר(38) | יהוה(33) | בעז(25) |
Song of Songs | רעיתי(46) | נפשי(39) | בנות(39) |
Zechariah | צבאות(392) | אלי(230) | אשר(220) |
Zephaniah | ההוא(11) | קול(8) | אשר(8) |
With this, we have reached more or less the same degree of analysis as with the English texts.
Previous | Home | Next |
---|---|---|
One Result, Several Questions | θεόφιλος Journey | Topic Modeling |