All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sktutilities.transliteration.IndicUnicodeTransformer Maven / Gradle / Ivy

Go to download

A collection of scala and java classes for some basic character level processing for the Sanskrit and other Indic (kannada, telugu, etc..) languages, contributed by the open source sanskrit-coders projects and friends. Some notable facilities: * Transliterate text from one script or encoding scheme to another. * Some grammar simulation. Examples: see https://github.com/sanskrit-coders/indic-transliteration Contributions and suggestions are invited at https://github.com/sanskrit-coders/indic-transliteration . (Sister projects there may also be of interest.)

The newest version!
package com.sktutilities.transliteration;

import java.util.ArrayList;
import java.util.Hashtable;

import com.sktutilities.util.VowelUtil;

public class IndicUnicodeTransformer
{

    private Hashtable unicode;

    private Hashtable matra;

    private String halant = "";
    
    public IndicUnicodeTransformer()
    {
        
    }
    public IndicUnicodeTransformer(Hashtable unicode, Hashtable matra, String halant)
    {
        this.unicode = unicode;
        this.matra = matra;
        this.halant = halant;
       
    }
    
    public String transform(String slpString)
    {
    
        String transformed = "";
    
        int strLen = slpString.length();
        ArrayList shabda = new ArrayList();
        String lastEntry = "";
        for (int i = 0; i < strLen; i++)
        {
            char c = slpString.charAt(i);
            String varna = String.valueOf(c);
            
            if (VowelUtil.isConsonant(varna))
            {
                shabda.add(unicode.get(varna));
                shabda.add(halant); //halant
                lastEntry = halant;
            }
    
            else if (VowelUtil.isVowel(varna))
            {
                 if (halant.equals(lastEntry))
                {
                    if (varna.equals("a"))
                    {
                        shabda.set(shabda.size() - 1,"");
                    }
                    else
                    {
                        shabda.set(shabda.size() - 1, matra.get(varna));
                    }
                }
    
                else
                {
                    shabda.add(unicode.get(varna));
                }
                 lastEntry = unicode.get(varna);
            } // end of else if is-Vowel
    
            else if (unicode.containsKey(varna))
            {
                shabda.add(unicode.get(varna));
                lastEntry = unicode.get(varna);
            }
            else
            {
                shabda.add(varna);
                lastEntry = varna;
            }
            
        } // end of for
    
        for (String string: shabda)
        {
            transformed += string;
        }
        
        //Discard the shabda array
        shabda = null;
        return transformed; // return transformed;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy