net.sourceforge.pinyin4j
Class PinyinFormatter

java.lang.Object
  extended by net.sourceforge.pinyin4j.PinyinFormatter

 class PinyinFormatter
extends java.lang.Object

Contains logic to format given Pinyin string

Author:
Li Min (xmlerlimin@gmail.com)

Constructor Summary
PinyinFormatter()
           
 
Method Summary
private static java.lang.String convertToneNumber2ToneMark(java.lang.String pinyinStr)
          Convert tone numbers to tone marks using Unicode

Algorithm for determining location of tone mark
A simple algorithm for determining the vowel on which the tone mark appears is as follows:
First, look for an "a" or an "e".
(package private) static java.lang.String formatHanyuPinyin(java.lang.String pinyinStr, HanyuPinyinOutputFormat outputFormat)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PinyinFormatter

PinyinFormatter()
Method Detail

formatHanyuPinyin

static java.lang.String formatHanyuPinyin(java.lang.String pinyinStr,
                                          HanyuPinyinOutputFormat outputFormat)
                                   throws BadHanyuPinyinOutputFormatCombination
Parameters:
pinyinStr - unformatted Hanyu Pinyin string
outputFormat - given format of Hanyu Pinyin
Returns:
formatted Hanyu Pinyin string
Throws:
BadHanyuPinyinOutputFormatCombination

convertToneNumber2ToneMark

private static java.lang.String convertToneNumber2ToneMark(java.lang.String pinyinStr)
Convert tone numbers to tone marks using Unicode

Algorithm for determining location of tone mark
A simple algorithm for determining the vowel on which the tone mark appears is as follows:
  1. First, look for an "a" or an "e". If either vowel appears, it takes the tone mark. There are no possible pinyin syllables that contain both an "a" and an "e".
  2. If there is no "a" or "e", look for an "ou". If "ou" appears, then the "o" takes the tone mark.
  3. If none of the above cases hold, then the last vowel in the syllable takes the tone mark.

Parameters:
pinyinStr - the ascii represention with tone numbers
Returns:
the unicode represention with tone marks