yosina 1.1.3 → 3.0.0

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
  SHA256:
3
- metadata.gz: 506016d955f814d8eb4ee28c64ac510b251f3336681bcf93f116a929dcf2540b
4
- data.tar.gz: 492d9fd8286a536a1dd07858d8c7c789cb30e0b78ba11adf3c76ba43c2035ac2
3
+ metadata.gz: 4d31d3fa007ce64078273418d9372e42e5aae7bacec0682019ce4fab8d2e93f1
4
+ data.tar.gz: c641e3563f3baf54e781660b34f76806d90983d03598133f4efbf1bbeb29531c
5
5
  SHA512:
6
- metadata.gz: 6b7691ee1fd50819b2cc7fb6a48f53bb0524c0817279104f2b6bfe731d794c80a99d2f44b7da733d60c3d28f29c83ba859200987356d807550ba6adc45fbfc9a
7
- data.tar.gz: 100771ea6fa26397a3ba462842f7427b739a2d5f2cb3f580982ef76896adfc532b3ebe8cbc89a760927ffd774f8417a7c5559d5996f2333c06cb49a2a9f5b8ab
6
+ metadata.gz: '05648b23304aa9cf4668826f2b94bb27c29d7d74eb8832d910ce5d1ff237157c6814af181804dd2cc692d0c7322201daa8c38cbc52cb19c5bb9a20115ec5c497'
7
+ data.tar.gz: 64de351469c65778f19759b834ee516af59cdf8dc42a104cbee1b4e16c627704b13ba421eb3513f0b407b7df2146c6f7a66e288d06eec56e3679bfd1bb6057a1
@@ -271,7 +271,11 @@ module Yosina
271
271
 
272
272
  def apply_replace_suspicious_hyphens_to_prolonged_sound_marks(ctx)
273
273
  if @replace_suspicious_hyphens_to_prolonged_sound_marks
274
- ctx.insert_middle([:prolonged_sound_marks, { replace_prolonged_marks_following_alnums: true }])
274
+ ctx.insert_middle([:prolonged_sound_marks, {
275
+ replace_prolonged_marks_following_alnums: true,
276
+ replace_prolonged_marks_between_non_kanas:
277
+ @replace_suspicious_hyphens_to_prolonged_sound_marks == 'aggressive'
278
+ }])
275
279
  else
276
280
  ctx
277
281
  end
@@ -416,7 +416,6 @@ module Yosina
416
416
  "\u{1f1fe}" => { rendering: 'Y', type: 's', emoji: false },
417
417
  "\u{1f1ff}" => { rendering: 'Z', type: 's', emoji: false },
418
418
  "\u{1f6be}" => { rendering: 'WC', type: 's', emoji: true },
419
- "\u{1f200}" => { rendering: "\u{307b}\u{304b}", type: 's', emoji: false },
420
419
  "\u{1f201}" => { rendering: "\u{30b3}\u{30b3}", type: 's', emoji: true },
421
420
  "\u{1f202}" => { rendering: "\u{30b5}", type: 's', emoji: false },
422
421
  "\u{1f210}" => { rendering: "\u{624b}", type: 's', emoji: false },
@@ -13,7 +13,7 @@ module Yosina
13
13
 
14
14
  # Generated mapping data
