Skip to content

This is a rewrite of Shabad OS's gurmukhi-utils to C#. Gurmukhi Utils are general utilities for working with Gurmukhi text data.

License

Notifications You must be signed in to change notification settings

onkarjit/ShabadOs.GurmukhiUtils

Repository files navigation

Gurmukhi Utils

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

Gurmukhi Utils is a library for converting, analyzing, and testing gurmukhi strings.

Usage

Gurmukhi Utils C# rewrite is available as ShabadOS.GurmukhiUtils on NuGet.

  1. Install ShabadOS.GurmukhiUtils package via NuGet.
  2. Add using ShabadOS.GurmukhiUtils
  3. Done!

API

CountSyllables(text) ⇒ int

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

FirstLetters(line) ⇒ string

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|

IsGurmukhi(text, [exhaustive]) ⇒ bool

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

StripAccents(text) ⇒ string

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

StripEndings(text) ⇒ string

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.

StripVishraams(text, [vishraams]) ⇒ string

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.

ToAsciiGurmukhi(text) ⇒ string

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]

ToEnglish(line) ⇒ string

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 ||

ToHindi(text) ⇒ string

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("ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥") // => सु बैठ इकंत्र ॥५७८॥

ToShahmukhi(text) ⇒ string

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("ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥") // => سُ بَےٹھ ِاکںتر ۔۔۵۷۸۔۔

ToSyllabicSymbols(text) ⇒ string

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"

ToUnicodeGurmukhi(text) ⇒ string

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]") // => ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥

Contributing

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.

Acknowledgements

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.

License

Licensed under the GPL v3.

About

This is a rewrite of Shabad OS's gurmukhi-utils to C#. Gurmukhi Utils are general utilities for working with Gurmukhi text data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages