My favorites | Sign in
Project Logo
                
Search
for
PrimezeroTools  
PrimezeroTools 0.9.x - pre-production release

Current Version: 0.9.4

This is a pre-production release, using PHP 5.2.x or later

Introduction

PrimezeroTools is a simple, open source toolset for Chinese language processing. It contains many of the tools used to build applications like Primezero Chinese Tools.

Download PrimezeroTools

I want to help you build your own e-learning applications, so I am providing the source code for free.

Sample Usage: Primezero Chinese Tools

Primezero Chinese Tools uses a loosely-coupled group of frameworks to "do work on words".

Sample Usage: Primezero i18n Terminal

Primezero i18n Terminal provides quick, intuitive tools uses PrimezeroTools.

Definitions

Index Files

  • IndexFiles - codecs for pinyintypes and hanzitypes

Mega Methods (upper class)

Puny Methods (middle and lower class)


TCB - Taking Care of Business

Ready. Set. Sprint.

Sample Code + Output: Hello World


$pzt = new PrimezeroTools();

// prints 'hello world' in Chinese
echo $hello_world = "世界你好";


// prints 'hello world' in hanyu pinyin 
// outputs -- shi4 jie4 ni3 hao3 
echo $got_pinyin = $pzt->pzhanzi_hanzi_to_pinyin($hello_world);


// prints 'hello world' in hanyu pinyin with tone marks 
// outputs -- shì jiè nĭ hăo 
echo $got_tonemarks = $pzt->pzpinyin_tonedisplay_convert_to_mark($got_pinyin);


// prints 'hello world' in zhuyin fuhao 
// outputs -- ㄕˋ ㄐㄧㄝˋ ㄋㄧˇ ㄏㄠˇ 
echo $got_zhuyin = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_zhuyin($got_pinyin);


// prints 'hello world' in tongyong pinyin 
// outputs --  shih4 jie4 ni3 hao3 
echo $got_tongyong = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_tongyong_pinyin($got_pinyin);


// prints 'hello world' in mandarin yale 
// outputs -- shr4 jye4 ni3 hau3
echo $got_zhuyin = $pzt->pzpinyin_pinyintype_hanyu_pinyin_to_yale($got_pinyin);


// prints 'happy to meet you' in Traditional Chinese 
echo $happy_to_meet_you = "很高興認識你";


// prints 'happy to meet you' in Simplified Chinese
// outputs -- 很高兴认识你
echo $pzt->pzhanzi_traditional_to_simplified($happy_to_meet_you);

Reading CEDICT-compatible Files (pzcedict)

Example Code

# sample line from CEDICT-compatible file
$line = "安頓 安顿 [an1 dun4] /find a place for/help settle down/arrange for/undisturbed/peaceful/";

$pzt = new PrimezeroTools();
print_r($pzt->pzcedict_entry_getvalues($line, TRUE));

Example Output

Array
(
    [trad] => 安頓
    [simp] => 安顿
    [py] => an1 dun4
    [defs] => Array
        (
            [0] => arrange for
            [1] => find a place for
            [2] => help settle down
            [3] => peaceful
            [4] => undisturbed
        )

)

Temperature Calculations (pzkelvin)

$pzt = new PrimezeroTools();


$pzt->pzkelvin_go("-100C in Kelvin",TRUE); 
$pzt->pzkelvin_go("-40 degC in F",TRUE); 
$t_0  = $pzt->pzkelvin_go("-50F at Rankine");       // 409.67
$t_f = $pzt->pzkelvin_go("500K to degC",TRUE);      // 226.85
echo $impossible_temperature  = $pzt->pzkelvin_go("-500F in degC"); 


// ** Example Code Output **/
// -100 Celsius = 173.15 Kelvin 
// -40 Celsius = -40.00 Fahrenheit 
// ** there is no printed output for this line
// 500 Kelvin = 226.85 Celsius 
// no conversions available

Reason For Primezero Kelvin Functions (pzkelvin)

Google Calculator incorrectly calculates temperatures below ZERO KELVIN. This is thermodynamically impossible, as temperature no longer exist below ABSOLUTELY ZERO.

With Primezero Kelvin Functions, you can make calculations between Celsius, Fahrenheit, Rankine and Kelvin that thermodynamically correct (in theory). Thus minimum values allowed are as follows:

  • 0 Kelvin
  • 0 Rankine
  • -273.15 Celsius
  • -459.67 Fahrenheit

Number and Quantity Conversions (pznumbers)

$pzt = new PrimezeroTools();

// positive and negative numbers
echo $pzt->pznumbers_go("33"); // 三十三
echo $pzt->pznumbers_go("-58"); // 負五十八
echo $pzt->pznumbers_go("8888"); // 八千八百八十八
echo $pzt->pznumbers_go("10538"); // 一萬〇五百三十八
echo $pzt->pznumbers_go("-99291"); //  負九萬九千二百九十一


// big positive and negative numbers
echo $pzt->pznumbers_go("100000000"); // 一億
echo $pzt->pznumbers_go("888384848"); // 八億八千八百三十八萬四千八百四十八
echo $pzt->pznumbers_go("8800980088"); // 八十八億九十八萬〇八十八


// long dates
echo $pzt->pznumbers_go("August 8, 2008"); // 二〇〇八年八月八日
echo $pzt->pznumbers_go("October 1, 1949"); // 一九四九年十月一日


// short dates dates MM/DD/YYYY or YYYY/MM/DD
echo $pzt->pznumbers_go("2008/01/20"); // 二〇〇八年一月二十日
echo $pzt->pznumbers_go("08-20-2005"); // 二〇〇五年八月二十日
echo $pzt->pznumbers_go("08.20.2005"); // 二〇〇五年八月二十日


// just translating the year alone
echo $pzt->pznumbers_go("year 2008"); // 二〇〇八年
echo $pzt->pznumbers_go("year 1932"); // 一九三二年
echo $pzt->pznumbers_go("year 2012"); // 二〇一二年


// money, money, money
echo $pzt->pznumbers_go("$2.22"); // 兩塊兩毛兩分
echo $pzt->pznumbers_go("$0.25"); // 兩毛五分
echo $pzt->pznumbers_go("$888,888.32"); // 八十八萬八千八百八十八塊三毛兩分
echo $pzt->pznumbers_go("$89985.62"); // 八萬九千九百八十五塊六毛兩分


// time, tick! tock!
echo $pzt->pznumbers_go("5:09"); // 上午五點九分
echo $pzt->pznumbers_go("8:32"); // 上午八點三十二分
echo $pzt->pznumbers_go("13:59"); // 下午一點五十九分

// time with AM or PM 
echo $pzt->pznumbers_go("2:09 am"); // 上午兩點九分 ** space is ok between time and am/pm
echo $pzt->pznumbers_go("2:12pm"); // 下午兩點十二分



// fractions
echo $pzt->pznumbers_go("3/5"); // 五分之三
echo $pzt->pznumbers_go("8/9"); // 九分之八
echo $pzt->pznumbers_go("-3/8"); // 負八分之三


// decimals
echo $pzt->pznumbers_go("8.29"); // 八點二九
echo $pzt->pznumbers_go("3.14"); // 三點一四
echo $pzt->pznumbers_go("-9.68"); // 負九點六八


// percents
echo $pzt->pznumbers_go("98%"); // 百分之九十八
echo $pzt->pznumbers_go("32%"); // 百分之三十二
echo $pzt->pznumbers_go("-3%"); // 負百分之三

Colophon


Sign in to add a comment
Hosted by Google Code