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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bd23a95575a6e870596ea70b119829c01cbeaf0
4
- data.tar.gz: e52a64cf85a4993763df1121d9cd0b7adb53d6c2
3
+ metadata.gz: 74fdef5cc781f68d8fa0649852196e18da653bb4
4
+ data.tar.gz: 4527dd51cc6a9457232417b710d6dba6ee575a9c
5
5
  SHA512:
6
- metadata.gz: 8ead23f301fa3745b1dc25e19b11f7d225595868cd365b1c067c17ae7dc393502cbaed79dcd63ae121ba15a352dbd0971c1ae3b55a34570258ef168ca589f0db
7
- data.tar.gz: 7afdbd2f11989ddcdde5ae67d8bcd3d59156e7fe1a4965c870827c699c6e9a6ef3d8b67965604eb5e6c13e24f9c1e9b077a9d01a6ca8a78c66e9b8b80e7fec79
6
+ metadata.gz: 8e71daa28c77501ef7161c8216f1b077492396d4c62d7125e1ab1fd3eca77f2232fdcd7ce94727b3e95c0ffccb478d6de727dd0262b36d3d0883c3c654472a73
7
+ data.tar.gz: 6828744572889782705e67bf3f04c18f46dd7ad32d0014a9b67371a264799d7688a61c2ad55d9abdf26e09acf9fccf58260dc12d170d138ce4b9cd8a8f83362e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # :link: Kusari
1
+ # :link: Kusari [![Gem Version](https://badge.fury.io/rb/kusari.png)](https://badge.fury.io/rb/kusari)
2
2
 
3
3
  Japanese random sentence generator based on Markov chain.
4
4
 
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 4 tokens, we can create both of HEAD-started and TAIL-ended array of words
30
- return if tokens.size < 4
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] + sampled_array[2]
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[2]
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[2] == TAIL
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] + sampled_array[2]
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
@@ -1,3 +1,3 @@
1
1
  module Kusari
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
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-09 00:00:00.000000000 Z
11
+ date: 2015-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: igo-ruby