camdict 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 556f016868d71a2d1dde23319a9d59dfa60ba05c
4
- data.tar.gz: cb0090a31d8f56da0d366819f0de47309d9d5dfa
3
+ metadata.gz: 9375049d96a36f304ae7262da7047f6c4d6e0402
4
+ data.tar.gz: a1256a02286a23bbd204bb0cd5de8a5670c5d12b
5
5
  SHA512:
6
- metadata.gz: 3c110ea5cfe31a35bd69952f983669377a577aa1f7960ac7f69dd7d073d25ff6ff2f031b4a9ba9aa7190b169ded33dba3b06df70788bccb17be77fb93cb1196f
7
- data.tar.gz: dda29ecc637f0550bddfd78b23071210649e8c9aa2d58dbc34cf14b764ec0f7e92bc5c917182bd73a4da0e62516c7cdf03dac647c1b30ce5e584ae30fba54604
6
+ metadata.gz: 857e3d9ee01bdf43511371ec3f1b6bf6df45185f4078e2e1e245243307322a85b9e3bda3b2a77523fa3884b14dd27c62541c1d27a02d718b447e750546bdbf02
7
+ data.tar.gz: b69da41647e14adefa47ee049df7b7967354f212479e6b3669d3c4e19e6a8385ae6222bd2df73becb745e3758af6e62df75c1652286f3cde459d5c796964f5d4
@@ -10,10 +10,11 @@ module Camdict
10
10
  # are not included.
11
11
  class Client
12
12
 
13
- # Default dictionary is british. Other possible +dict+ values:
14
- # american-english, business-english, learner-english.
13
+ # Default dictionary is english-chinese-simplified.
14
+ # Other possible +dict+ values:
15
+ # british, american-english, business-english, learner-english.
15
16
  def initialize(dict=nil)
16
- @dictionary = dict || "british"
17
+ @dictionary = dict || "english-chinese-simplified"
17
18
  end
18
19
 
19
20
 
@@ -352,7 +352,24 @@ module Camdict
352
352
  if short[-1] == '-'
353
353
  center = short[1, slen-2]
354
354
  position = full.index(center[0])
355
- # match left
355
+ # match left and right
356
+ if full.index(center[-1])
357
+ left_matched_index = position
358
+ right_matched_index = flen-1 - full.index(center[-1])
359
+ rev_number = center.length - (right_matched_index -
360
+ left_matched_index + 1)
361
+ if left_matched_index && rev_number <= 0
362
+ right_index = mix_spi(basesp, right_matched_index+1..flen-1)
363
+ rev_right_index = revise_index(right_index, rev_number)
364
+ findex = mix_spi(basesp, 0..left_matched_index-1,
365
+ ussp, left_matched_index+1,
366
+ rev_right_index, 0)
367
+ ret = full[0..left_matched_index-1] + center +
368
+ full[right_matched_index+1..flen-1]
369
+ return {baseipa: ret, sindex: findex}
370
+ end
371
+ end
372
+ # match left only
356
373
  if position && (slen - 2 < flen - 1 - position)
357
374
  findex = mix_spi(basesp, 0..position-1, ussp, position-1,
358
375
  basesp, position+slen-2..flen-1)
@@ -360,7 +377,7 @@ module Camdict
360
377
  return {baseipa: ret, sindex: findex}
361
378
  end
362
379
  position = full.index(center[-1])
363
- # match right
380
+ # match right only
364
381
  if position && (position + 1 > slen - 2)
365
382
  findex = mix_spi(basesp, 0..position-slen+2, ussp, position-slen+2,
366
383
  basesp, position+1..flen-1)
@@ -414,6 +431,22 @@ module Camdict
414
431
  end
415
432
  end
416
433
 
434
+ # +superscript_index+ is the superscript index for an IPA
435
+ # +rev_number+ is the number that is used to revise the superscript index
436
+ # after the common part of a us shorten ipa is joined with uk ipa, the
437
+ # remainding part requires to be revised as it becomes longer or shorter.
438
+ # return the revised superscript_index or nil if the passed
439
+ # +superscript_index+ is nil.
440
+ def revise_index(superscript_index, rev_number)
441
+ return nil if superscript_index.nil?
442
+ ret = []
443
+ superscript_index.each_pair { |position, len|
444
+ ret += [position+rev_number, len]
445
+ }
446
+ return nil if ret.empty?
447
+ ret
448
+ end
449
+
417
450
  # Determine whether or not the range is included by the superscript index.
