ke2daira 0.1.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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +28 -0
- data/Rakefile +10 -0
- data/lib/ke2daira/version.rb +5 -0
- data/lib/ke2daira.rb +69 -0
- data/sig/ke2daira.rbs +5 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c05a97016dd61db84acc369c2b97805265fb8d3c5b7db226d7058ab7d5708bdf
|
4
|
+
data.tar.gz: fac2bd729b6ef78fa148856e80c4c45d39d0a847696dd657429071a3d6339904
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d061c43d6a5a339af1ac903741a474d05c56ede78407ba083a6cbb4f266a548d4eb02fe11a5ddffc3937e1758020e6e20281ba564ceb81d0d21b5fbc20adc5db
|
7
|
+
data.tar.gz: 0c8d094c9044eee27483ff9e121b646f0878f04de39c1584a312338bd57ad11900ca6b0bd6751ae8c5c2e4eaf248e8fa3f05e54089aa37cd6e5136f5c02cf3d4
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ke2daira (0.1.0)
|
5
|
+
suika (~> 0.3.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
dartsclone (0.3.2)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
json (2.6.3)
|
14
|
+
language_server-protocol (3.17.0.3)
|
15
|
+
parallel (1.22.1)
|
16
|
+
parser (3.2.2.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
rainbow (3.1.1)
|
19
|
+
rake (13.0.6)
|
20
|
+
regexp_parser (2.7.0)
|
21
|
+
rexml (3.2.5)
|
22
|
+
rspec (3.12.0)
|
23
|
+
rspec-core (~> 3.12.0)
|
24
|
+
rspec-expectations (~> 3.12.0)
|
25
|
+
rspec-mocks (~> 3.12.0)
|
26
|
+
rspec-core (3.12.1)
|
27
|
+
rspec-support (~> 3.12.0)
|
28
|
+
rspec-expectations (3.12.2)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-mocks (3.12.5)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-support (3.12.0)
|
35
|
+
rubocop (1.48.1)
|
36
|
+
json (~> 2.3)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.2.0.0)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml (>= 3.2.5, < 4.0)
|
42
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.28.0)
|
46
|
+
parser (>= 3.2.1.0)
|
47
|
+
rubocop-performance (1.16.0)
|
48
|
+
rubocop (>= 1.7.0, < 2.0)
|
49
|
+
rubocop-ast (>= 0.4.0)
|
50
|
+
ruby-progressbar (1.13.0)
|
51
|
+
standard (1.26.0)
|
52
|
+
language_server-protocol (~> 3.17.0.2)
|
53
|
+
rubocop (~> 1.48.1)
|
54
|
+
rubocop-performance (~> 1.16.0)
|
55
|
+
suika (0.3.2)
|
56
|
+
dartsclone (>= 0.2.0)
|
57
|
+
unicode-display_width (2.4.2)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
x86_64-linux
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
ke2daira!
|
64
|
+
rake (~> 13.0)
|
65
|
+
rspec (~> 3.0)
|
66
|
+
standard (~> 1.25)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.3.26
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 otariidae
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# ke2daira.rb
|
2
|
+
|
3
|
+
A Ruby implementation of [ke2daira](https://github.com/ryuichiueda/ke2daira)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```console
|
8
|
+
gem install ke2daira
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require "ke2daira"
|
15
|
+
|
16
|
+
puts Ke2daira.ke2dairanize("松平 健")
|
17
|
+
# "ケツダイラ マン"
|
18
|
+
```
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/otariidae/ke2daira.rb.
|
23
|
+
|
24
|
+
## License
|
25
|
+
|
26
|
+
[MIT License](https://opensource.org/licenses/MIT)
|
27
|
+
|
28
|
+
See LICENSE.txt.
|
data/Rakefile
ADDED
data/lib/ke2daira.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ke2daira/version"
|
4
|
+
require "suika"
|
5
|
+
|
6
|
+
# Ke2daira is a library to ke2dairanize
|
7
|
+
module Ke2daira
|
8
|
+
SEPARATOR = " "
|
9
|
+
private_constant :SEPARATOR
|
10
|
+
|
11
|
+
TAGGER = Suika::Tagger.new
|
12
|
+
private_constant :TAGGER
|
13
|
+
|
14
|
+
SuikaToken = Data.define(:surface_form, :pos, :pos_detail1, :pos_detail2, :pos_detail3, :conjugated_type,
|
15
|
+
:conjugated_form, :basic_form, :reading, :pronunciation)
|
16
|
+
private_constant :SuikaToken
|
17
|
+
|
18
|
+
# Ke2dairanize the givin name
|
19
|
+
# @param fullname [String]
|
20
|
+
# @return [String] ke2dairanized name
|
21
|
+
def self.ke2dairanize(fullname) # rubocop:disable Metrics/AbcSize
|
22
|
+
names = fullname.strip.split(SEPARATOR)
|
23
|
+
yomis = names.map { |name| to_yomi(name) }
|
24
|
+
|
25
|
+
return yomis[0] if yomis.length == 1
|
26
|
+
|
27
|
+
first_word = yomis[0]
|
28
|
+
last_word = yomis[-1]
|
29
|
+
|
30
|
+
# swap first characters of first and last name
|
31
|
+
yomis[0] = last_word[0] + first_word[1..]
|
32
|
+
yomis[-1] = first_word[0] + last_word[1..]
|
33
|
+
yomis.join(SEPARATOR)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
private
|
38
|
+
|
39
|
+
# Tokenize the givin sentence
|
40
|
+
# @param sentence [String] Japanese text to be tokenized
|
41
|
+
# @return [Array<SuikaToken>]
|
42
|
+
def tokenize(sentence)
|
43
|
+
raw_tokens = TAGGER.parse(sentence)
|
44
|
+
raw_tokens.map { |raw_token| raw_token2suikatoken(raw_token) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Convert Suika raw token to SuikaToken
|
48
|
+
# @param raw_token [String] Suika raw token
|
49
|
+
# @return [SuikaToken]
|
50
|
+
def raw_token2suikatoken(raw_token)
|
51
|
+
surface_form, rest_raw_token = raw_token.split("\t")
|
52
|
+
pos, pos_detail1, pos_detail2, pos_detail3, conjugated_type, conjugated_form,
|
53
|
+
basic_form, reading, pronunciation = rest_raw_token.split(",")
|
54
|
+
SuikaToken.new(surface_form, pos, pos_detail1, pos_detail2, pos_detail3, conjugated_type,
|
55
|
+
conjugated_form, basic_form, reading, pronunciation)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Convert the givin word to its reading
|
59
|
+
# @param word [String] a Japanese word
|
60
|
+
# @return [String] reading of the word
|
61
|
+
def to_yomi(word)
|
62
|
+
tokens = tokenize(word)
|
63
|
+
# fallback to the surface form when the reading is missing
|
64
|
+
tokens.map do |token|
|
65
|
+
token.reading || token.surface_form
|
66
|
+
end.join
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/sig/ke2daira.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ke2daira
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- otariidae
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: suika
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.2
|
27
|
+
description: A Ruby implementation of ke2daira
|
28
|
+
email:
|
29
|
+
- otariidae@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- CHANGELOG.md
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/ke2daira.rb
|
42
|
+
- lib/ke2daira/version.rb
|
43
|
+
- sig/ke2daira.rbs
|
44
|
+
homepage: https://github.com/otariidae/ke2daira.rb
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
allowed_push_host: https://rubygems.org
|
49
|
+
homepage_uri: https://github.com/otariidae/ke2daira.rb
|
50
|
+
source_code_uri: https://github.com/otariidae/ke2daira.rb
|
51
|
+
changelog_uri: https://github.com/otariidae/ke2daira.rb/blob/main/CHANGELOG.md
|
52
|
+
rubygems_mfa_required: 'true'
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.4.10
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: ke2daira
|
72
|
+
test_files: []
|