The Noble Quran in its original Arabic, alongside translations
Find a file
2022-10-07 15:24:31 -03:00
bin binlib/sql: add SQL::Template 2022-10-06 20:07:43 -03:00
bindata improve the pull-farsi, and pull-portuguese scripts 2022-07-17 16:37:36 -03:00
binlib binlib/sql: fix require of binlib/sql/template.rb 2022-10-07 15:24:31 -03:00
src binlib/sql: namespace SQL-related classes, and modules. 2022-10-06 20:07:43 -03:00
.gitignore add new SQL section "Save the database to disk". 2022-07-17 20:14:04 -03:00
.rubocop.yml rubocop-ify 2022-07-16 16:19:50 -03:00
.ruby-version readme: update. 2022-04-26 16:35:06 -03:00
.sqliterc add sample .sqliterc file. 2022-06-11 17:45:14 -03:00
Gemfile Gemfile: add source 2022-09-19 18:59:45 -03:00
README.md readme: improve. 2022-10-07 14:50:02 -03:00
VERSION v0.10.0 2022-09-02 15:48:41 -03:00

quran-pull

This repository contains the holy book, The Qur'an, in its original Arabic and as translations in English, Farsi, and Portuguese. The contents are made available in JSON, and SQL files.

Navigation

  1. src/json/directory
  2. src/sql/ directory
  3. bin/ directory

src/json/ directory

This section covers the JSON files. Click here to jump to the SQL section.

Arabic

Each JSON file represents a chapter, or surah. For example - src/json/ar/1.json contains Al-Fatihah. The structure of the JSON files can be described as an array where the first element is an object that contains information aboout the chapter, and the rest of the array is composed of two-element arrays - the first element being the verse number, and the second element being the contents of the verse. For example:

[
  { <chapter metadata> },
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  /* etc... */
]

English

The English translation is a copy of "The Clear Quran" - by Dr. Mustafa Khattab. Each JSON file represents a chapter, or surah. For example - src/json/en/1.json contains Al-Fatihah. The structure of the JSON files can be described as an array where the first element is an object that contains information aboout the chapter, and the rest of the array is composed of two-element arrays - the first element being the verse number, and the second element being the contents of the verse. For example:

[
  { <chapter metadata> },
  [
    1,
    "In the Name of Allah—the Most Compassionate, Most Merciful."
  ],
  [
    2,
    "All praise is for Allah—Lord of all worlds,"
  ],
  [
    3,
    "the Most Compassionate, Most Merciful,"
  ],
  [
    4,
    "Master of the Day of Judgment."
  ],
  [
    5,
    "You ˹alone˺ we worship and You ˹alone˺ we ask for help."
  ],
  [
    6,
    "Guide us along the Straight Path,"
  ],
  [
    7,
    "the Path of those You have blessed—not those You are displeased with, or those who are astray. "
  ]
]

Farsi

Each JSON file represents a chapter, or surah. For example - src/json/fa/1.json contains Al-Fatihah. The structure of the JSON files can be described as an array where the first element is an object that contains information aboout the chapter, and the rest of the array is composed of two-element arrays - the first element being the verse number, and the second element being the contents of the verse. For example:

[
  { <chapter metadata> },
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  /* etc... */
]

Portuguese

Each JSON file represents a chapter, or surah. For example - src/pt/1.json contains Al-Fatihah. The structure of the JSON files can be described as an array where the first element is an object that contains information aboout the chapter, and the rest of the array is composed of two-element arrays - the first element being the verse number, and the second element being the contents of the verse. For example:

[
  { <chapter metadata> },
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  [
    <verse number>,
    <verse contents>
  ],
  /* etc... */
]

Chapter metadata

The src/json/chapter-metadata.json file contains information about each chapter in The Qur'an. The JSON file is structured as an array of objects, where each object describes a given chapter.

The following example demonstrates how Al-Fatihah is described. The "codepoints" property is a sequence of unicode codepoints that can be mapped back to Arabic

  • for example by using JavaScript's String.fromCodePoint(...codepoints).
  {
    "id": "1",
    "place_of_revelation": "makkah",
    "transliterated_name": "Al-Fatihah",
    "translated_name": "The Opener",
    "verse_count": 7,
    "slug": "al-fatihah",
    "codepoints": [
      1575,
      1604,
      1601,
      1575,
      1578,
      1581,
      1577
    ]
  },

