Convert Chinese character to PinYin

linux
Written by Joe   
Thursday, 03 July 2008 08:28

Convert Chinese character to PinYin

We usually need convert Chinese character to pinyin, here is a java helper that can convert Chinse character to pinyin. It also allow you to give a connector between pinyins.

package base.helper;

public class PinYinHelper {
private static String[] name = { "zuo", "zun", "zui", "zuan", "zu", "zou",
"zong", "zi", "zhuo", "zhun", "zhui", "zhuang", "zhuan", "zhuai",
"zhua", "zhu", "zhou", "zhong", "zhi", "zheng", "zhen", "zhe",
"zhao", "zhang", "zhan", "zhai", "zha", "zeng", "zen", "zei", "ze",
"zao", "zang", "zan", "zai", "za", "yun", "yue", "yuan", "yu",
"you", "yong", "yo", "ying", "yin", "yi", "ye", "yao", "yang",
"yan", "ya", "xun", "xue", "xuan", "xu", "xiu", "xiong", "xing",
"xin", "xie", "xiao", "xiang", "xian", "xia", "xi", "wu", "wo",
"weng", "wen", "wei", "wang", "wan", "wai", "wa", "tuo", "tun",
"tui", "tuan", "tu", "tou", "tong", "ting", "tie", "tiao", "tian",
"ti", "teng", "te", "tao", "tang", "tan", "tai", "ta", "suo",
"sun", "sui", "suan", "su", "sou", "song", "si", "shuo", "shun",
"shui", "shuang", "shuan", "shuai", "shua", "shu", "shou", "shi",
"sheng", "shen", "she", "shao", "shang", "shan", "shai", "sha",
"seng", "sen", "se", "sao", "sang", "san", "sai", "sa", "ruo",
"run", "rui", "ruan", "ru", "rou", "rong", "ri", "reng", "ren",
"re", "rao", "rang", "ran", "qun", "que", "quan", "qu", "qiu",
"qiong", "qing", "qin", "qie", "qiao", "qiang", "qian", "qia",
"qi", "pu", "po", "ping", "pin", "pie", "piao", "pian", "pi",
"peng", "pen", "pei", "pao", "pang", "pan", "pai", "pa", "ou", "o",
"nuo", "nue", "nuan", "nv", "nu", "nong", "niu", "ning", "nin",
"nie", "niao", "niang", "nian", "ni", "neng", "nen", "nei", "ne",
"nao", "nang", "nan", "nai", "na", "mu", "mou", "mo", "miu",
"ming", "min", "mie", "miao", "mian", "mi", "meng", "men", "mei",
"me", "mao", "mang", "man", "mai", "ma", "luo", "lun", "lue",
"luan", "lv", "lu", "lou", "long", "liu", "ling", "lin", "lie",
"liao", "liang", "lian", "lia", "li", "leng", "lei", "le", "lao",
"lang", "lan", "lai", "la", "kuo", "kun", "kui", "kuang", "kuan",
"kuai", "kua", "ku", "kou", "kong", "keng", "ken", "ke", "kao",
"kang", "kan", "kai", "ka", "jun", "jue", "juan", "ju", "jiu",
"jiong", "jing", "jin", "jie", "jiao", "jiang", "jian", "jia",
"ji", "huo", "hun", "hui", "huang", "huan", "huai", "hua", "hu",
"hou", "hong", "heng", "hen", "hei", "he", "hao", "hang", "han",
"hai", "ha", "guo", "gun", "gui", "guang", "guan", "guai", "gua",
"gu", "gou", "gong", "geng", "gen", "gei", "ge", "gao", "gang",
"gan", "gai", "ga", "fu", "fou", "fo", "feng", "fen", "fei",
"fang", "fan", "fa", "er", "en", "e", "duo", "dun", "dui", "duan",
"du", "dou", "****", "diu", "ding", "die", "diao", "dian", "di",
"deng", "de", "dao", "dang", "dan", "dai", "da", "cuo", "cun",
"cui", "cuan", "cu", "cou", "cong", "ci", "chuo", "chun", "chui",
"chuang", "chuan", "chuai", "chu", "chou", "chong", "chi", "cheng",
"chen", "che", "chao", "chang", "chan", "chai", "cha", "ceng",
"ce", "cao", "cang", "can", "cai", "ca", "bu", "bo", "bing", "bin",
"bie", "biao", "bian", "bi", "beng", "ben", "bei", "bao", "bang",
"ban", "bai", "ba", "ao", "ang", "an", "ai", "a" };

private static int[] code = { -10254, -10256, -10260, -10262, -10270,
-10274, -10281, -10296, -10307, -10309, -10315, -10322, -10328,
-10329, -10331, -10519, -10533, -10544, -10587, -10764, -10780,
-10790, -10800, -10815, -10832, -10838, -11014, -11018, -11019,
-11020, -11024, -11038, -11041, -11045, -11052, -11055, -11067,
-11077, -11097, -11303, -11324, -11339, -11340, -11358, -11536,
-11589, -11604, -11781, -11798, -11831, -11847, -11861, -11867,
-12039, -12058, -12067, -12074, -12089, -12099, -12120, -12300,
-12320, -12346, -12359, -12556, -12585, -12594, -12597, -12607,
-12802, -12812, -12829, -12831, -12838, -12849, -12852, -12858,
-12860, -12871, -12875, -12888, -13060, -13063, -13068, -13076,
-13091, -13095, -13096, -13107, -13120, -13138, -13147, -13318,
-13326, -13329, -13340, -13343, -13356, -13359, -13367, -13383,
-13387, -13391, -13395, -13398, -13400, -13404, -13406, -13601,
-13611, -13658, -13831, -13847, -13859, -13870, -13878, -13894,
-13896, -13905, -13906, -13907, -13910, -13914, -13917, -14083,
-14087, -14090, -14092, -14094, -14097, -14099, -14109, -14112,
-14122, -14123, -14125, -14135, -14137, -14140, -14145, -14149,
-14151, -14159, -14170, -14345, -14353, -14355, -14368, -14379,
-14384, -14399, -14407, -14429, -14594, -14630, -14645, -14654,
-14663, -14668, -14670, -14674, -14678, -14857, -14871, -14873,
-14882,

-14889, -14894, -14902, -14908, -14914, -14921, -14922, -14926,
-14928, -14929, -14930, -14933, -14937, -14941, -15109, -15110,
-15117, -15119, -15121, -15128, -15139, -15140, -15141, -15143,
-15144, -15149, -15150, -15153, -15158, -15165, -15180, -15183,
-15362, -15363, -15369, -15375, -15377, -15385, -15394, -15408,
-15416, -15419, -15435, -15436, -15448, -15454, -15625, -15631,
-15640, -15652, -15659, -15661, -15667, -15681, -15701, -15707,
-15878, -15889, -15903, -15915, -15920, -15933, -15944, -15958,
-15959, -16155, -16158, -16169, -16171, -16180, -16187, -16202,
-16205, -16212, -16216, -16220, -16393, -16401, -16403, -16407,
-16412, -16419, -16423, -16427, -16429, -16433, -16448, -16452,
-16459, -16465, -16470, -16474, -16647, -16657, -16664, -16689,
-16706, -16708, -16733, -16915, -16942, -16970, -16983, -17185,
-17202, -17417, -17427, -17433, -17454, -17468, -17482, -17487,
-17496, -17676, -17683, -17692, -17697, -17701, -17703, -17721,
-17730, -17733, -17752, -17759, -17922, -17928, -17931, -17947,
-17950, -17961, -17964, -17970, -17988, -17997, -18012, -18181,
-18183, -18184, -18201, -18211, -18220, -18231, -18237, -18239,
-18446, -18447, -18448, -18463, -18478, -18490, -18501, -18518,
-18526, -18696, -18697, -18710, -18722, -18731, -18735, -18741,
-18756, -18763, -18773, -18774, -18783, -18952, -18961, -18977,
-18996, -19003, -19006, -19018, -19023, -19038, -19212, -19218,
-19224, -19227, -19235, -19238, -19242, -19243, -19249, -19261,
-19263, -19270, -19275, -19281, -19288, -19289, -19467, -19479,
-19484, -19500, -19515, -19525, -19531, -19540, -19715, -19725,
-19728, -19739, -19741, -19746, -19751, -19756, -19763, -19774,
-19775, -19784, -19805, -19976, -19982, -19986, -19990, -20002,
-20026, -20032, -20036, -20051, -20230, -20242, -20257, -20265,
-20283, -20292, -20295, -20304, -20317, -20319 };

public static String pinyin(String content) {
if (MiscHelper.isBlank(content)) {
return content;
}
content = content.trim();

char[] chars = content.toCharArray();
StringBuffer retuBuf = new StringBuffer();
for (int i = 0, Len = chars.length; i < Len; i++) {
retuBuf.append(getPinyin(chars, i));

}

String result = MiscHelper.replaceAll(retuBuf.toString().toLowerCase(),
"[^a-z0-9-]", "");
if (MiscHelper.isBlank(seperator)) {
return result;
} else {
return MiscHelper.replaceAll(result, seperator + seperator,
seperator);
}
}

public static String seperator = "-";

private static boolean isAscii(int ascii) {
return ascii > 0 && ascii < 160;
}

private static String getPinyin(char[] chars, int index) {
char c = chars[index];
int ascii = getCnAscii(c);
if (ascii == 0) {
return String.valueOf(c);
} else {
String spell = getSpellByAscii(ascii);
if (spell == null) {
return String.valueOf(c);
} else {
if (isAscii(ascii)) {
if (index < chars.length - 1) {
if (ascii == 32) {
return seperator;
}
int next = getCnAscii(chars[index + 1]);
if (isAscii(next)) {
return spell;
}
} else {
if (ascii == 32) {
return "";
}
return spell;
}
}
if (index < chars.length - 1) {
return spell + seperator;
} else {
return spell;
}
}

}
}

private static int getCnAscii(char cn) {

byte[] bytes = null;
try {
bytes = (String.valueOf(cn)).getBytes("GB2312");
} catch (Exception e) {
e.printStackTrace();
}
if (bytes == null || bytes.length > 2 || bytes.length <= 0) {
return 0;
}
if (bytes.length == 1) {
return bytes[0];
} else {
int hightByte = 256 + bytes[0];
int lowByte = 256 + bytes[1];
int ascii = (256 * hightByte + lowByte) - 256 * 256;
return ascii;
}
}

private static String getSpellByAscii(int ascii) {
if (ascii > 0 && ascii < 160) {
return String.valueOf((char) ascii);
}
if (ascii < -20319 || ascii > -10247) {
return "";
}
int ind;

for (ind = 0; ind < code.length; ind++) {
if (ascii >= code[ind]) {
break;
}
}
return name[ind];
}

}
 
 
linux
Joomla Plugin--Random content
Written by Joe   
Monday, 30 June 2008 07:31

