loremarkov 0.1.0.1 → 0.2.0.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 +7 -1
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/loremarkov.rb +10 -1
- data/loremarkov.gemspec +1 -0
- data/test/test_loremarkov.rb +33 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e78a7b3fb1d519f6c0224af1f9f1b7d474dc3d26
|
4
|
+
data.tar.gz: 69de89322707b1b4b6fe12e50e3c3210440d8288
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2777a1717bebf7649e6ba48ae38a0385bccf1d23247f00c5aca5b0ac64468058ec11a469cdbb84c94d6dc1d680109aece186e381afc54407c022d2b42b7c6382
|
7
|
+
data.tar.gz: 1d998f8216b82045bed198cdbaf5f6996ae17e1382505b540a80930605bed458c933068f17c690aeff7b6eb98ee2ad1736b06a3de7714d3702bd2c99a6957622
|
data/README.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
[](https://travis-ci.org/rickhull/loremarkov)
|
2
|
+
[](http://badge.fury.io/rb/loremarkov)
|
3
|
+
[](https://codeclimate.com/github/rickhull/loremarkov)
|
4
|
+
[](https://gemnasium.com/rickhull/loremarkov)
|
5
|
+
[](https://hakiri.io/github/rickhull/loremarkov/master)
|
6
|
+
|
1
7
|
Introduction
|
2
8
|
===
|
3
9
|
|
@@ -33,7 +39,7 @@ Examples
|
|
33
39
|
$ destroy epigenetics
|
34
40
|
$ destroy oslo_accords 3
|
35
41
|
$ destroy ~/my_first_corpus.txt
|
36
|
-
$ man ls | destroy
|
42
|
+
$ man ls | destroy 12
|
37
43
|
|
38
44
|
Inspiration
|
39
45
|
===
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0.1
|
data/lib/loremarkov.rb
CHANGED
@@ -93,6 +93,12 @@ class Loremarkov
|
|
93
93
|
lex(text[0, 999 * num_prefix_words])[0, num_prefix_words]
|
94
94
|
end
|
95
95
|
|
96
|
+
# Given `lorem_ipsum`, return the string from reading `text/lorem_ipsum`
|
97
|
+
def self.sample_text(name)
|
98
|
+
File.read File.join(__dir__, '..', 'text', name)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Useful for testing at the very least
|
96
102
|
attr_reader :markov
|
97
103
|
|
98
104
|
# More prefix_words means tighter alignment to original text
|
@@ -102,7 +108,10 @@ class Loremarkov
|
|
102
108
|
end
|
103
109
|
|
104
110
|
# Generate Markov structure from text.
|
105
|
-
# Text should have a definite end, not just a convenient buffer split
|
111
|
+
# Text should have a definite end, not just a convenient buffer split.
|
112
|
+
# This method may be called several times, but note that several EOFs
|
113
|
+
# will be present in the markov structure, any one of which will trigger
|
114
|
+
# a conclusion by #generate_all.
|
106
115
|
def analyze(text)
|
107
116
|
@markov.merge!(self.class.analyze(text, @num_prefix_words))
|
108
117
|
end
|
data/loremarkov.gemspec
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'loremarkov'
|
4
|
+
|
5
|
+
NUM_PREFIX = 3
|
6
|
+
LOREM_IPSUM = Loremarkov.sample_text 'lorem_ipsum'
|
7
|
+
LOREM_LEX = Loremarkov.lex LOREM_IPSUM
|
8
|
+
LOREM_SENTENCE = LOREM_IPSUM[/[^.]*\./]
|
9
|
+
LOREM_SENTENCE_WORDS = %w{
|
10
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
11
|
+
tempor incididunt ut labore et dolore magna aliqua.
|
12
|
+
}
|
13
|
+
|
14
|
+
describe Loremarkov do
|
15
|
+
describe "Lorem ipsum" do
|
16
|
+
describe "sample text" do
|
17
|
+
it "must match test data" do
|
18
|
+
# this works because the first Lorem tokens are all spaces
|
19
|
+
LOREM_SENTENCE.must_equal LOREM_SENTENCE_WORDS.join(' ')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "lex" do
|
24
|
+
it "must provide expected prefixes" do
|
25
|
+
LOREM_LEX.each.with_index { |token, i|
|
26
|
+
break if i >= 36
|
27
|
+
# this too works because all tokens are spaces
|
28
|
+
token.must_equal (i % 2 == 0 ? LOREM_SENTENCE_WORDS[i/2] : ' ')
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loremarkov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Hull
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- bin/destroy
|
66
66
|
- lib/loremarkov.rb
|
67
67
|
- loremarkov.gemspec
|
68
|
+
- test/test_loremarkov.rb
|
68
69
|
- text/epigenetics
|
69
70
|
- text/lorem_ipsum
|
70
71
|
- text/oslo_accords
|