utanone 0.1.2 → 0.1.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
  SHA256:
3
- metadata.gz: 803e7b863bce0ef8254b5e37e6faa866b583ae49facb72ec40d4629eaf88cb57
4
- data.tar.gz: 4a01df2d0ed0d1ac5d24024d5b8fe8e879f694fb1f0e0dcede8302b8ca7e693e
3
+ metadata.gz: 6897c3a5635555cc9ce0bba7bf439d9345979a3d64740a78f71060edf1c0f0d7
4
+ data.tar.gz: 8115d2a37a1170baabd0e6085695b6b7be904f1f71d4891d47c8eba138330b27
5
5
  SHA512:
6
- metadata.gz: ce626ab61cf3c16055ca30047020ac66cfa70ce30e19b118cd691c6a0feb1752e848190ae8a0274288ed701f03e1383de5f5c5ff3d09b1481bce3638f63e45f9
7
- data.tar.gz: 5c87aff2a79445f38f807fa610b5cb376d5503ab48104678b161316733508d55224db90a223af96d7ee9123d0c90d721a851d54997f34a20df575aa754cb72ef
6
+ metadata.gz: 0f3d0ac53578864d8aebc66a864d791722db00ae59b2dcb6833cbfa0e50c311bbe9acd32f9564dd64b0e680ae28cf5c7f3b70456ec02c5b75d3ac07e479af2f3
7
+ data.tar.gz: aae866c6c37f280c5c4b13a6a25f037eeb0e6bf4f6ee09e7e178965cb15fc352331288dce8717af07474fce028ddbf5c95eda6b3253edff4a5623be43e68c9dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [0.1.3] - 2021-10-13
2
+ - add: 読みが取れなかった場合に表層形がひらがな、またはカタカナであれば表層系をカタカナにして返す[#8](https://github.com/yuriko1211/utanone/pull/8)
3
+
1
4
  ## [0.1.2] - 2021-10-09
2
5
  - add: #correct によるよみがな修正の際にひらがなが混在していても修正できるようにした [#7](https://github.com/yuriko1211/utanone/pull/7)
3
6
 
data/lib/utanone/uta.rb CHANGED
@@ -8,6 +8,7 @@ module Utanone
8
8
 
9
9
  EXCLUDING_COUNTING_RUBY_BY_TANKA = /ァ|ィ|ォ|ャ|ュ|ョ/
10
10
  EXCLUDING_COUNTING_LEXICAL_CATEGORIES = %w[記号].freeze
11
+ HIRAGANA_AND_KATAKANA = /\A[ぁ-んァ-ヶー-]+\z/
11
12
 
12
13
  def initialize(str, ref_uta = nil)
13
14
  @original_str = str
@@ -78,14 +79,7 @@ module Utanone
78
79
  next if result.is_eos?
79
80
 
80
81
  morpheme = separated_element(result)
81
-
82
- if ref_uta
83
- # ref_utaとして参照するUtaオブジェクトが渡されている場合は読みを参照するUtaオブジェクトから取得する
84
- ref_morpheme = ref_uta.parsed_morphemes.find { _1[:word] == morpheme[:word] }
85
- morpheme[:ruby] = ref_morpheme[:ruby] if ref_morpheme
86
- end
87
-
88
- raise Utanone::ParseError unless morpheme[:ruby]
82
+ morpheme[:ruby] = correct_ruby(morpheme, ref_uta)
89
83
 
90
84
  array << morpheme
91
85
  end
@@ -121,6 +115,22 @@ module Utanone
121
115
  }
122
116
  end
123
117
 
118
+ def correct_ruby(morpheme, ref_uta)
119
+ if ref_uta
120
+ # ref_utaとして参照するUtaオブジェクトが渡されている場合は読みを参照するUtaオブジェクトから取得する
121
+ ref_morpheme = ref_uta.parsed_morphemes.find { _1[:word] == morpheme[:word] }
122
+ morpheme[:ruby] = ref_morpheme[:ruby] if ref_morpheme
123
+ end
124
+
125
+ if morpheme[:ruby]
126
+ morpheme[:ruby]
127
+ else
128
+ raise Utanone::ParseError unless HIRAGANA_AND_KATAKANA.match?(morpheme[:word])
129
+
130
+ convert_kana(morpheme[:word])
131
+ end
132
+ end
133
+
124
134
  def natto
125
135
  @natto ||= Natto::MeCab.new
126
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Utanone
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utanone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuriko1211
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-09 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mecab