markovite 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: 9228ae1173249e835b7a51bff00e748a4cda2a134592a3bf630bbc55320fcbe1
4
- data.tar.gz: 51d7fca721c7598b77185ad7729176b1c60957889d53a8be70d6d1865b670b5c
3
+ metadata.gz: a45b08ff10130126c3f0325fca5a1a1d23d31b942e0430d088f73b6ab812faac
4
+ data.tar.gz: 698a6acf00459bb8f61f8325e48f2c096b36af8de6890126d2e68c2a0d994627
5
5
  SHA512:
6
- metadata.gz: b83bc1f1b4995779073a53ec19a542c80e6aac02a3995b44f51d16e875fbe12137fb540aabdfc7c4b03e65ff79e3322a3fc8fff60f6b4937bf1e6c7899b22e3f
7
- data.tar.gz: 55826f34f74b4c2cf8cf7cdd9a07310b7466927424d478da49e2ddf2b09455469d128f1e1513561f58261471e8cb67a626d58720bf7d4b820fbefdd36ef217ce
6
+ metadata.gz: d2579a001419cf3ca5913d8d55b7d05b98f5628de91c7b128b9276d58fc22cb2fded0237dc0852df1f2c4c15c1d461ac7e4f522fca1d002c9cae254ede2eb4fc
7
+ data.tar.gz: e5a2b74db3c68cde040a1d935d9c62237d6f076fa2d82893cdcbed0a7b42171ca8e47d71c76bcff15c7c663ef1edd1e231e5dbd1353dc78a2d8023d246c4c381
data/Gemfile.lock CHANGED
@@ -1,17 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markovite (0.2.3)
4
+ markovite (0.2.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  coderay (1.1.2)
10
10
  diff-lcs (1.3)
11
+ interception (0.5)
11
12
  method_source (0.9.0)
12
13
  pry (0.11.3)
13
14
  coderay (~> 1.1.0)
14
15
  method_source (~> 0.9.0)
16
+ pry-rescue (1.4.5)
17
+ interception (>= 0.5)
18
+ pry
15
19
  rake (10.4.2)
16
20
  rspec (3.7.0)
17
21
  rspec-core (~> 3.7.0)
@@ -34,6 +38,7 @@ DEPENDENCIES
34
38
  bundler (~> 1.16)
35
39
  markovite!
36
40
  pry
41
+ pry-rescue
37
42
  rake (~> 10.0)
38
43
  rspec (~> 3.0)
39
44
 
@@ -9,13 +9,13 @@ class Dictionary
9
9
 
10
10
  attr_accessor :chain, :sentence_split, :sentences
11
11
  attr_reader :depth
12
- def initialize(sentence_split, depth = 2)
13
- self.sentence_split = sentence_split
12
+ def initialize(sentence_split = nil, depth = 2)
13
+ self.sentence_split = sentence_split || SentenceSplit.new
14
14
  # The following line ensures a new array is created for each new key
15
15
  # instead of using the memory address of the first array created raise exception "First argument must contain a SplitSentence instance" if sentence_split.class != SentenceSplit
16
16
  # as the default value
17
17
  self.chain = Hash.new { |h, k| h[k] = [] }
18
- self.sentences = sentence_split.sentences
18
+ self.sentences = sentence_split.split_text
19
19
  @depth = depth
20
20
  construct_chain
21
21
  end
@@ -30,7 +30,8 @@ class Dictionary
30
30
 
31
31
  def expand_chain(text)
32
32
  new_sentences = sentence_split.split_text(text)
33
- self.sentences += sentence_split.sentences
33
+ sentence_split.expand_corpus(text)
34
+ self.sentences += new_sentences
34
35
  construct_chain(new_sentences)
35
36
  end
36
37
 
@@ -19,18 +19,13 @@ class SplitSentence
19
19
 
20
20
  #look into detecting abbreviations!
21
21
 
22
- attr_accessor :sentences, :corpus
22
+ attr_accessor :corpus
23
23
 
24
- def initialize(corpus)
24
+ def initialize(corpus = "")
25
25
  self.corpus = corpus.dup
26
- self.sentences = []
27
26
  split_text
28
27
  end
29
28
 
30
- def clear_sentences
31
- sentences.clear
32
- end
33
-
34
29
  # We will want to change this to something that splits the words into an
35
30
  # array, then we will make another pass through the word array to find
36
31
  # where a sentence begins and ends
@@ -41,31 +36,36 @@ class SplitSentence
41
36
  # capitalized, and the end of the sentence will end with some sort of punctuation.
42
37
 
43
38
  def split_text(new_text = nil)
44
- clear_sentences
45
39
  current_sentence = []
40
+ sentences = []
46
41
  new_text = new_text || corpus
47
42
  all_words = split_words(new_text)
48
43
  all_words.each do |word|
49
44
  if is_end_of_sentence?(word)
50
- current_sentence = add_sentence(current_sentence, word)
45
+ sentences << add_sentence(current_sentence, word)
46
+ current_sentence.clear
51
47
  elsif has_newline?(word)
52
48
  newline_words = split_newline(word)
53
- current_sentence = add_sentence(current_sentence, newline_words[0])
49
+ sentences << add_sentence(current_sentence, newline_words[0])
50
+ current_sentence.clear
54
51
  current_sentence << newline_words[1]
55
52
  else
56
53
  current_sentence << word
57
54
  end
58
55
  end
59
- add_sentence(current_sentence, nil) if !current_sentence.empty?
56
+ sentences << add_sentence(current_sentence, nil) if !current_sentence.empty?
60
57
  sentences
61
58
  end
62
59
 
60
+ def expand_corpus(text)
61
+ self.corpus += "\n" + text
62
+ end
63
+
63
64
  private
64
65
 
65
66
  def add_sentence(sentence, word)
66
67
  sentence << word if word
67
- sentences << sentence.compact.join(" ")
68
- []
68
+ sentence.compact.join(" ")
69
69
  end
70
70
 
71
71
  def split_words(text)
@@ -1,3 +1,3 @@
1
1
  module Markovite
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/markovite.rb CHANGED
@@ -14,7 +14,20 @@ module Markovite
14
14
  parse_file(filename, dict_depth) if filename
15
15
  end
16
16
 
17
- def parse_string(text, dict_depth=DEFAULT_DEPTH)
17
+ def self.combine(left_chain, right_chain, dict_depth = nil)
18
+ dict_depth = dict_depth || left_chain.depth
19
+ new_chain = Markovite::Chain.new
20
+ new_chain.parse_string(left_chain.corpus, dict_depth)
21
+ new_chain.parse_string(right_chain.corpus, dict_depth)
22
+ new_chain
23
+ end
24
+
25
+ def corpus
26
+ split.corpus
27
+ end
28
+
29
+ def parse_string(text, dict_depth=nil)
30
+ dict_depth = dict_depth || self.depth || DEFAULT_DEPTH
18
31
  depth_check(dict_depth)
19
32
  if chainer
20
33
  add_from_text(text)
@@ -81,6 +94,7 @@ module Markovite
81
94
  #look into refactoring this
82
95
  @depth = dict_depth
83
96
  self.split = SplitSentence.new(text)
97
+ @corpus = split.corpus
84
98
  self.dictionary = Dictionary.new(split, depth)
85
99
  self.chainer = Chainer.new(dictionary)
86
100
  end
data/markovite.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
  spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "pry-rescue"
36
37
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markovite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandra Wright
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-rescue
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: "Doctors hate this one weird trick that generates really good looking
70
84
  gibberish! \n Markovite is simple, but powerful markov chain generator that is designed
71
85
  to be hackable to your heart's delight"
@@ -93,6 +107,7 @@ files:
93
107
  - lib/markovite/version.rb
94
108
  - markovite.gemspec
95
109
  - pkg/markovite-0.2.2.gem
110
+ - pkg/markovite-0.2.3.gem
96
111
  homepage: https://github.com/f3mshep/ruby_markovify
97
112
  licenses:
98
113
  - MIT