Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
Recently I've been busy enhancing my Jawi to Rumi converter and I found out that some Jawi words cannot be converted back to Rumi(Romanized) form if there's no available match in the map based dictionary. To tackle this type of problem, I've to devise a better way to convert the Jawi words to Rumi. One such way is to break the Jawi word into each individual characters and perform a map(a.k.a hash-table) search for the individual character.
Depending on the Jawi input, some Rumi results are easy to figure out. Words such as foto
or syampu
are easily comprehensible from their final Rumi result. However, some words will require the reader to have some ability to read Jawi. At the minimum, the reader needs to know about the placement rules of ا - alif
alphabet in a word.
Ok, here you go!
package main
import (
"log"
)
var jawiAlphabet = map[string]string{}
var rumiAlphabet = map[string]string{}
func main() {
// build the Jawi map
jawiAlphabet["ا"] = "alif"
jawiAlphabet["ب"] = "ba"
jawiAlphabet["ت"] = "ta"
jawiAlphabet["ث"] = "sa(tha)"
jawiAlphabet["ج"] = "jim"
jawiAlphabet["چ"] = "ca"
jawiAlphabet["ح"] = "ha(ḥa)"
jawiAlphabet["خ"] = "kha(khO)"
jawiAlphabet["د"] = "dal"
jawiAlphabet["ذ"] = "zal(dhal)"
jawiAlphabet["ر"] = "ra(rO)"
jawiAlphabet["ز"] = "zai"
jawiAlphabet["س"] = "sin"
jawiAlphabet["ش"] = "syin"
jawiAlphabet["ص"] = "sad(ṣod)"
jawiAlphabet["ض"] = "dad(ḍod)"
jawiAlphabet["ط"] = "ta(ṭo)"
jawiAlphabet["ظ"] = "za(ẓo)"
jawiAlphabet["ع"] = "ain"
jawiAlphabet["غ"] = "ghain"
jawiAlphabet["ڠ"] = "nga"
jawiAlphabet["ف"] = "fa"
jawiAlphabet["ڤ"] = "pa"
jawiAlphabet["ق"] = "qaf"
jawiAlphabet["ک"] = "kaf"
jawiAlphabet["ݢ"] = "ga"
jawiAlphabet["ل"] = "lam"
jawiAlphabet["م"] = "mim"
jawiAlphabet["ن"] = "nun"
jawiAlphabet["و"] = "wau"
jawiAlphabet["ۏ"] = "va"
jawiAlphabet["ه"] = "ha"
jawiAlphabet["ء"] = "hamzah"
jawiAlphabet["ي"] = "ya"
jawiAlphabet["ڽ"] = "nya"
jawiAlphabet["ى"] = "e(ye)"
// build the Rumi map
rumiAlphabet["ا"] = "a"
rumiAlphabet["ب"] = "b"
rumiAlphabet["ت"] = "t"
rumiAlphabet["ث"] = "t'"
rumiAlphabet["ج"] = "j"
rumiAlphabet["چ"] = "c"
rumiAlphabet["ح"] = "H"
rumiAlphabet["خ"] = "H'"
rumiAlphabet["د"] = "d"
rumiAlphabet["ذ"] = "d'"
rumiAlphabet["ر"] = "r"
rumiAlphabet["ز"] = "z"
rumiAlphabet["س"] = "s"
rumiAlphabet["ش"] = "s'"
rumiAlphabet["ص"] = "S"
rumiAlphabet["ض"] = "D"
rumiAlphabet["ط"] = "T"
rumiAlphabet["ظ"] = "Z"
rumiAlphabet["ع"] = "g"
rumiAlphabet["غ"] = "g'"
rumiAlphabet["ڠ"] = "N"
rumiAlphabet["ف"] = "f"
rumiAlphabet["ڤ"] = "p"
rumiAlphabet["ق"] = "q"
rumiAlphabet["ک"] = "k"
rumiAlphabet["ݢ"] = "k'"
rumiAlphabet["ل"] = "l"
rumiAlphabet["م"] = "m"
rumiAlphabet["ن"] = "n"
rumiAlphabet["و"] = "o"
rumiAlphabet["ۏ"] = "v"
rumiAlphabet["ه"] = "h"
rumiAlphabet["ء"] = "-"
rumiAlphabet["ي"] = "y"
rumiAlphabet["ڽ"] = "ñ"
rumiAlphabet["ى"] = "e"
testRumi := "cendawan"
testJawi := "چنداون"
//testRumi := "foto"
//testJawi := "فوتو"
//testRumi := "syampu"
//testJawi := "شمڤو"
log.Println("Breaking down :", testRumi + " --> " + testJawi)
var hurufResult []string
var rumiResult []string
for _,t := range testJawi {
j := jawiAlphabet[string(t)]
r := rumiAlphabet[string(t)]
log.Println(string(t),j,r)
hurufResult = append(hurufResult,j)
rumiResult = append(rumiResult,r)
}
log.Println("hurufResult : ", hurufResult)
log.Println("rumiResult : ", rumiResult)
}
Sample output:
2020/01/12 20:27:34 Breaking down : syampu --> شمڤو
2020/01/12 20:27:34 ش syin s'
2020/01/12 20:27:34 م mim m
2020/01/12 20:27:34 ڤ pa p
2020/01/12 20:27:34 و wau o
2020/01/12 20:27:34 hurufResult : [syin mim pa wau]
2020/01/12 20:27:34 rumiResult : [s' m p o]
Hope this helps and happy coding!
See also : Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.9k Golang : HTTP Server Example
+78.1k Golang : How to return HTTP status code?
+18.8k Golang : Clearing slice
+9.1k Golang : Find the length of big.Int variable example
+7k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+37.1k Upload multiple files with Go
+4.6k Golang : A program that contain another program and executes it during run-time
+13.8k Javascript : Prompt confirmation before exit
+42.8k Golang : Get hardware information such as disk, memory and CPU usage
+5.2k Golang *File points to a file or directory ?
+8.9k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+12.4k Golang : Pass database connection to function called from another package and HTTP Handler