kusari 0.1.1 → 0.2.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 +4 -4
- data/README.md +14 -22
- data/kusari.gemspec +1 -0
- data/lib/kusari.rb +8 -0
- data/lib/kusari/markov_sentence_generator.rb +21 -0
- data/lib/kusari/version.rb +1 -1
- metadata +16 -3
- data/CODE_OF_CONDUCT.md +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c5e18dceb3a187701f5b2603b8dad8b3d1428a6
|
4
|
+
data.tar.gz: 24007d2bd9e077c9cf64a1e57fdf5b6c344825be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
30
|
+
In addition to the above operations, we can save the tokenized word table on local as:
|
43
31
|
|
44
32
|
```ruby
|
45
|
-
|
46
|
-
p sentence
|
47
|
-
# => "ネロは、アルデンネ生まれの兄弟よりも仲のよい大の少年でした。"
|
33
|
+
generator.save("tokenized_table.markov")
|
48
34
|
```
|
49
35
|
|
50
|
-
|
36
|
+
And it can be loaded by:
|
51
37
|
|
52
|
-
|
38
|
+
```ruby
|
39
|
+
generator.load("tokenized_table.markov")
|
40
|
+
```
|
53
41
|
|
54
|
-
|
42
|
+
Finally, we can obtain randomly generated sentence as:
|
55
43
|
|
56
|
-
|
44
|
+
```ruby
|
45
|
+
generator.generate(140)
|
46
|
+
# => "ネロは、アルデンネ生まれの兄弟よりも仲のよい大の少年でした。"
|
47
|
+
```
|
57
48
|
|
58
|
-
|
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
|
-
|
51
|
+
## License
|
61
52
|
|
53
|
+
MIT
|
data/kusari.gemspec
CHANGED
data/lib/kusari.rb
CHANGED
@@ -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
|
data/lib/kusari/version.rb
CHANGED
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.
|
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-
|
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
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -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/)
|