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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

┬а

History

1 Commit
┬а
┬а
┬а
┬а
┬а
┬а
┬а
┬а
┬а
┬а
┬а
┬а

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