src/sql/ directory

This section covers the SQL files.

  • The src/sql/schema.sql defines the schema of the database.
    The schema is composed of three tables: qurans, chapters, and verses.

  • The src/sql/seed.sql populates the contents of the database.
    The languages included are Arabic, English, Farsi, and Portuguese.

  • The src/sql/queries/ directory contains .sql files that contain SQL queries.
    They serve as examples, and as inspiration for writing new queries.

SQLite3

This section of the README demonstrates how the SQL files mentioned above can be used to create a fully populated database in memory, how to query the database, and how to save the database to disk for future use.

It is assumed that the repository has been cloned or downloaded (see below), and that "sqlite3" is started from the root of the repository. Other SQL databases, such as MySQL, and PostgreSQL should be able to import the SQL files as well, but have not been tested.

1. $HOME/.sqliterc

For identical results - it is recommended that $HOME/.sqliterc has the following contents:

PRAGMA case_sensitive_like=ON;
pragma FOREIGN_KEYS = on;
.headers on
.mode column

2. Import / save the database to disk

The .save command can be used to save the database to disk permanently, and avoid repeatedly importing the database into memory:

sqlite> .read src/sql/schema.sql
sqlite> .read src/sql/seed.sql
sqlite> .save src/sql/quran.db
sqlite> .exit

SQLite3 can now be started with the path to the database saved to disk:

$ sqlite3 src/sql/quran.db
sqlite> SELECT qurans.id FROM qurans WHERE qurans.locale = 'ar';
id
--
1
sqlite>

3. Query the database

3.1

After the previous steps, the database is fully populated and exists on disk. We can now query the database and its contents. The SQL query we will execute fetches the contents of chapter 112 in the English locale (i.e: en):

SELECT qurans.locale,
       chapters.tr_name  AS "chapter (name)",
       chapters.number   AS chapter,
       verses.number     AS verse,
       verses.content
FROM   verses
       INNER JOIN qurans
               ON qurans.id = verses.quran_id
       INNER JOIN chapters
               ON chapters.id = verses.chapter_id
WHERE  qurans.locale = "en"
       AND chapters.number = 112;

The output should look like this:

locale  chapter (name)  chapter  verse  content
------  --------------  -------  -----  -----------------------------------------------------
en      Al-Ikhlas       112      1      Say, ˹O Prophet,˺ “He is Allah—One ˹and Indivisible˺;
en      Al-Ikhlas       112      2      Allah—the Sustainer ˹needed by all˺.
en      Al-Ikhlas       112      3      He has never had offspring, nor was He born.
en      Al-Ikhlas       112      4      And there is none comparable to Him.”

3.2

The next query we will execute demonstrates how to find a particular word or phrase in the English translation of The Qur'an - using the LIKE operator:

SELECT qurans.locale,
       chapters.name   AS "chapter (name)",
       chapters.number AS chapter,
       verses.number   AS verse,
       verses.content
FROM   verses
       INNER JOIN qurans
               ON qurans.id = verses.quran_id
       INNER JOIN chapters
               ON chapters.id = verses.chapter_id
WHERE  qurans.locale = "en"
       AND verses.content LIKE "%reflected light%";

The output should look like this:

locale  chapter (name)  chapter  verse  content
------  --------------  -------  -----  ----------------------------------------------------
en      Jonah           10       5      He is the One Who made the sun a radiant source and
                                        the moon a reflected light, with precisely ordained
                                        phases, so that you may know the number of years and
                                        calculation ˹of time˺. Allah did not create all this
                                        except for a purpose. He makes the signs clear for
                                        people of knowledge.

bin/ directory

The bin/ directory contains scripts that generate the contents of the src/ directory:

Note

By default it is not neccessary to run the scripts mentioned above because the contents of src/ is included in the repository already.

Note

The scripts are written in Ruby v3.1.0+.
The script dependencies can be installed by running the following from the root of the repository:

gem install bundler --no-document
bundle install

Download

For those who don't have access to, or know how to use "git", a zip file of the repository is provided for download: download zip file.

Credit, and thanks

The content of the src/ directory was automatically generated thanks to the following websites:

License

This software is released into the Public Domain.