This is a rewrite of Shabad OS's gurmukhi-utils to C#. Gurmukhi Utils are general utilities for working with Gurmukhi text data.
using ShabadOS.GurmukhiUtils;
var unicodeGurmukhi = "ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ реерйзрее ри░ри╣ри╛риЙ рее"
var asciiGurmukhi = "so Gru rwKu; vfweI qoie ]1] rhwau ]"
GurmukhiUtils.ToAsciiGurmukhi(unicodeGurmukhi) // => so Gru rwKu; vfweI qoie ]1] rhwau ]
GurmukhiUtils.ToUnicodeGurmukhi(asciiGurmukhi) // => ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ реерйзрее ри░ри╣ри╛риЙ рее
GurmukhiUtils.ToEnglish(asciiGurmukhi) // => so ghar raakh; vaddaaee toie |1| rahaau |
GurmukhiUtils.StripEndings(GurmukhiUtils.ToEnglish(asciiGurmukhi)) // => so ghar raakh; vaddaaee toie
Table of Contents
- Introduction
- Usage
- API
- CountSyllables(text) тЗТ int
- FirstLetters(line) тЗТ string
- IsGurmukhi(text, [exhaustive]) тЗТ bool
- StripAccents(text) тЗТ string
- StripEndings(text) тЗТ string
- StripVishraams(text, [vishraams]) тЗТ string
- ToAsciiGurmukhi(text) тЗТ string
- ToEnglish(line) тЗТ string
- ToHindi(text) тЗТ string
- ToShahmukhi(text) тЗТ string
- ToSyllabicSymbols(text) тЗТ string
- ToUnicodeGurmukhi(text) тЗТ string
- Contributing
- Acknowledgements
- License
Gurmukhi Utils is a library for converting, analyzing, and testing gurmukhi strings.
Gurmukhi Utils C# rewrite is available as ShabadOS.GurmukhiUtils on NuGet.
- Install ShabadOS.GurmukhiUtils package via NuGet.
- Add
using ShabadOS.GurmukhiUtils
- Done!
Calculates the number of syllables according to Sanskrit prosody, Pingala, Matra/Meter/Morae.
Returns: int
- An integer adding up all the 1"s (laghu/light/short) and 2"s (guru/heavy/long).
Param | Type | Description |
---|---|---|
text | string |
The string to analyze |
Example
CountSyllables("рикрйНри░ринрйВ рикрйНри░рйЗриорйА рикрйЬрйНри╣ риЪрйЬрйНри╣ рижрйНри╡рйИрид")
// expected output: 14
Generates the first letters for a unicode Gurmukhi, Hindi transliteration, or English transliteration string. Includes any end-word vishraams, and line-end characters.
Returns: string
- The first letters of each word in the provided Gurmukhi line.
Param | Type | Description |
---|---|---|
line | string |
The line to generate the first letters for. |
Example (Gurmukhi first letters)
FirstLetters("ри╕римрижри┐ риори░рйИ. ри╕рйЛ риори░ри┐ ри░ри╣рйИ; рилри┐ри░ри┐. риори░рйИ рии, рижрйВриЬрйА ри╡ри╛ри░ рее") // => ри╕рио.ри╕риори░;рил.риории,рижри╡рее
Example (Hindi first letters)
FirstLetters("рдЧреБрд░рдореБрдЦрд┐ рд▓рд╛рдзрд╛ рдордирдореБрдЦрд┐ рдЧрд╡рд╛рдЗрдЖ рее") // => рдЧрд▓рдордЧрее
Example (English first letters)
FirstLetters("sabad marai. so mar rahai; fir. marai na, doojee vaar |") // => sm.smr;f.mn,dv|
Checks if first char in string is part of the Gurmukhi Unicode block.
Returns: bool
- True if Unicode Gurmukhi, false if other.
Param | Type | Default | Description |
---|---|---|---|
text | string |
The text to check. | |
[exhaustive] | bool |
false |
If true , checks if the whole string is Unicode Gurmukhi. |
Example
IsGurmukhi("риЧрйБри░риорйБриЦрйА") // => true
IsGurmukhi("gurmuKI") // => false
Removes accents from ASCII/Unicode Gurmukhi letters with their base letter. Useful for generalising search queries.
Returns: string
- A simplified version of the provided Gurmukhi string.
Param | Type | Description |
---|---|---|
text | string |
The text to convert. |
Example
StripAccents("рйЫрйЮрйИри╢ри╕риУ") // => риЬрилрйИри╕ри╕рй│
StripAccents("Z^Svb") // => gKsvb
Strips line endings from any Gurmukhi or translation string. Accepts both Unicode and ASCII input. Useful for generating accurate first letters or modifying non-Gurbani for better display. Not designed for headings or Sirlekhs.
Returns: string
- A ending-less version of the text.
Param | Type | Description |
---|---|---|
text | string |
The text to stip endings from. |
Example (Line ending phrases)
StripEndings("ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ реерйзрее ри░ри╣ри╛риЙ рее") // => ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ
StripEndings("ри╣рйБриХриорйБ рикриЫри╛ригри┐; ридри╛ риЦри╕риорйИ риори┐ри▓ригри╛ реерйзрее ри░ри╣ри╛риЙ рижрйВриЬри╛ рее") // => ри╣рйБриХриорйБ рикриЫри╛ригри┐; ридри╛ риЦри╕риорйИ риори┐ри▓ригри╛
StripEndings("риЬрии риири╛риириХ. риЧрйБри░риорйБриЦри┐ риЬри╛ридри╛ ри░ри╛рио реерйкреерймрее риЫриХри╛ рйз рее") // => риЬрии риири╛риириХ. риЧрйБри░риорйБриЦри┐ риЬри╛ридри╛ ри░ри╛рио
Example (English Translations)
StripEndings("O Nanak, Forever And Ever True. ||1||") // => O Nanak, Forever And Ever True.
StripEndings("lush greenery. ||1||Pause||") // => lush greenery.
StripEndings("always I live within the Khalsa. 519") // => always I live within the Khalsa.
StripEndings("without your reminiscence.(1) (3)") // => without your reminiscence.
Example (Spanish Translations)
StripEndings("ofrece su ser en sacrificio a Ti. (4-2-9)") // => ofrece su ser en sacrificio a Ti.
Removes the specified vishraams from a string.
Returns: string
- A vishraam-less Gurmukhi string.
Param | Type | Default | Description |
---|---|---|---|
text | string |
The text to remove vishraams from. | |
[vishraams] | Vishraam |
Vishraam.Heavy | Vishraam.Medium | Vishraam.Light | The vishraams to remove. Defaults to all. |
Example (Text only, default options)
StripVishraams("ри╕римрижри┐ риори░рйИ. ри╕рйЛ риори░ри┐ ри░ри╣рйИ;") // => "ри╕римрижри┐ риори░рйИ ри╕рйЛ риори░ри┐ ри░ри╣рйИ
StripVishraams("sbid mrY. so mir rhY; iPir.") // => sbid mrY so mir rhY iPir
Example (Heavy vishraams only)
StripVishraams("sbid mrY. so mir rhY; iPir.", Vishraam.Heavy) // => sbid mrY. so mir rhY iPir.
Example (Medium vishraams only)
StripVishraams("Anhd sbd vjwey,", Vishraam.Medium) // => Anhd sbd vjwey
Example (Light vishraams only)
StripVishraams("sbid mrY. so, mir rhY; iPir.", Vishraam.Light) // => sbid mrY so mir rhY; iPir
Example (Heavy and Medium vishraams only)
StripVishraams("sbid mrY. so, mir rhY; iPir.", Vishraam.Heavy | Vishraam.Medium) // => sbid mrY. so mir rhY iPir.
Converts Gurmukhi unicode text to ASCII, used GurmukhiAkhar font.
Returns: string
- An ASCII representation of the provided unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | string |
The unicode text to convert. |
Example
ToAsciiGurmukhi("ри╣риори╛ ри╕ри╛риЗри▓ри┐ ри▓рйБридрйЮри┐ ри╣риХ рикри░ри╡ри░ри╢ рее") // => hmw swieil luqi& hk prvrS ]
ToAsciiGurmukhi("ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее") // => su bYiT iekMqR ]578]
Transliterates a line from Unicode Gurmukhi to english.
Currently supports the ,
, ;
, .
vishraam characters.
Returns: string
- The English transliteration of the provided Gurmukhi line.
Param | Type | Description |
---|---|---|
line | string |
The Gurmukhi Unicode line to transliterate. |
Example
ToEnglish("ри╣рйБриХриорйА ри╣рйБриХриорйБ риЪри▓ри╛риП ри░ри╛ри╣рйБ рее") // => hukamee hukam chalaae raahu ||
Example
ToEnglish("ринри╛риВрибри╛ ринри╛риЙ риЕрй░риорйНри░ри┐ридрйБ ридри┐ридрйБ риври╛ри▓ри┐ рее") // => bhaa(n)ddaa bhaou anmrit tit dtaal ||
Transliterates Unicode Gurmukhi text to Hindi (Devanagari script).
Returns: string
- A Hindi transliteration of the provided Unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | string |
The Unicode Gurmukhi text to convert. |
Example
ToHindi("риХрйБри▓ риЬрии риоризрйЗ риори┐ри▓рй╡рйЛри┐ ри╕ри╛ри░риЧ рикри╛рии ри░рйЗ рее") // => рдХреБрд▓ рдЬрди рдордзреЗ рдорд┐рд▓реНрдпреЛ рд╕рд╛рд░рдЧ рдкрд╛рди рд░реЗ рее
ToHindi("ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее") // => рд╕реБ рдмреИрда рдЗрдХрдВрддреНрд░ реерелренреорее
Transliterates Unicode Gurmukhi text to the Shahmukhi script.
Returns: string
- A Shahmukhi transliteration of the provided Unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | string |
The Unicode Gurmukhi text to convert. |
Example
ToShahmukhi("ри╣риори╛ ри╕ри╛риЗри▓ри┐ ри▓рйБридрйЮри┐ ри╣риХ рикри░ри╡ри░ри╢ рее") // => ┘З┘Е╪з ╪│╪з┘Р╪з┘Д ┘Д┘П╪к┘Б ┘З┌й ┘╛╪▒┘И╪▒╪┤ █Ф█Ф
ToShahmukhi("ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее") // => ╪│┘П ╪и┘О█Т┘╣┌╛ ┘Р╪з┌й┌║╪к╪▒ █Ф█Ф█╡█╖█╕█Ф█Ф
Represents text in syllables according to Sanskrit prosody, Pingala, Matra/Meter/Morae
Returns: string
- A syllabic representation of 1"s (laghu/light/short) and 2"s (guru/heavy/long).
Param | Type | Description |
---|---|---|
text | string |
The string to convert |
Example
ToSyllabicSymbols( "рикрйНри░ринрйВ рикрйНри░рйЗриорйА рикрйЬрйНри╣ риЪрйЬрйНри╣ рижрйНри╡рйИрид" )
// expected output: "12 22 11 11 21"
Converts ASCII text used in the GurmukhiAkhar font to Unicode.
Returns: string
- A unicode representation of the provided ASCII Gurmukhi string.
Param | Type | Description |
---|---|---|
text | string |
The ASCII text to convert. |
Example
ToUnicodeGurmukhi("kul jn mDy imil┬┤o swrg pwn ry ]") // => риХрйБри▓ риЬрии риоризрйЗ риори┐ри▓рй╡рйЛри┐ ри╕ри╛ри░риЧ рикри╛рии ри░рйЗ рее
ToUnicodeGurmukhi("su bYiT iekMqR ]578]") // => ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее
There are multiple ways to contribute whether you are a user or developer. For example:
- Submit bugs and feature requests.
- Review documentation and make pull requests for anything from typos to new content.
- Give feedback on the onboarding process to make it easier for others to join the project.
All credits go to the maintainers of gurmukhi-utils for creating this wonderful tool which aids in creating Gurmukhi related tools and services.
@Onkarjit is the maintainer of this repository which is a C# rewrite of gurmukhi-utils.
Licensed under the GPL v3.