418
451
  # Return the pair of index array when it is included by that. Or return nil.
419
452
  def at_range(spindex, range)
data/test/itest_client.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class ClientiTest < Test::Unit::TestCase
5
+ class ClientiTest < Minitest::Test
6
6
  def test_fetch
7
7
  c = Camdict::Client.new
8
8
  result = c.send :fetch, "pppppp"
@@ -1,13 +1,14 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class DefinitioniTest < Test::Unit::TestCase
5
+ class DefinitioniTest < Minitest::Test
6
6
 
7
7
  def test_part_of_speech
8
8
  data = {'aluminium' => 'noun', 'aluminum' => 'noun',
9
9
  'look at sth' => 'phrasal verb', 'plagiarist' => 'noun',
10
- 'pass water' => 'idiom', 'ruby' => ['noun', 'adjective']}
10
+ 'pass water' => 'idiom', 'ruby' => 'noun'}
11
+ # adjective for ruby exists in British dictionary
11
12
  data.each_pair { |word, exp_result|
12
13
  w = Camdict::Word.new(word)
13
14
  defa = w.definitions
@@ -31,33 +32,33 @@ module Camdict
31
32
  imaginary = {
32
33
  :word => "imaginary",
33
34
  :uk_utf8 => %w(26a 2c8 6d e6 64 292 2e 26a 2e 6e 259 72 2e 69),
34
- :expected => %w(26a 2c8 6d e6 64 292 2e 259 2e 6e 65 72 2e 69),
35
+ :us_utf8 => %w(26a 2c8 6d e6 64 292 2e 259 2e 6e 65 72 2e 69),
35
36
  :uk_inx => [10,1],
36
- :spiexp => nil,
37
+ :us_inx => nil,
37
38
  :which => 0
38
39
  }
39
40
  plagiarism = {
40
41
  :word => "plagiarism",
41
42
  :uk_utf8 => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 26a 2e 7a 259 6d),
42
- :expected => %w(2c8 70 6c 65 26a 2e 64 292 25a 2e 26a 2e 7a 259 6d),
43
+ :us_utf8 => %w(2c8 70 6c 65 26a 2e 64 292 25a 2e 26a 2e 7a 259 6d),
43
44
  :uk_inx => [8,1,14,1],
44
- :spiexp => [13,1],
45
+ :us_inx => [13,1],
45
46
  :which => 0
46
47
  }
47
48
  aluminum = {
48
49
  :word => "aluminum",
49
50
  :uk_utf8 => %w(259 2c8 6c 75 2d0 2e 6d 26a 2e 6e 259 6d),
50
- :expected => %w(259 2c8 6c 75 2d0 2e 6d 26a 2e 6e 259 6d),
51
+ :us_utf8 => %w(259 2c8 6c 75 2d0 2e 6d 26a 2e 6e 259 6d),
51
52
  :uk_inx => nil,
52
- :spiexp => nil,
53
+ :us_inx => nil,
53
54
  :which => 0
54
55
  }
55
56
  sled = {
56
57
  :word => "sled",
57
58
  :uk_utf8 => nil,
58
- :expected => nil,
59
+ :us_utf8 => nil,
59
60
  :uk_inx => nil,
60
- :spiexp => nil,
61
+ :us_inx => nil,
61
62
  :which => 1
62
63
  }
63
64
  data = [imaginary, plagiarism, aluminum, sled]
@@ -71,10 +72,10 @@ module Camdict
71
72
  us = us.unpack('U*').map { |n| n.to_s 16 } if us
72
73
  actk = defo.ipa.k
73
74
  acts = defo.ipa.s