Shuffle it up with RandomContent, a plugin for Joomla 1.5.
RandomContent displays random content at the bottom of articles browsed by users. Displayed content is drawn from the same category the browsed article-belongs to.
The plugin proves useful in a variety of situations, for example, when website managers are interested in increasing exposure of content through similar article displays.


V1.1
1. Fix unset variable bugs.

2. Add category exclusion. Articles from the categories will not show random contents. This is helpful for 'About us' articles.

3. Add category selection. No matter what  category the browsed article belongs to ,the rand content plugin will show articles from the set categories.

Please download from the attachement.

Attachments:
 RandomContent1.1.zip2 Kb
 
What Parameters Are Available for Joomla extensions?
Written by Joe   
Saturday, 28 June 2008 10:25

Modules, plug-ins, and components all allow you to define configuration parameters through XML files. Many common parameter types are predefined and can be used in Joomla extensions. Every parameter you define must have five basic attributes.

  1. Parameter name, so you can reference it later in your code.
  2. A default value to be displayed and used if no value is chosen.
  3. A visible label
  4. A description appearing when the mouse cursor hovers over it
  5. The type of parameter

A categorized list is below:

Content

section - All published sections in a list category - All published categories in a list

Text Input

text - A standard text input

textarea - A plain textarea field

password - A standard text input where the characters are masked as they are entered editors - Provides the admin's currently chosen WYSIWYG editor for input

