igo 0.1.0 → 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: '0019e83e3f2f8e1d64f1b616b77426958d6cb5098ac621d36e3f5c7b7a26f038'
4
- data.tar.gz: c82aec2104524b815e1213a337c2b9e9a65bb533d8ce82a9de81bebb308a8aca
3
+ metadata.gz: cd6b6d4214bdb3825759167d9d17797e0b988b72665cde7ecbd9162d9723deff
4
+ data.tar.gz: a1e18a3d1e598b553a2da2e47a1955312d08fb0dc6a56bf4bea35d9eb26defc9
5
5
  SHA512:
6
- metadata.gz: 0ced2f8c27ca4ead3deb08275b1bc8023119cd54ab320c4cb596a487b4361ce298ebf84ce889263f295c37c2fcef0010bd4f2c95965d48e3bf947f60d31d0290
7
- data.tar.gz: 57acd881bfb264a1d570511414a9d0b4dea423f751f198382211ce139011403f9460c0c4da2f5025357ac34b1306bdf7d47b5c364046b8d326d40685c526924c
6
+ metadata.gz: 4855cc233e4594677d671eb8cfea48ff20fddd51b22a7abda157229652761dc9af4a55b66ea71649a27ade2c9afba3435085d3d78d9ce883c1022030e09c7602
7
+ data.tar.gz: 2ba7a4d3ea3749d69aba62f1edbcf057a68a5e39c1db6866d3b178f3ff1676be6f9a494ad7a924b735d8de85dab08391ca208841a452946a6cdca8adbe9679aa
data/README.md CHANGED
@@ -1,39 +1,85 @@
1
- # Igo
1
+ # 言語 :: Igo
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Support `zh-CN`, `ja-JP`
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/igo`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ install
6
+ ```cmd
7
+ gem install igo
8
+ ```
6
9
 
7
- ## Installation
10
+ ## 使い方 :: Usage / Ja
8
11
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ ```ruby
13
+ require 'igo'
14
+ require 'igo/ja'
10
15
 
11
- Install the gem and add to the application's Gemfile by executing:
16
+ j = Igo::Ja
12
17
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+ cutted = j.cut "あー、合成は結合法則を満たすんでしたね"
19
+ #=> ["では", "、", "圏論", "の", "話", "を", "しましょ", "う", "か", "N", "この", "前", "は", "、圏", "について", "紹介 しました"]
14
20
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ cutted = j.cut "あー、合成は結合法則を満たすんでしたね", s: true
22
+ #=> "では 、 圏論 の 話 を しましょ う か N この 前 は 、圏 について 紹介しました"
16
23
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
24
+ ```
18
25
 
19
- ## Usage
26
+ 下ノ関数は、暫く未完成です、ごめんね:
20
27
 
21
- TODO: Write usage instructions here
28
+ `j.romaji`, `j.kana`, `j.tag`。
22
29
 
23
- ## Development
30
+ ## 用法 :: Usage / Zh
24
31
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+ Lack __Trad-Zh__ :: 暂不支持「正體中文」
26
33
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+ ```ruby
35
+ require 'igo'
36
+ require 'igo/zh'
37
+ z = Igo::Zh
38
+ ```
28
39
 
29
- ## Contributing
40
+ ### Pinyin :: 拼音
30
41
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/igo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/igo/blob/master/CODE_OF_CONDUCT.md).
42
+ ```ruby
43
+ z.pinyin "全世界的无产者,联合起来!"
44
+ #=> ["quan2", "shi4", "jie4", "de", "wu2", "chan3", "zhe3", "lian2", "he2", "qi3", "lai2"]
45
+ z.pinyin "全世界的无产者,联合起来!", s: 1
46
+ #=> "quan2 shi4 jie4 de wu2 chan3 zhe3 lian2 he2 qi3 lai2"
47
+ ```
32
48
 
33
- ## License
49
+ ### seperate word :: 分词
34
50
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+ ```ruby
52
+ z.cut "全世界的无产者,联合起来!"
53
+ #=> ["全世界", "的", "無產階級", ",", "聯合", "起來", "!"]
54
+ z.cut "全世界的无产者,联合起来!", s: true
55
+ #=> "全世界 的 无产者 ! 联合 起来 !"
56
+ ```
57
+ ### Taging word :: 标注词类
36
58
 
37
- ## Code of Conduct
59
+ 后续可能添加 `by` 关键词指定函数。
38
60
 
39
- Everyone interacting in the Igo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/igo/blob/master/CODE_OF_CONDUCT.md).
61
+ ```ruby
62
+ z.tag "全世界的无产者,联合起来!"
63
+ #=> [["全世界", "n"], ["的", "uj"], ["无产者", "n"], ["!", "x"], ["联合", "v"], ["起来", "v"], ["!", "x"]]
64
+ z.tag "全世界的无产者,联合起来!", s: true
65
+ #=> "全世界_n 的_uj 无产者_n ,_x 联合_v 起来_v !_x"
66
+ ```
67
+ ### 词频统计
68
+
69
+ ```ruby
70
+ z.freq "全世界的无产者,联合起来!", 5
71
+ #=> [["无产者", 9.96885201925], ["全世界", 6.80147590842], ["联合", 5.64979650728], ["起来", 3.96134044655]]
72
+
73
+ # alias 拼音, 分词, 标记, 词频
74
+
75
+ ```
76
+
77
+ ## LINCENCE :: 协议
78
+
79
+ __MPL 2.0__
80
+
81
+ ## Requires
82
+
83
+ - `jieba-rb`
84
+ - `nokogiri`
85
+ - `open-uri`
data/lib/igo/ja.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'jisho_api'
2
2
  require 'nokogiri'
3
3
  require 'open-uri'
4
-
4
+ require 'uri'
5
5
 
6
6
  module Igo
7
7
  module Jisho
@@ -10,6 +10,7 @@ module Igo
10
10
 
11
11
  class << self
12
12
  def cut str, s: false
13
+ str = URI.encode_www_form_component(str)
13
14
  doc = Nokogiri::HTML(URI.open(SEARCH_URL + str).read)
14
15
  cutted = doc.css(".japanese_word__text_wrapper").map{_1.text.strip}
15
16
  s ? cutted.join(" ") : cutted
data/lib/igo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Igo
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/igo/zh.rb CHANGED
@@ -3,15 +3,17 @@ require 'ruby_pinyin'
3
3
  module Igo
4
4
  module Zh
5
5
 
6
- Tagging = JiebaRb::Tagging
6
+ Tagging = JiebaRb::Tagging.new
7
7
  Segment = JiebaRb::Segment.new mode: :mix, user_dict: "ext/cppjieba/dict/user.dict.utf8"
8
8
  Keyword = JiebaRb::Keyword.new
9
9
 
10
10
  # @params chinese: String
11
11
  # @returns pinyin_numeraltone: String
12
12
  class << self
13
- def pinyin str
14
- str.each_char.map{PinYin.of_string(_1, :ascii)}
13
+ def pinyin str, s: false
14
+ res = str.each_char.map{PinYin.of_string(_1, :ascii)}.flatten
15
+ s ? res.join(" ") : res
16
+
15
17
  end
16
18
  def pinyin_tonal_s str
17
19
  PinYin.sentence(token, :ascii)
@@ -24,7 +26,8 @@ module Igo
24
26
  if tag
25
27
  s ? Tagging.tag(str).map{_1.to_a.flatten.join("_")}.join(" ") : Tagging.tag(str).map{_1.to_a.flatten}
26
28
  else
27
- Segment.cut(str)
29
+ res = Segment.cut(str)
30
+ s ? res.join(" ") : res
28
31
  end
29
32
  end
30
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: igo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - saisui
@@ -32,7 +32,7 @@ files:
32
32
  - sig/igo.rbs
33
33
  homepage: https://github.com/saisui/igo-rb
34
34
  licenses:
35
- - MIT
35
+ - MPL-2.0
36
36
  metadata:
37
37
  allowed_push_host: https://rubygems.org
38
38
  homepage_uri: https://github.com/saisui/igo-rb