74
- assert_equal d[:uk_utf8], uk
75
- assert_equal d[:expected], us
76
- assert_equal d[:uk_inx], actk
77
- assert_equal d[:spiexp], acts
75
+ assert_equal d[:uk_utf8], uk, "#{d[:word]} uk ipa got a problem"
76
+ assert_equal d[:us_utf8], us, "#{d[:word]} us ipa got a problem"
77
+ assert_equal d[:uk_inx], actk, "#{d[:word]} uk superscript index issue"
78
+ assert_equal d[:us_inx], acts, "#{d[:word]} us superscript index issue"
78
79
  }
79
80
  end
80
81
 
@@ -1,16 +1,17 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class ExplanationiTest < Test::Unit::TestCase
5
+ class ExplanationiTest < Minitest::Test
6
6
  def test_explanations
7
7
  w = Camdict::Word.new('correct')
8
8
  defa = w.definitions
9
9
  def1 = defa.first #first is adjective
10
10
  e1 = def1.explanations.first
11
- assert_equal "A2", e1.level
12
- assert_equal "B2", defa.last.explanations.first.level
13
- assert_equal "I've got 30 exam papers to correct.",
11
+ #todo: level info is not in english-chinese-simplied dictionary
12
+ #assert_equal "A2", e1.level
13
+ #assert_equal "B2", defa.last.explanations.first.level
14
+ assert_equal "I've got thirty exam papers to correct.",
14
15
  defa.last.explanations.first.examples.last.sentence
15
16
  w = Camdict::Word.new('correctly')
16
17
  defa = w.definitions
@@ -18,7 +19,7 @@ module Camdict
18
19
  e1 = def1.explanations
19
20
  assert_equal "Have I pronounced your name correctly?",
20
21
  e1[2].examples[0].sentence
21
- assert_equal "B1", e1[2].level
22
+ #assert_equal "B1", e1[2].level
22
23
  end
23
24
 
24
25
  def test_phrase_meaning
data/test/test_client.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
@@ -10,11 +10,11 @@ module Camdict
10
10
  </ul>
11
11
  EoHTM
12
12
 
13
- class ClientTest < Test::Unit::TestCase
13
+ class ClientTest < MiniTest::Test
14
14
 
15
15
  def test_new
16
16
  c = Camdict::Client.new
17
- assert c.instance_eval { @dictionary == "british" }
17
+ assert c.instance_eval { @dictionary == "english-chinese-simplified" }
18
18
  c = Camdict::Client.new("american-english")
19
19
  assert c.instance_eval { @dictionary == "american-english" }
20
20
  end
@@ -55,7 +55,7 @@ EoHTM
55
55
  end
56
56
 
57
57
  def test_di_head
58
- # Nokogiri version 1.? and later required for this test case
58
+ # Nokogiri version 1.6.2 and later required for this test case
59
59
  # but previous versions should also work with camdict
60
60
  # you won't see this test case failure once
61
61
  # https://github.com/sparklemotion/nokogiri/pull/1020 is released.
data/test/test_common.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class CommonTest < Test::Unit::TestCase
5
+ class CommonTest < Minitest::Test
6
6
  include Camdict::Common
7
7
 
8
8
  def test_flatten
@@ -39,9 +39,11 @@ module Camdict
39
39
  'the other end of sth']
40
40
  assert_equal expected, str.flatten
41
41
  strs = ["20/20 vision", "public enemy number one/no. 1"]
42
- assert_nothing_raised do
43
- strs.each { |s| s.flatten }
44
- end
42
+ # todo:
43
+ # "20/20 vision".flatten => "20/20 vision" no change expected
44
+ # public enemy number one/no. 1 =>
45
+ # public enemy number one
46
+ # public enemy no. 1
45
47
  str = "the more...the more/less"
46
48
  expected = ['the more...the more', 'the more...the less']
47
49
  assert_equal expected, str.flatten
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
@@ -13,7 +13,7 @@ module Camdict
13
13
  '<span class="runon-info"><span class="posgram"><span class="pos">noun' +
14
14
  '</span></span></span></span>'
15
15
 
16
- class DefinitionTest < Test::Unit::TestCase
16
+ class DefinitionTest < Minitest::Test
17
17
 
18
18
  def test_pos
19
19
  html = '<h2 class="di-title cdo-section-title-hw">favourite</h2>' +
@@ -141,6 +141,14 @@ module Camdict
141
141
  :uk_inx => [10,1],
142
142
  :spiexp => nil
