islamic-network / api.alquran.cloud

The AlQuran.Cloud API - https://alquran.cloud/api
GNU General Public License v3.0
229 stars 42 forks source link

Allow query param to strip Bismillah from first ayahs #17

Open meezaan opened 5 years ago

RabeeAbuBaker commented 4 years ago

I had to do it manually:

if (this.surahNumber !== 1) { // Remvoing basmala this.ayahs[0].text = this.ayahs[0].text.substring(38); }

vipafattal commented 4 years ago

@RAbuBaker This way of removing Baslmalih has a lot of drawbacks, this will remove more text in Surah Tawba since no Baslmalih in it, and in some cases, the Baslmalih has Arabic Shadiha ( ّ ) such as Surah AlQader, in this case, the length of Baslmalih is no longer 38.

My solution to this is to get the range of Baslmalih by getting the first index of "ٱلرَّحِيمِ" then replacing this range with an empty string:

(This code is in Kotlin, but I think you can find something similar for what are you programming in)


const val Fatiha = "Al-Faatiha"
const val Tawba = "At-Tawba"

fun getEndIndexOfBasmalih(): Int {
        //Works only for quran-uthmani
        val string = "ٱلرَّحِيمِ"
        return ayaText.indexOf(string, 0) + string.length
    }

fun getTextWithoutBasmalih(numberInSurah :Int): String {
      return   if (numberInSurah == 1 
            &&  surah!!.englishName != MushafConstants.Fatiha
            &&  surah!!.englishName != MushafConstants.Tawba)
            ayaText.substring(getEndIndexOfBasmalih(), ayaText.length)
        else ayaText
    }
RabeeAbuBaker commented 4 years ago

@RAbuBaker This way of removing Baslmalih has a lot of drawbacks, this will remove more text in Surah Tawba since no Baslmalih in it, and in some cases, the Baslmalih has Arabic Shadiha ( ّ ) such as Surah AlQader, in this case, the length of Baslmalih is no longer 38.

My solution to this is to get the range of Baslmalih by getting first index of "ٱلرَّحِيمِ" then replacing this range with an empty string:

(This code is in Kotlin, but I think you can find something similar for what are you programming in)

const val Fatiha = "Al-Faatiha"
const val Tawba = "At-Tawba"

fun getEndIndexOfBasmalih(): Int {
        val string = "ٱلرَّحِيمِ"
        return ayaText.indexOf(string, 0) + string.length
    }

fun getTextWithoutBasmalih(numberInSurah :Int): String {
      return   if (numberInSurah == 1 && surah.englishName != Fatiha)
            ayaText.replaceRange(0, getEndIndexOfBasmalih(), "")
        else ayaText
    }

Thanks a lot for pointing out to this.. it was indeed helpful.

I am programming in ES6/Angular. I will certainly do something similar. JazakAllah Kahir..

vipafattal commented 4 years ago

Most Welcome

meezaan commented 4 years ago

@vipafattal @RAbuBaker this will only work with quran-uthmani - not with quran-simple - incase anyone is using that.

vipafattal commented 4 years ago

@vipafattal @RAbuBaker this will only work with quran-uthmani - not with quran-simple - incase anyone is using that.

Yes I'm using it with quran-uthmani if someone is not using generic Quran version, they can replace

val string = "ٱلرَّحِيمِ"

with same version of end Basmalih in quran-simple, otherwise, I would suggest splitting first Aya by whitespace I think this will work fine in all quran version:

fun getEndIndexOfBasmalih(): Int {
    val split = ayaText.split(' ')
    return ayaText.indexOf(split[3], 0) +  split[3].length
}
meezaan commented 4 years ago

Thanks @vipafattal I will try and prioritise this to deal with it on the API side.

RabeeAbuBaker commented 4 years ago

Any update on this? @meezaan

meezaan commented 4 years ago

Al Salaamu Alaykum @RabeeAbuBaker. It's number 5 on the backlog - https://github.com/orgs/islamic-network/projects/5 - so not yet, I'm afraid. But soon, God willing!

ghazalitajuddin commented 3 years ago

I use .replace() method. Those unicode is part of Bismillah. Hope helps.

strippedContent: function(string) { return string.replace("\u0628\u0650\u0633\u0652\u0645\u0650 \u0627\u0644\u0644\u0651\u064e\u0647\u0650 \u0627\u0644\u0631\u0651\u064e\u062d\u0652\u0645\u064e\u0670\u0646\u0650 \u0627\u0644\u0631\u0651\u064e\u062d\u0650\u064a\u0645\u0650", ""); },