jkf 0.5.1 → 0.5.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 +4 -4
- data/.envrc +1 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +3 -12
- data/LICENSE.txt +1 -0
- data/README.en.md +26 -21
- data/README.md +34 -21
- data/bench.rb +1 -1
- data/jkf.gemspec +12 -8
- data/lib/jkf/converter/base.rb +1 -1
- data/lib/jkf/converter/csa.rb +4 -7
- data/lib/jkf/converter/ki2.rb +5 -5
- data/lib/jkf/converter/kif.rb +9 -14
- data/lib/jkf/converter/kifuable.rb +6 -6
- data/lib/jkf/parser/base.rb +2 -2
- data/lib/jkf/parser/csa.rb +282 -287
- data/lib/jkf/parser/ki2.rb +3 -2
- data/lib/jkf/parser/kif.rb +3 -6
- data/lib/jkf/parser/kifuable.rb +2 -2
- data/lib/jkf/version.rb +1 -1
- data/lib/jkf.rb +1 -0
- data/manifest.scm +4 -130
- data/po/all.pot +57 -47
- data/po/en.po +78 -76
- data/po/en.rdoc.po +580 -0
- metadata +32 -18
- data/.github/workflows/ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rubocop.yml +0 -65
- data/.rubocop_todo.yml +0 -7
- data/Guardfile +0 -27
- data/bin/console +0 -15
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa24be83e28547743c1bc4c5c12e3b336fe4f448d8cd8f729620c9878a1de42
|
4
|
+
data.tar.gz: bc7e2b1eba4f7f9c970d266cba6f4887444dde261169a0e8d52eb02642802e0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86861a9621a3dc7fa5e7c61fbeeb53c5791bc28fc37b53f3b7bbea44e4f85b0489d4c7b9da2e669432861ac007cf25803dc99c14cbd9b667969df43ef4871a97
|
7
|
+
data.tar.gz: 5d2ea1626f6a644760b2ae533fdd5497bd3c5c6e14f73e1001146315008ffd6e5424f5acfe9b0654f8793743baf20a96ca228b8cb42f4b16b8c98b5998868627
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
use guix
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## 0.5.3 - 2025-07-21
|
11
|
+
|
12
|
+
Update project links.
|
13
|
+
|
14
|
+
## 0.5.2 - 2024-10-26
|
15
|
+
|
16
|
+
This is a maintenance release.
|
17
|
+
|
18
|
+
### Others
|
19
|
+
|
20
|
+
* Lint with RuboCop performance plugin
|
21
|
+
* Update documentation
|
22
|
+
* Update gem dependencies; RuboCop and RuboCop RSpec.
|
23
|
+
|
10
24
|
## [0.5.1] - 2023-06-24
|
11
25
|
|
12
26
|
### Changed
|
data/Gemfile
CHANGED
@@ -2,20 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rake'
|
6
|
-
|
7
5
|
group :development do
|
8
|
-
gem '
|
9
|
-
gem 'yard', require: false
|
10
|
-
|
11
|
-
gem 'guard-rubocop', require: false
|
12
|
-
gem 'rubocop', '~> 1.32.0', require: false
|
13
|
-
gem 'rubocop-rake', '~> 0.6.0', require: false
|
14
|
-
gem 'rubocop-rspec', '~> 2.12', require: false
|
6
|
+
gem 'yard'
|
15
7
|
end
|
16
8
|
|
17
9
|
group :test do
|
18
|
-
gem '
|
19
|
-
gem '
|
20
|
-
gem 'simplecov', require: false
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
gem 'simplecov'
|
21
12
|
end
|
data/LICENSE.txt
CHANGED
data/README.en.md
CHANGED
@@ -1,37 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# jkf gem
|
2
|
+
|
2
3
|
[](https://badge.fury.io/rb/jkf)
|
4
5
|
[](https://travis-ci.org/iyuuya/jkf)
|
6
7
|
[](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
|
7
8
|
|
8
|
-
jkf is a Ruby port of [json-kifu-format][jkf].
|
9
|
-
It supports both of the conversion from KIF
|
10
|
-
|
9
|
+
The jkf gem is a Ruby port of [json-kifu-format (JKF)][jkf].
|
10
|
+
It supports both of the conversion from KIF (see [棋譜ファイル KIF 形式][kakinoki]),
|
11
|
+
KI2, or CSA (see [CSA標準棋譜ファイル形式][csa]) to JKF, and the one from JKF to KIF,
|
12
|
+
KI2, or CSA.
|
11
13
|
|
12
|
-
[
|
14
|
+
[csa]: http://www2.computer-shogi.org/protocol/record_v22.html
|
15
|
+
[jkf]:
|
16
|
+
https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
|
17
|
+
[kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
|
13
18
|
|
14
19
|
## Installation
|
15
20
|
|
16
|
-
If you install this gem to your application (with Bundler), add
|
17
|
-
Gemfile
|
21
|
+
If you install this gem to your application (with [Bundler][bundler]), add
|
22
|
+
this to `Gemfile`.
|
23
|
+
|
24
|
+
[bundler]: https://bundler.io/
|
18
25
|
|
19
26
|
```ruby
|
20
27
|
gem 'jkf'
|
21
28
|
```
|
22
29
|
|
23
|
-
Then run bundle to install this gem.
|
24
|
-
|
25
|
-
$ bundle
|
30
|
+
Then run `bundle` to install this gem.
|
26
31
|
|
27
|
-
Or directly install with gem install command.
|
28
|
-
|
29
|
-
$ gem install jkf
|
32
|
+
Or directly install with `gem install` command.
|
30
33
|
|
31
34
|
## Usage
|
32
35
|
|
33
|
-
This gem has the Parser and the Converter for
|
34
|
-
CSA.
|
36
|
+
This gem has the parser {Jkf::Parser} and the converter {Jkf::Converter} for
|
37
|
+
each formats: KIF, KI2, and CSA.
|
35
38
|
|
36
39
|
```ruby
|
37
40
|
kif_parser = Jkf::Parser::Kif.new
|
@@ -45,8 +48,8 @@ ki2_converter = Jkf::Converter::Ki2.new
|
|
45
48
|
csa_converter = Jkf::Converter::Csa.new
|
46
49
|
```
|
47
50
|
|
48
|
-
|
49
|
-
|
51
|
+
{Jkf::Parser::Base#parse} to convert into JKF.
|
52
|
+
{Jkf::Converter::Base#convert} to convert into each formats from JKF.
|
50
53
|
|
51
54
|
```ruby
|
52
55
|
jkf = kif_parser.parse(kif_str) #=> Hash
|
@@ -62,13 +65,15 @@ csa = csa_converter.convert(jkf) #=> String
|
|
62
65
|
|
63
66
|
## Contributing
|
64
67
|
|
65
|
-
Feel free to report bugs or send pull requests at
|
66
|
-
[
|
68
|
+
Feel free to report bugs or send pull requests at [the GitHub
|
69
|
+
repository][repo].
|
70
|
+
|
71
|
+
[repo]: https://github.com/iyuuya/jkf
|
67
72
|
|
68
73
|
If you work on Guix, run tests by `guix shell`.
|
69
74
|
|
70
75
|
## License
|
71
76
|
|
72
|
-
This gem is
|
73
|
-
License](http://opensource.org/licenses/MIT).
|
77
|
+
This gem is provided under the [MIT License][mit].
|
74
78
|
|
79
|
+
[mit]: http://opensource.org/licenses/MIT
|
data/README.md
CHANGED
@@ -1,30 +1,29 @@
|
|
1
|
-
#
|
2
|
-
[](https://badge.fury.io/rb/jkf) [](https://travis-ci.org/iyuuya/jkf) [](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
|
1
|
+
# jkf gem
|
3
2
|
|
4
|
-
jkfは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
|
5
|
-
KIF
|
3
|
+
jkf gemは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
|
4
|
+
柿木形式([棋譜ファイル KIF 形式][kakinoki]、KI2)、[CSA標準棋譜ファイル形式][csa]の構文解析とJKFへの変換、JKFからKIF, KI2, CSAへの変換に対応しています。
|
6
5
|
|
6
|
+
[csa]: http://www2.computer-shogi.org/protocol/record_v22.html
|
7
7
|
[jkf]: https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
|
8
|
+
[kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
|
8
9
|
|
9
|
-
##
|
10
|
+
## インストール
|
10
11
|
|
11
|
-
|
12
|
+
アプリケーションにインストールする場合([Bundler][bundler]を使用する場合)、`Gemfile`に以下のように記述してください。
|
13
|
+
|
14
|
+
[bundler]: https://bundler.io/
|
12
15
|
|
13
16
|
```ruby
|
14
17
|
gem 'jkf'
|
15
18
|
```
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
$ bundle
|
20
|
+
さらに`bundle`コマンドを実行することでインストールできます。
|
20
21
|
|
21
|
-
|
22
|
+
または、`gem install`コマンドを使って直接インストールもできます。
|
22
23
|
|
23
|
-
|
24
|
+
## 使い方
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
KIF, KI2, CSAそれぞれParserとConverterが用意してあります。
|
26
|
+
KIF, KI2, CSAそれぞれ構文解析器 {Jkf::Parser} と変換器 {Jkf::Converter} が用意してあります。
|
28
27
|
|
29
28
|
```ruby
|
30
29
|
kif_parser = Jkf::Parser::Kif.new
|
@@ -38,7 +37,7 @@ ki2_converter = Jkf::Converter::Ki2.new
|
|
38
37
|
csa_converter = Jkf::Converter::Csa.new
|
39
38
|
```
|
40
39
|
|
41
|
-
|
40
|
+
{Jkf::Parser::Base#parse} でJKFへの変換、 {Jkf::Converter::Base#convert} でJKFから各形式へ変換できます。
|
42
41
|
|
43
42
|
```ruby
|
44
43
|
jkf = kif_parser.parse(kif_str) #=> Hash
|
@@ -52,15 +51,29 @@ ki2 = ki2_converter.convert(jkf) #=> String
|
|
52
51
|
csa = csa_converter.convert(jkf) #=> String
|
53
52
|
```
|
54
53
|
|
55
|
-
##
|
54
|
+
## 貢献
|
55
|
+
|
56
|
+
バグレポートやプルリクエストは[リポジトリ][repo]でよろしくお願いします。
|
56
57
|
|
57
|
-
|
58
|
-
https://github.com/iyuuya/jkf.
|
58
|
+
[repo]: https://sourceforge.net/p/ruby-jkf/code/
|
59
59
|
|
60
60
|
Guixで開発されている場合は`guix shell`で`rake test`によるテスト実行ができます。
|
61
61
|
|
62
|
-
|
62
|
+
翻訳はドキュメントとAPIの2種類があります。
|
63
|
+
APIについてはRDocの国際化の機能を使います。
|
64
|
+
POTファイルの生成には`rdoc --format pot`とします。
|
65
|
+
これにより`doc/rdoc.pot`が生成されます。
|
66
|
+
このPOTファイルから各言語のPOファイルを初期化できます。
|
67
|
+
例えば`msginit -i doc/rdoc.pot -o po/en.rdoc.po --locale en_US.UTF-8`です。
|
68
|
+
|
69
|
+
## 謝辞
|
70
|
+
|
71
|
+
このプロジェクトは[GitHubのiyuuya/jkf](https://github.com/iyuuya/jkf)を元にしています。
|
72
|
+
そこから[GitHubのgemmaro/jkf](https://github.com/gemmaro/jkf)にフォークされました。
|
73
|
+
現在の開発は[SourceForgeのjkf](https://sourceforge.net/projects/ruby-jkf/)に移っています。
|
74
|
+
|
75
|
+
## 利用許諾
|
63
76
|
|
64
|
-
ライセンスはMITです。
|
65
|
-
[MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
ライセンスは[MIT License][mit]です。
|
66
78
|
|
79
|
+
[mit]: http://opensource.org/licenses/MIT
|
data/bench.rb
CHANGED
data/jkf.gemspec
CHANGED
@@ -5,19 +5,23 @@ require 'jkf/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'jkf'
|
7
7
|
spec.version = Jkf::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = ['i.yuuya@gmail.com']
|
8
|
+
spec.authors = %w[iyuuya gemmaro]
|
9
|
+
spec.email = ['i.yuuya@gmail.com', 'gemmaro.dev@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = '
|
12
|
-
spec.description = '
|
13
|
-
spec.homepage = 'https://
|
11
|
+
spec.summary = 'Shogi formats parser and converter'
|
12
|
+
spec.description = 'The jkf gem provides parsers and converters (generaters) for several shogi formats, including json-kifu-format, KIF, KI2, and CSA.'
|
13
|
+
spec.homepage = 'https://sourceforge.net/projects/ruby-jkf/'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.required_ruby_version = '>= 3.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir = 'exe'
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
19
|
spec.require_paths = ['lib']
|
22
|
-
|
20
|
+
|
21
|
+
spec.metadata = {
|
22
|
+
'rubygems_mfa_required' => 'true',
|
23
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/jkf'
|
24
|
+
}
|
25
|
+
|
26
|
+
spec.add_development_dependency "rake"
|
23
27
|
end
|
data/lib/jkf/converter/base.rb
CHANGED
data/lib/jkf/converter/csa.rb
CHANGED
@@ -16,12 +16,8 @@ module Jkf
|
|
16
16
|
|
17
17
|
def convert_information(header)
|
18
18
|
result = ''
|
19
|
-
if header['先手'] || header['下手']
|
20
|
-
|
21
|
-
end
|
22
|
-
if header['後手'] || header['上手']
|
23
|
-
result += 'N-' + (header.delete('後手') || header.delete('上手') || '') + "\n"
|
24
|
-
end
|
19
|
+
result += 'N+' + (header.delete('先手') || header.delete('下手') || '') + "\n" if header['先手'] || header['下手']
|
20
|
+
result += 'N-' + (header.delete('後手') || header.delete('上手') || '') + "\n" if header['後手'] || header['上手']
|
25
21
|
header.each { |(k, v)| result += "$#{csa_header_key(k)}:#{v}\n" }
|
26
22
|
result
|
27
23
|
end
|
@@ -60,6 +56,7 @@ module Jkf
|
|
60
56
|
before_pos = nil
|
61
57
|
moves.each do |move|
|
62
58
|
next if move == {}
|
59
|
+
|
63
60
|
result += convert_move(move['move'], before_pos) if move['move']
|
64
61
|
result += convert_special(move['special'], move['color']) if move['special']
|
65
62
|
if move['time']
|
@@ -144,7 +141,7 @@ module Jkf
|
|
144
141
|
end
|
145
142
|
|
146
143
|
def pos2str(pos)
|
147
|
-
'%d%d'
|
144
|
+
format('%d%d', pos['x'], pos['y'])
|
148
145
|
end
|
149
146
|
|
150
147
|
def version
|
data/lib/jkf/converter/ki2.rb
CHANGED
@@ -24,20 +24,20 @@ module Jkf
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def convert_header(header)
|
27
|
-
header.
|
27
|
+
header.filter_map do |(key, value)|
|
28
28
|
result = add_header(key, value)
|
29
|
-
if
|
29
|
+
if /\A[先後上下]手\Z/.match?(key)
|
30
30
|
nil
|
31
31
|
else
|
32
32
|
result
|
33
33
|
end
|
34
|
-
end.
|
34
|
+
end.join
|
35
35
|
end
|
36
36
|
|
37
37
|
def add_header(key, value)
|
38
38
|
result = "#{key}:#{value}\n"
|
39
|
-
if
|
40
|
-
if
|
39
|
+
if /\A[先後上下]手\Z/.match?(key)
|
40
|
+
if /[先下]/.match?(key)
|
41
41
|
@header2.unshift result
|
42
42
|
else
|
43
43
|
@header2 << result
|
data/lib/jkf/converter/kif.rb
CHANGED
@@ -25,10 +25,10 @@ module Jkf
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def convert_header(header, jkf)
|
28
|
-
header.
|
28
|
+
header.filter_map do |(key, value)|
|
29
29
|
result = "#{key}:#{value}\n"
|
30
|
-
if
|
31
|
-
if
|
30
|
+
if /\A[先後上下]手\Z/.match?(key)
|
31
|
+
if /[先下]/.match?(key)
|
32
32
|
@header2.unshift result
|
33
33
|
else
|
34
34
|
@header2 << result
|
@@ -39,7 +39,7 @@ module Jkf
|
|
39
39
|
else
|
40
40
|
result
|
41
41
|
end
|
42
|
-
end.
|
42
|
+
end.join
|
43
43
|
end
|
44
44
|
|
45
45
|
def convert_moves(moves, idx = 0)
|
@@ -57,7 +57,7 @@ module Jkf
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def convert_move_line(move, index)
|
60
|
-
result = '%4d '
|
60
|
+
result = format('%4d ', index)
|
61
61
|
result += convert_move(move['move'])
|
62
62
|
result += convert_time(move['time']) if move['time']
|
63
63
|
result += '+' if move['forks']
|
@@ -65,7 +65,7 @@ module Jkf
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def convert_special_line(move, index)
|
68
|
-
result = '%4d '
|
68
|
+
result = format('%4d ', index)
|
69
69
|
result += ljust(special2kan(move['special']), 13)
|
70
70
|
result += convert_time(move['time']) if move['time']
|
71
71
|
result += '+' if move['forks']
|
@@ -85,13 +85,8 @@ module Jkf
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def convert_time(time)
|
88
|
-
'(%2d:%02d/%02d:%02d:%02d)'
|
89
|
-
|
90
|
-
time['now']['s'],
|
91
|
-
time['total']['h'],
|
92
|
-
time['total']['m'],
|
93
|
-
time['total']['s']
|
94
|
-
]
|
88
|
+
format('(%2d:%02d/%02d:%02d:%02d)', time['now']['m'], time['now']['s'], time['total']['h'], time['total']['m'],
|
89
|
+
time['total']['s'])
|
95
90
|
end
|
96
91
|
|
97
92
|
def special2kan(special)
|
@@ -119,7 +114,7 @@ module Jkf
|
|
119
114
|
end
|
120
115
|
|
121
116
|
def pos2str(pos)
|
122
|
-
'%d%d'
|
117
|
+
format('%d%d', pos['x'], pos['y'])
|
123
118
|
end
|
124
119
|
end
|
125
120
|
end
|
@@ -52,7 +52,7 @@ module Jkf
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def convert_motigoma(pieces)
|
55
|
-
pieces.to_a.reverse.
|
55
|
+
pieces.to_a.reverse.filter_map do |(piece, num)|
|
56
56
|
if num > 0
|
57
57
|
str = csa2kind(piece)
|
58
58
|
if num > 1
|
@@ -62,7 +62,7 @@ module Jkf
|
|
62
62
|
end
|
63
63
|
str
|
64
64
|
end
|
65
|
-
end.
|
65
|
+
end.join(' ') + " \n"
|
66
66
|
end
|
67
67
|
|
68
68
|
def convert_board_piece(piece)
|
@@ -81,7 +81,7 @@ module Jkf
|
|
81
81
|
def convert_special(special, index)
|
82
82
|
result = "まで#{index + 1}手"
|
83
83
|
|
84
|
-
if special == 'TORYO' || special
|
84
|
+
if special == 'TORYO' || special.include?('ILLEGAL')
|
85
85
|
turn = @players[index % 2]
|
86
86
|
result += "で#{turn}手の"
|
87
87
|
result += { 'TORYO' => '勝ち',
|
@@ -115,7 +115,7 @@ module Jkf
|
|
115
115
|
|
116
116
|
def convert_forks(forks, index)
|
117
117
|
result = "\n"
|
118
|
-
result = "変化:%4d手\n"
|
118
|
+
result = format("変化:%4d手\n", index) # ki2の場合\nなし
|
119
119
|
forks.each do |moves|
|
120
120
|
result += convert_moves(moves, index)
|
121
121
|
end
|
@@ -131,9 +131,9 @@ module Jkf
|
|
131
131
|
players_flag = :sengo
|
132
132
|
jkf['header']&.keys&.detect { |key| key =~ /[上下]手/ } && players_flag = :uwasimo
|
133
133
|
@players = if players_flag == :uwasimo
|
134
|
-
[
|
134
|
+
%w[下 上]
|
135
135
|
else
|
136
|
-
[
|
136
|
+
%w[先 後]
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
data/lib/jkf/parser/base.rb
CHANGED
@@ -30,7 +30,7 @@ module Jkf
|
|
30
30
|
@result != :failed
|
31
31
|
end
|
32
32
|
|
33
|
-
def failed
|
33
|
+
def failed? = !success?
|
34
34
|
|
35
35
|
def match_regexp(reg)
|
36
36
|
matched = @scanner.scan(reg)
|
@@ -92,7 +92,7 @@ module Jkf
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def record_failure(
|
95
|
+
def record_failure(_expected)
|
96
96
|
return if @scanner.pos < @max_fail_pos
|
97
97
|
|
98
98
|
return unless @scanner.pos > @max_fail_pos
|