Selections

menu - All published menus in a lis

t menuitem - All published menu items in a list

filelist - A list of files to choose from, given a base folder path

folderlist - A list of folders to choose from, given a base folder path

imagelist - A list of images to choose from, given a base folder

path list - A list of items to choose from (hardcoded into parameter definition)

radio - A list of radio selection items to choose from (hardcoded into parameter definition) sql - Creates a dropdown list out of a provided SQL query

Predefined

helpsites - A list of websites powering help file translations to choose from

languages - A list of installed languages to choose from

spacer - Creates a visual separation between parameters; no input value is required timezones - A list of all world timezones

Other

hidden - Creates a hidden form element with the value and name provided

 
What Events Can be Registered in Joomla 1.5?
Written by Joe   
Saturday, 28 June 2008 09:58

Plug-ins in Joomla can respond to any number of events during a request.

Multiple plug-ins can respond to any one event in their group. The ordering of the plug-ins in Joomla's back end determines the order which registered functions are called. For instance, if both plug-in A and plug-in B respond to onBeforeDisplayContent, A's function registered with onBeforeDisplayContent will be called first.

A listing of when these events occur, grouped by plug-in type is as follows:

System

onAfterInitialise – after the framework loads, but before routing and output onAfterRoute – after routing, but before output onAfterDispatch – after the Joomla! application is started onAfterRender – after all output is processed onGetWebServices – when the XML-RPC function requests a list of valid function calls onLoginFailure – when a login attempt fails

