Git Product home page Git Product logo

zh2py's Introduction

Zh2py -- 汉字转拼音方案

zh2py是一个简单而高效的汉字转拼音方案,提供php和python扩展,

实现方式:将汉字转换成数字序号,然后去词表数组中查询拼音.词表已经事先生成好, 存储在dict/gbk.dict中,由mmap加载.

示例:

<?php
if(zh2py_load_table("../dict/gbk.dict")){
 $chinese = "测试数据";
 print zh2py_get_pinyin($chinese)."\n";
}
#!/usr/bin/env python
import zh2py
zy = zh2py.Zh2Py()
zy.load_table("../dict/gbk.dict")
data = open("./testdata/gbkall").read()
print zy.get_pinyin(data)
print zy.get_pinyin(data)

本项目还整理了一个多音字的词库,存入在dict/polymorphic.dict;示例文件是php-example/test_poly.php:

<?php
include "./Zh2pyPoly.php";
$z2p = new Zh2pyPoly("../dict/polymorphic.dict","../dict/gbk.dict");
print_r($z2p->getPinyin("我们都是**人.我有一匹黄骠马.我屏息屏气.一页扁舟来."));

注意,如果运行php的时候拼音结果出不来,请注意查看php文件编码是否是GBK;

zh2py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.