15
15
  HYPHENS_MAPPINGS = {
16
- '-' => HyphensRecord.new(ascii: '-', jisx0201: '-', jisx0208_90: "\u{2212}", jisx0208_90_windows: "\u{2212}"),
16
+ '-' => HyphensRecord.new(ascii: '-', jisx0201: '-', jisx0208_90: "\u{2212}", jisx0208_90_windows: "\u{ff0d}"),
17
17
  '|' => HyphensRecord.new(ascii: '|', jisx0201: '|', jisx0208_90: "\u{ff5c}", jisx0208_90_windows: "\u{ff5c}"),
18
18
  '~' => HyphensRecord.new(ascii: '~', jisx0201: '~', jisx0208_90: "\u{301c}", jisx0208_90_windows: "\u{ff5e}"),
19
19
  "\u{a2}" => HyphensRecord.new(jisx0208_90: "\u{a2}", jisx0208_90_windows: "\u{ffe0}"),
@@ -71,6 +71,12 @@ module Yosina
71
71
  [0x30fc, 0xff70].include?(char_code)
72
72
  end
73
73
 
74
+ def kana?(char_code)
75
+ hiragana?(char_code) || katakana?(char_code) ||
76
+ hatsuon?(char_code) || sokuon?(char_code) ||
77
+ prolonged_sound_mark?(char_code)
78
+ end
79
+
74
80
  def prolongable?(char_code)
75
81
  prolonged_sound_mark?(char_code) || hiragana?(char_code) || katakana?(char_code)
76
82
  end
@@ -83,7 +89,8 @@ module Yosina
83
89
  # Transliterator for prolonged sound marks
84
90
  class Transliterator < Yosina::BaseTransliterator
85
91
  attr_reader :skip_already_transliterated_chars, :allow_prolonged_hatsuon,
86
- :allow_prolonged_sokuon, :replace_prolonged_marks_following_alnums
92
+ :allow_prolonged_sokuon, :replace_prolonged_marks_following_alnums,
93
+ :replace_prolonged_marks_between_non_kanas
87
94
 
88
95
  # Initialize the transliterator with options
89
96
  #
@@ -96,12 +103,15 @@ module Yosina
96
103
  # Default: false.
97
104
  # @option options [Boolean] :replace_prolonged_marks_following_alnums Replace prolonged marks after alphanum
98
105
  # with hyphens. Default: false.
106
+ # @option options [Boolean] :replace_prolonged_marks_between_non_kanas Replace prolonged marks between
107
+ # non-kana characters with hyphens. Default: false.
99
108
  def initialize(options = {})
100
109
  super()
101
110
  @skip_already_transliterated_chars = options.fetch(:skip_already_transliterated_chars, false)
102
111
  @allow_prolonged_hatsuon = options.fetch(:allow_prolonged_hatsuon, false)
103
112
  @allow_prolonged_sokuon = options.fetch(:allow_prolonged_sokuon, false)
104
113
  @replace_prolonged_marks_following_alnums = options.fetch(:replace_prolonged_marks_following_alnums, false)
114
+ @replace_prolonged_marks_between_non_kanas = options.fetch(:replace_prolonged_marks_between_non_kanas, false)
105
115
  end
106
116
 
107
117
  # Convert hyphen-like characters to appropriate prolonged sound marks
@@ -125,13 +135,28 @@ module Yosina
125
135
  prev_non_prolonged_char = last_non_prolonged_char
126
136
  last_non_prolonged_char = char
127
137
 
128
- if (prev_non_prolonged_char.nil? || alphanumeric?(prev_non_prolonged_char.c.ord)) && (
138
+ prev_type = prev_non_prolonged_char&.c&.ord
139
+ following_type = last_non_prolonged_char.c.empty? ? nil : last_non_prolonged_char.c.ord
140
+
141
+ replace_by_alnum = @replace_prolonged_marks_following_alnums &&
142
+ (prev_non_prolonged_char.nil? || alphanumeric?(prev_type))
143
+ replace_by_non_kana = @replace_prolonged_marks_between_non_kanas &&
144
+ (prev_non_prolonged_char.nil? || !kana?(prev_type)) &&
145
+ (following_type.nil? || !kana?(following_type))
146
+
147
+ if (replace_by_alnum || replace_by_non_kana) && (
129
148
  !@skip_already_transliterated_chars || !processed_char_in_lookahead
130
149
  )
131
- halfwidth = halfwidth?(
132
- prev_non_prolonged_char.nil? ? last_non_prolonged_char.c.ord : prev_non_prolonged_char.c.ord
133
- )
134
- replacement = halfwidth ? "\u002d" : "\uff0d"
150
+ if replace_by_non_kana
151
+ prev_half = prev_non_prolonged_char.nil? || halfwidth?(prev_type)
152
+ next_half = !following_type.nil? && halfwidth?(following_type)
153
+ replacement = !prev_half && !next_half ? "\uff0d" : "\u002d"
154
+ else
155
+ halfwidth = halfwidth?(
156
+ prev_non_prolonged_char.nil? ? following_type : prev_type
157
+ )
158
+ replacement = halfwidth ? "\u002d" : "\uff0d"
159
+ end
135
160
  lookahead_buf.each do |buffered_char|
136
161
  y << Char.new(c: replacement, offset: offset, source: buffered_char)
137
162
  offset += replacement.length
@@ -158,7 +183,8 @@ module Yosina
158
183
  y << Char.new(c: replacement, offset: offset, source: char)
159
184
  offset += replacement.length
160
185
  next
161
- elsif @replace_prolonged_marks_following_alnums && alphanumeric?(last_non_prolonged_char.c.ord)
186
+ elsif (@replace_prolonged_marks_following_alnums && alphanumeric?(last_non_prolonged_char.c.ord)) ||
187
+ (@replace_prolonged_marks_between_non_kanas && !kana?(last_non_prolonged_char.c.ord))
162
188
  lookahead_buf << char
163
189
  next
164
190
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yosina
4
- VERSION = '1.1.3'
4
+ VERSION = '3.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yosina
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moriyoshi Koizumi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-13 00:00:00.000000000 Z
11
+ date: 2026-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -143,7 +143,7 @@ metadata:
143
143
  homepage_uri: https://github.com/yosina-lib/yosina
144
144
  source_code_uri: https://github.com/yosina-lib/yosina
145
145
  changelog_uri: https://github.com/yosina-lib/yosina/releases
146
- post_install_message:
146
+ post_install_message:
147
147
  rdoc_options: []
148
148
  require_paths:
149
149
  - lib
@@ -158,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.0.3.1
162
- signing_key:
161
+ rubygems_version: 3.5.11
162
+ signing_key:
163
163
  specification_version: 4
164
164
  summary: Japanese text transliteration library
165
165
  test_files: []