143
143
  }
144
+ plagiarism = {
145
+ :uk_utf8 => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 61 26a 7a),
146
+ :us_utf8 => %w(2d 64 292 259 72 2e 26a 2e 7a 259 6d),
147
+ :expected => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 26a 2e 7a 259 6d),
148
+ :us_inx => [3,1,9,1],
149
+ :uk_inx => [8,1],
150
+ :spiexp => [8,1,14,1]
151
+ }
144
152
  # left hyphen
145
153
  plagiarize = {
146
154
  :uk_utf8 => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 61 26a 7a),
@@ -150,14 +158,6 @@ module Camdict
150
158
  :uk_inx => [8,1],
151
159
  :spiexp => nil
152
160
  }
153
- plagiarism = {
154
- :uk_utf8 => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 61 26a 7a),
155
- :us_utf8 => %w(2d 64 292 259 72 2e 26a 2e 7a 259 6d),
156
- :expected => %w(2c8 70 6c 65 26a 2e 64 292 259 72 2e 26a 2e 7a 259 6d),
157
- :us_inx => [3,1,9,1],
158
- :uk_inx => [8,1],
159
- :spiexp => [8,1,14,1]
160
- }
161
161
  painting = {
162
162
  :uk_utf8 => %w(2c8 70 65 26a 6e 2e 74 26a 14b),
163
163
  :us_utf8 => %w(2d 74 32c 26a 14b),
@@ -1,8 +1,8 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class ExplanationTest < Test::Unit::TestCase
5
+ class ExplanationTest < Minitest::Test
6
6
 
7
7
  def test_get_level
8
8
  html = '<span class="def-info"><span class="epp-xref B1">B1</span>'
@@ -1,8 +1,8 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'camdict'
3
3
 
4
4
  module Camdict
5
- class HTTPClientTest < Test::Unit::TestCase
5
+ class HTTPClientTest < Minitest::Test
6
6
 
7
7
  def test_get_html
8
8
  require 'webrick'
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pan Gaoyong
8
- - 潘高勇
8
+ - "潘高勇"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-04 00:00:00.000000000 Z
12
+ date: 2014-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 1.6.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 1.6.2
28
28
  description: Get definitions, pronunciation and example sentences of a word or phrase
29
29
  from the online Cambridge dictionaries.
30
30
  email: pan.gaoyong@gmail.com
@@ -32,24 +32,24 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - license
36
- - Rakefile
37
35
  - README.md
36
+ - Rakefile
38
37
  - lib/camdict.rb
39
- - lib/camdict/http_client.rb
38
+ - lib/camdict/client.rb
39
+ - lib/camdict/common.rb
40
40
  - lib/camdict/definition.rb
41
41
  - lib/camdict/explanation.rb
42
- - lib/camdict/common.rb
42
+ - lib/camdict/http_client.rb
43
43
  - lib/camdict/word.rb
44
- - lib/camdict/client.rb
45
- - test/itest_explanation.rb
46
- - test/test_common.rb
44
+ - license
47
45
  - test/itest_client.rb
48
46
  - test/itest_definition.rb
49
- - test/test_definition.rb
50
- - test/test_http_client.rb
47
+ - test/itest_explanation.rb
51
48
  - test/test_client.rb
49
+ - test/test_common.rb
50
+ - test/test_definition.rb
52
51
  - test/test_explanation.rb
52
+ - test/test_http_client.rb
53
53
  homepage: https://github.com/pan/camdict
54
54
  licenses:
55
55
  - MIT
@@ -60,18 +60,26 @@ require_paths:
60
60
  - lib
61
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - '>='
63
+ - - ">="
64
64
  - !ruby/object:Gem::Version
65
65
  version: 1.9.3
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.1.11
73
+ rubygems_version: 2.2.2
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: online Cambridge dictionary client
77
- test_files: []
77
+ test_files:
78
+ - test/itest_explanation.rb
79
+ - test/test_common.rb
80
+ - test/itest_client.rb
81
+ - test/itest_definition.rb
82
+ - test/test_definition.rb
83
+ - test/test_http_client.rb
84
+ - test/test_client.rb
85
+ - test/test_explanation.rb