ting 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module Ting
2
+ module Tones
3
+ class Supernum < Tone
4
+ class <<self
5
+
6
+ GLYPHS=['', '¹', '²', '³', '⁴',] #⁰ for neutral tone?
7
+
8
+ def add_tone(syll,tone)
9
+ syll + GLYPHS[normalize(tone) % 5]
10
+ end
11
+
12
+ def peek_tone(syll)
13
+ return t if t = GLYPHS.index(syll.chars[-1])
14
+ return NEUTRAL_TONE
15
+ end
16
+
17
+ def pop_tone(syll)
18
+ [ peek_tone(syll), syll[/\A[^#{GLYPHS.join}]+/] ]
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'ting'
2
+ require 'test/unit'
3
+ require 'csv'
4
+
5
+
6
+ # This test uses the chart from piyin.info to compare all implemted conversion types
7
+ # Since I can't find another reference of the hanyu pinyin 'lo', I have removed it from the table
8
+
9
+ class TestCompare < Test::Unit::TestCase
10
+ CHART=CSV.parse(IO.read(File.dirname(__FILE__)+'/../lib/ting/data/comparison.csv'))
11
+ COMPARE=[:hanyu, :wadegiles, :zhuyin, :tongyong]
12
+
13
+
14
+ # Test all combinations, included parsing/unparsing the same type
15
+
16
+ def test_do_comparisons
17
+ COMPARE.each do |from|
18
+ COMPARE.each do |to|
19
+ compare(from,to)
20
+ end
21
+ end
22
+ end
23
+
24
+ def compare(from, to)
25
+ reader = Ting.reader(from, :no_tones)
26
+ writer = Ting.writer(to, :no_tones)
27
+
28
+ ifrom = CHART[0].index from.to_s
29
+ ito = CHART[0].index to.to_s
30
+
31
+ CHART[1..-1].each do |vals|
32
+ assert_equal(vals[ito].strip, writer << (reader << vals[ifrom].strip), "Converting from #{from} to #{to} value #{vals[ito]}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'ting'
3
+ require 'yaml'
4
+
5
+ $KCODE='u'
6
+
7
+ module HanyuCoverage
8
+ grid=YAML.load(IO.read(File.dirname(__FILE__)+'/../lib/ting/data/valid_pinyin.yaml'))
9
+ grid.each do |fname, row|
10
+ row.each do |iname, hanyu|
11
+ eval %[
12
+ class Test_#{hanyu} < Test::Unit::TestCase
13
+ include Ting
14
+ def initialize(s)
15
+ super(s)
16
+ @reader = Ting.reader(:hanyu, :no_tones)
17
+ @writer = Ting.writer(:hanyu, :no_tones)
18
+ end
19
+
20
+ def test_parse_#{hanyu}
21
+ assert_equal('#{hanyu}', @writer.unparse(Syllable.new(Initial::#{iname}, Final::#{fname}, Tones::NEUTRAL_TONE)), 'Wrong hanyu for Initial::#{iname}+Final::#{fname}, expected `#{hanyu}` ')
22
+ end
23
+
24
+ def test_unparse_#{hanyu}
25
+ ts=*@reader.parse('#{hanyu}')
26
+ assert_not_nil(ts, 'Reader<:hanyu, :no_tone>#parse("#{hanyu}") returned nil')
27
+ assert_equal(Initial::#{iname}, ts.initial, 'Wrong initial for `#{hanyu}`, expected Initial::#{iname}')
28
+ assert_equal(Final::#{fname}, ts.final, 'Wrong final for `#{hanyu}`, expected Final::#{fname}')
29
+ end
30
+ end
31
+ ]
32
+ end
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ting
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Arne Brasseur
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-04 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Pinyin can convert between various systems for phonetically writing Mandarin Chinese. It can also handle various representation of tones, so it can be used to convert pinyin with numbers to pinyin with tones.
22
+ email:
23
+ - arne@arnebrasseur.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - History.txt
31
+ files:
32
+ - History.txt
33
+ - README.rdoc
34
+ - Rakefile
35
+ - TODO
36
+ - examples/cgiform/cgiform.rb
37
+ - examples/cgiform/template.rhtml
38
+ - examples/hello.rb
39
+ - lib/ting.rb
40
+ - lib/ting/conversion.rb
41
+ - lib/ting/conversions.rb
42
+ - lib/ting/conversions/hanyu.rb
43
+ - lib/ting/data/comparison.csv
44
+ - lib/ting/data/final.csv
45
+ - lib/ting/data/initial.csv
46
+ - lib/ting/data/paladiy.txt
47
+ - lib/ting/data/rules.yaml
48
+ - lib/ting/data/valid_pinyin.yaml
49
+ - lib/ting/exception.rb
50
+ - lib/ting/groundwork.rb
51
+ - lib/ting/string.rb
52
+ - lib/ting/support.rb
53
+ - lib/ting/tones.rb
54
+ - lib/ting/tones/accents.rb
55
+ - lib/ting/tones/supernum.rb
56
+ - lib/ting/tones/ipa.rb
57
+ - lib/ting/tones/marks.rb
58
+ - lib/ting/tones/no_tones.rb
59
+ - lib/ting/tones/numbers.rb
60
+ - test/test_comparison.rb
61
+ - test/test_hanyu_coverage.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/arnebrasseur/ting
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --main
69
+ - README.rdoc
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 2
92
+ summary: A conversion library for Chinese transcription methods like Hanyu Pinyin, Bopomofo and Wade-Giles.
93
+ test_files:
94
+ - test/test_hanyu_coverage.rb
95
+ - test/test_comparison.rb