Giter Club home page Giter Club logo

bpmf_py_dart's Introduction

bmpf_py A bopomofo and pinyin library

Features

  • It handles parsing of Bopomofo (注音符號) and Hanyu Pinyin (漢語拼音), two of the most popular phonetic notations of modern standard Mandarin;
  • It supports parsing of Pinyin written with tone mark diacritics.
  • It recognizes ascii pinyin in which tones are represented with trailing numbers and the letter 'v' is used as the replacement of the less accessible 'ü';
  • It supports mutual conversion between Bopomofo and Pinyin;
  • It supports mutual conversion between the ascii pinyin and the standard form, which is toned with marks;
  • It's lightweight and efficient both cpu- and memory-wise'
  • It stands alone having no dependency;
  • It's thoroughly tested;
  • It's easy to use. It consists of only a single class, provided with simple and intuitive properties and methods.
  • It only handles pinyin in lower case;

bmpf_py 專注注音拼音處理

特點

  • 對「注音符號」和「漢語拼音」進行綴字分析,識別音節(含聲調),生成音節對象(BpSyllable)
  • 支持非標準 ASCII 拼音(以 v 代 ü,以數字標調)
  • 實現注音、拼音、ASCII 拼音兩兩相互轉換
  • 輕量、高效
  • 無外部依賴
  • 充分測試
  • 簡潔易用。只包括一個class,並配備直觀應手的 props 和 methods
  • 只支持小寫拼音

Usage · 用法

import 'package:bpmf_py/bpmf_py.dart';
import 'package:bpmf_py/bpmf_codes.dart';

void main() {
  //You can create a mandarin syllable directly with the contructor.

  const shuai4 = BpmfSyllable($sh, $u, $ai, 4);

  print(shuai4); //outputs: ㄕㄨㄞˋ

  // `$sh, $u, $ai` are just integer charCode, cuz dart doesn't have a char type
  // we have to use integers, bpmf_codes defined the full set of characters used
  // by bopomofo and pinyin:
  //    lower case ones represent bopomofo symbols  - eg. $eng for 'ㄥ'
  //    upper case ones represent vanilla latin letters - eg. $Z for 'z'
  //    $1 - $5 are bopomofo tonemarks

  var txt = '\t ㄎㄨㄟˋ ㄖㄣˊ';
  //Parse bopomofo
  var (syl, pos) = BpmfSyllable.parseBopomofo('\t ㄎㄨㄟˋ ㄖㄣˊ');
  //It skips spaces and returns the first recognized syllable and the
  //new position of the letter immediately after the syllable

  print(syl); //outputs: 'ㄎㄨㄟˋ'

  //Continue to parse the next syllable
  (syl, pos) = BpmfSyllable.parseBopomofo(txt, pos: pos);
  print(syl); //outputs: 'ㄖㄣˊ'

  //If the text is ill-formed...
  (syl, pos) = BpmfSyllable.parseBopomofo('万X尢', pos: 0);
  //... it returns an empty syllable and keeps the pos unchanged
  print('The syllable is "$syl", next index is $pos');
  //outpus: The syllable is "", next index is 0

  //If you don't care about the continuous parsing you can simply use the factory
  //method, ignore the position.
  syl = BpmfSyllable.fromBopomofo(txt);
  print("'$syl' again!"); //outputs: 'ㄎㄨㄟˋ' again!

  //parsing pinyin and ascii pinyin are similar:
  txt = 'ráo';
  syl = BpmfSyllable.fromPinyin(txt);
  print(syl.pinyin); //outputs:'ráo'

  txt = 'lve4';
  syl = BpmfSyllable.fromAsciiPinyin(txt);
  print(syl.pinyin); //outputs:'lüè'

  //try BpmfSyllable.parsePinyin and BpmfSyllable.parseAsciiPinyin yourself!

  //The syllable object is equatable and comparable
  syl = BpmfSyllable($r, $u, $ang, 3); // a fabricated sound
  final syl2 = BpmfSyllable.fromAsciiPinyin('ruang3');
  assert(syl == syl2);

  final syllables = ['zhuan4', 'an3', 'an1', 'bo2', 'qi3']
      .map(BpmfSyllable.fromAsciiPinyin)
      .toList();
  syllables.sort((a, b) => a.compareTo(b));
  print(
      syllables.map((x) => x.asciiPinyin)); //out: (bo2, qi3, zhuan4, an1, an3)
  //The order conforms to the order of bopomofo: b p ... i u ü

  //For you convenience the following helper functions are also provided:
  print(pinyinToAsciiPinyin('ráo')); //outputs: rao2
  print(asciiPinyinToPinyin('rao2')); //outputs: ráo
  print(bopomofoToPinyin('ㄑㄩㄥ')); //outputs: 'qiōng'
  print(pinyinToBopomofo('qiōng')); //outputs: 'ㄑㄩㄥ
  print(asciiPinyinToBopomofo('qiong1')); //outputs: 'ㄑㄩㄥ
  print(bopomofoToAsciiPinyin('ㄑㄩㄥ')); //outputs: 'qiong1
}

bpmf_py_dart's People

Watchers

 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.