Created
July 5, 2020 09:45
-
-
Save yazinsai/289bd74b02c724f981b7e36574dfea34 to your computer and use it in GitHub Desktop.
A simple Ruby script to parse text from the Quran into text without diacritics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# 1. Copy the raw text from https://www.corequran.com/ | |
# 2. Run "ruby parse.rb" | |
# 3. Paste the copied text | |
# 4. Press "Ctrl + D" to see the output | |
def parse(str) | |
str | |
.split("\n") | |
.map { |aya| remove_verse_number(aya) } | |
.map { |aya| remove_diacritics(aya) } | |
end | |
def remove_verse_number(str) | |
str.gsub(/﴿.*?﴾/, '').strip | |
end | |
def remove_diacritics(str) | |
diacritics = 'ِ', 'ُ', 'ٓ', 'ٰ', 'ْ', 'ٌ', 'ٍ', 'ً', 'ّ', 'َ', ' ۛ', ' ۖ', ' ۗ' | |
str.gsub Regexp.union(diacritics), '' | |
end | |
puts parse(STDIN.read) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment