kusari 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74fdef5cc781f68d8fa0649852196e18da653bb4
4
- data.tar.gz: 4527dd51cc6a9457232417b710d6dba6ee575a9c
3
+ metadata.gz: 8c5e18dceb3a187701f5b2603b8dad8b3d1428a6
4
+ data.tar.gz: 24007d2bd9e077c9cf64a1e57fdf5b6c344825be
5
5
  SHA512:
6
- metadata.gz: 8e71daa28c77501ef7161c8216f1b077492396d4c62d7125e1ab1fd3eca77f2232fdcd7ce94727b3e95c0ffccb478d6de727dd0262b36d3d0883c3c654472a73
7
- data.tar.gz: 6828744572889782705e67bf3f04c18f46dd7ad32d0014a9b67371a264799d7688a61c2ad55d9abdf26e09acf9fccf58260dc12d170d138ce4b9cd8a8f83362e
6
+ metadata.gz: f563f36388c93c566af8d257d4ab827fb04842ade662dcc2e60085c3998a9931eaa64c055df272a8d3be707a7bfcd1648dc4be0cf4cc06b5042c9fdab2c475af
7
+ data.tar.gz: 0950caf620102142a7dd64d8acb39e2b8c075cbec962848847301d4a29c633dec52abf7b87951a830df58b81ee734e84af2140572d53cb2fd0056f6947310fdf
data/README.md CHANGED
@@ -4,18 +4,6 @@ Japanese random sentence generator based on Markov chain.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'kusari'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
7
  $ gem install kusari
20
8
 
21
9
  ## Usage
@@ -39,23 +27,27 @@ generator.add_string("彼らは、実の兄弟よりも仲のよい大の親友
39
27
  generator.add_string("ネロは、アルデンネ生まれの少年でした。")
40
28
  ```
41
29
 
42
- Finally, we can obtain randomly generated sentence as:
30
+ In addition to the above operations, we can save the tokenized word table on local as:
43
31
 
44
32
  ```ruby
45
- sentence = generator.generate(140)
46
- p sentence
47
- # => "ネロは、アルデンネ生まれの兄弟よりも仲のよい大の少年でした。"
33
+ generator.save("tokenized_table.markov")
48
34
  ```
49
35
 
50
- Here, an argument of the generate method defines limit length for the generated sentence; `generator.generate(140)` creates a sentence which can be posted on Twitter, for example.
36
+ And it can be loaded by:
51
37
 
52
- ## Development
38
+ ```ruby
39
+ generator.load("tokenized_table.markov")
40
+ ```
53
41
 
54
- 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.
42
+ Finally, we can obtain randomly generated sentence as:
55
43
 
56
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+ ```ruby
45
+ generator.generate(140)
46
+ # => "ネロは、アルデンネ生まれの兄弟よりも仲のよい大の少年でした。"
47
+ ```
57
48
 
58
- ## Contributing
49
+ Here, an argument of the generate method defines limit length for the generated sentence; `generator.generate(140)` creates a sentence which can be posted on Twitter, for example.
59
50
 
60
- Bug reports and pull requests are welcome on GitHub at https://github.com/takuti/kusari. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
51
+ ## License
61
52
 
53
+ MIT
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "igo-ruby", "~> 0.1.5"
22
+ spec.add_dependency "msgpack"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.10"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -14,5 +14,13 @@ module Kusari
14
14
  def generate(limit)
15
15
  @generator.generate(limit)
16
16
  end
17
+
18
+ def load(path)
19
+ @generator.load_table(path)
20
+ end
21
+
22
+ def save(path)
23
+ @generator.save_table(path)
24
+ end
17
25
  end
18
26
  end
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "igo-ruby"
4
+ require "msgpack"
4
5
 
5
6
  class MarkovSentenceGenerator
6
7
  HEAD = "[HEAD]"
@@ -16,6 +17,26 @@ class MarkovSentenceGenerator
16
17
  @markov_table = Array.new
17
18
  end
18
19
 
20
+ def load_table(path)
21
+ if File.exists?(path)
22
+ f = File.new(path, "rb").read
23
+ pack = MessagePack.unpack(f)
24
+ @gram = pack["gram"]
25
+ @markov_table = pack["table"]
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ def save_table(path)
32
+ pack = Hash.new
33
+ pack["gram"] = @gram
34
+ pack["table"] = @markov_table
35
+ File.open(path, "wb") do |f|
36
+ f.write pack.to_msgpack
37
+ end
38
+ end
39
+
19
40
  def tokenize(string)
20
41
  tokens = Array.new
21
42
  tokens << HEAD
@@ -1,3 +1,3 @@
1
1
  module Kusari
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kusari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takuti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-12 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: igo-ruby
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: msgpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -76,7 +90,6 @@ files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
78
92
  - ".travis.yml"
79
- - CODE_OF_CONDUCT.md
80
93
  - Gemfile
81
94
  - README.md
82
95
  - Rakefile
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)