kusari 0.1.0 → 0.1.1
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 +1 -1
- data/lib/kusari.rb +1 -1
- data/lib/kusari/markov_sentence_generator.rb +7 -7
- data/lib/kusari/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74fdef5cc781f68d8fa0649852196e18da653bb4
|
4
|
+
data.tar.gz: 4527dd51cc6a9457232417b710d6dba6ee575a9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e71daa28c77501ef7161c8216f1b077492396d4c62d7125e1ab1fd3eca77f2232fdcd7ce94727b3e95c0ffccb478d6de727dd0262b36d3d0883c3c654472a73
|
7
|
+
data.tar.gz: 6828744572889782705e67bf3f04c18f46dd7ad32d0014a9b67371a264799d7688a61c2ad55d9abdf26e09acf9fccf58260dc12d170d138ce4b9cd8a8f83362e
|
data/README.md
CHANGED
data/lib/kusari.rb
CHANGED
@@ -4,7 +4,7 @@ require "kusari/version"
|
|
4
4
|
module Kusari
|
5
5
|
class Generator
|
6
6
|
def initialize(gram=3, ipadic_path="./ipadic")
|
7
|
-
@generator = MarkovSentenceGenerator.new(gram, ipadic_path)
|
7
|
+
@generator = MarkovSentenceGenerator.new([2, gram].max, ipadic_path)
|
8
8
|
end
|
9
9
|
|
10
10
|
def add_string(string)
|
@@ -26,8 +26,8 @@ class MarkovSentenceGenerator
|
|
26
26
|
def add(string)
|
27
27
|
tokens = tokenize(string)
|
28
28
|
|
29
|
-
# if there are at least
|
30
|
-
return if tokens.size <
|
29
|
+
# if there are at least N+1 tokens, we can create both of HEAD-started and TAIL-ended array of words
|
30
|
+
return if tokens.size < @gram + 1
|
31
31
|
|
32
32
|
# update markov_table
|
33
33
|
i = 0
|
@@ -49,14 +49,14 @@ class MarkovSentenceGenerator
|
|
49
49
|
|
50
50
|
# sample one HEAD-started array and create initial sentence based on that
|
51
51
|
sampled_array = head_arrays.sample
|
52
|
-
sentence = sampled_array[1]
|
52
|
+
sentence = sampled_array[1..@gram-1].join
|
53
53
|
|
54
54
|
# start Markov chain until getting the TAIL flag
|
55
55
|
loop do
|
56
56
|
# select all arrays which can chain their head word to current tail of the sentence
|
57
57
|
chain_arrays = Array.new
|
58
58
|
@markov_table.each do |markov_array|
|
59
|
-
if markov_array[0] == sampled_array[
|
59
|
+
if markov_array[0] == sampled_array[@gram-1]
|
60
60
|
chain_arrays << markov_array
|
61
61
|
end
|
62
62
|
end
|
@@ -66,11 +66,11 @@ class MarkovSentenceGenerator
|
|
66
66
|
|
67
67
|
# grow current sentence and check if it has the TAIL flag
|
68
68
|
sampled_array = chain_arrays.sample
|
69
|
-
if sampled_array[
|
70
|
-
sentence += sampled_array[1]
|
69
|
+
if sampled_array[sampled_array.length-1] == TAIL
|
70
|
+
sentence += sampled_array[1..@gram-2].join
|
71
71
|
break
|
72
72
|
else
|
73
|
-
concat_string = sampled_array[1]
|
73
|
+
concat_string = sampled_array[1..@gram-1].join
|
74
74
|
break if sentence.length + concat_string.length > limit
|
75
75
|
sentence += concat_string
|
76
76
|
end
|
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.1.
|
4
|
+
version: 0.1.1
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: igo-ruby
|