Search

onSearch – when a search is performed onSearchAreas – when the search component requests a list of valid search areas

Authentication

onAuthenticate – when a user initially attempts to authenticate, provides a method for authentication

 

User

onLoginUser – after a user initally authenticates, but before fully logged in: all functions must return true finish to authenticate onLogoutUser – when a user attempts to logout: all functions must return true to logout onBeforeStoreUser – just before a user is stored in the database onAfterStoreUser – after a user is stored in the database onBeforeDeleteUser – just before a user is deleted from the system onAfterDeleteUser – just after a user is deleted from the system

Editor-xtd

onCustomEditorButton – when custom editor buttons are loaded, allows the additon of buttons

Editor

onInit – when the editor is initialized onDisplay – when the editor is ready to be displayed onGetContent – when the contents of the editor are requested onSetContent – when the contents of the editor are populated onSave – when the contents of the editor are saved onGetInsertMethod – just before the editor is output

Content

onPrepareContent – before any output occurs onAfterDisplayTitle – just after article title is displayed onBeforeDisplayContent – just before content is output, returns output to be displayed onAfterDisplayContent – just after content is output, returns output to be displayed

 
How to extend Joomla? Components, Modules, or Plug-in?
Written by Joe   
Saturday, 28 June 2008 09:32

There are three types of extensions that Joomla supports: Component, Module, and Plug-in, each with a specific use.

Components

Of the three extensions , components are the most essential. Components are essentially what you see in the "main" portion of the page. Joomla is designed to load and run exactly one component for each page. Consequently, Joomla's core content management functionality is itself a component. Components frequently have sophisticated back-end controls. The back end is commonly used to create and update records in database tables; also it can do typically anything, provided it is programmed in PHP. For instance, you may have a batch job that typically runs from a UNIX command line, but you can use the back end to provide a link where non-programmers can call it. You can also use it to allow site administrators to upload pictures or videos. The official components include com_content,com_contact,com_search,and com_weblinks etc.

Modules

In contrast to components, any number of modules can appear on a page. Modules typically make up the elements of a sidebar or content menus. Modules complement the content contained in a component; they are not intended to be the main substance of a page. Joomla also supports content modules, which involve no programming and can be displayed alongside the components. The back-end controls for modules are limited, typically consisting of basic formatting. The official modules include mod_login,mod_latestnews,mod_related_items,mod_mostread, and mod_mainmenu etc.

Plug-Ins(Mambot)

When a piece of code is needed throughout the site, it is best implemented as a plug-in (formerly called a Mambot). Plug-ins are commonly used to format the output of a component or module when a page is built. Some examples of plug-ins include keyword highlighting, article comment boxes, and JavaScript-based HTML editors. Plug-ins can also be used to extend the results found in the core search component. The back-end controls are similar to those of modules. Plug-Ins mainly includes authentication, content, editors, editors-xtd, search, system, user,xmlrpc types. For content type, the officail modules include pagenavigation, geshi,vote, and pagebreak etc.

Summary

Joomla can be extended through components, modules, and plug-ins. This allows you to add functionalities to a Joomla site without hacking the core code. Joomla can then be maintained and updated without disturbing the custom code.

 
More Articles...
<< Start < Prev 1 2 3 4 5 6 7 8 9 Next > End >>

Page 6 of 9