markovite 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/environment.rb +4 -0
- data/lib/.DS_Store +0 -0
- data/lib/markovite.rb +86 -0
- data/lib/markovite/chainer.rb +117 -0
- data/lib/markovite/dict.rb +67 -0
- data/lib/markovite/splitter.rb +69 -0
- data/lib/markovite/version.rb +3 -0
- data/markovite.gemspec +35 -0
- data/pkg/markovite-0.1.0.gem +0 -0
- data/pkg/markovite-0.2.0.gem +0 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59954d2685196332c680dcad7b09ac470e25fc284035da71fbb9b40898bac750
|
4
|
+
data.tar.gz: abd736b797da4d2b6c25a1d64226e4d0ea402cb861b539d8edbfd0eee2c015cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 589de5784a1afe9e2cf25b5cb41c71eafb962646b77c62b4f5bdb358f573cf4891ba933252ee065fadd50ae3cc7ba1a29d06f4f8a47a0cc833b0b5aa16d63746
|
7
|
+
data.tar.gz: a2434e3dd6e04f9946ba5800daf2fdb0826decb23504cc901bd9d73ef88bc389bfc135de74c47b62b8b47656000831026b2a3ede7144ba095cd7768f7e1b4d23
|
data/.DS_Store
ADDED
Binary file
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at superbiscuit@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
markovite (0.2.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
markovite!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 f3mshep
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Markovite
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/markovite`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'markovite'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install markovite
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/f3mshep/markovite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Markovite project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/f3mshep/markovite/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "markovite"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/markovite.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative "../config/environment"
|
2
|
+
|
3
|
+
module Markovite
|
4
|
+
FILE_EXT = [/.txt\z/i, /.rtf\z/i]
|
5
|
+
class Chain
|
6
|
+
attr_accessor :dictionary, :chainer, :split
|
7
|
+
attr_reader :depth
|
8
|
+
DEFAULT_DEPTH = 2
|
9
|
+
MAX_FILENAME_LENGTH = 255
|
10
|
+
|
11
|
+
def initialize(filename = nil, dict_depth=DEFAULT_DEPTH)
|
12
|
+
parse_file(filename, dict_depth) if filename
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_string(text, dict_depth=DEFAULT_DEPTH)
|
16
|
+
if chainer
|
17
|
+
add_from_text(text)
|
18
|
+
else
|
19
|
+
new_from_text(text, dict_depth)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_file(filename, dict_depth = DEFAULT_DEPTH)
|
24
|
+
raise "Invalid file type" if !is_valid_file_ext?(filename)
|
25
|
+
text = File.read(filename)
|
26
|
+
parse_string(text, dict_depth)
|
27
|
+
end
|
28
|
+
|
29
|
+
def << (corpus)
|
30
|
+
if is_file?(corpus)
|
31
|
+
parse_file(corpus)
|
32
|
+
else
|
33
|
+
parse_string(corpus)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
####Future Self: Make this a module####
|
38
|
+
|
39
|
+
def split_words(str)
|
40
|
+
str.split(" ")
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_sentence
|
44
|
+
chainer.make_sentence
|
45
|
+
end
|
46
|
+
|
47
|
+
def make_sentences(amount)
|
48
|
+
chainer.make_sentences(amount)
|
49
|
+
end
|
50
|
+
|
51
|
+
def make_sentence_starts_with(phrase)
|
52
|
+
chainer.make_sentence_starts_with(phrase)
|
53
|
+
end
|
54
|
+
|
55
|
+
def make_sentence_of_length(how_long)
|
56
|
+
chainer.make_sentence_of_length(how_long)
|
57
|
+
end
|
58
|
+
|
59
|
+
#### ####
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def new_from_text(text, dict_depth)
|
64
|
+
#look into refactoring this
|
65
|
+
@depth = dict_depth
|
66
|
+
self.split = SplitSentence.new(text)
|
67
|
+
self.dictionary = Dictionary.new(split, depth)
|
68
|
+
self.chainer = Chainer.new(dictionary)
|
69
|
+
end
|
70
|
+
|
71
|
+
def is_valid_file_ext?(filename)
|
72
|
+
re = Regexp.union(FILE_EXT)
|
73
|
+
filename.match(re)
|
74
|
+
end
|
75
|
+
|
76
|
+
def is_file?(str)
|
77
|
+
str.length < 255 && split_words(str).length == 1
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_from_text(text)
|
81
|
+
dictionary.expand_chain(text)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# class
|
2
|
+
class Chainer
|
3
|
+
|
4
|
+
attr_accessor :dictionary
|
5
|
+
attr_reader :depth
|
6
|
+
|
7
|
+
BEGINNING = "__BEGIN__"
|
8
|
+
ENDING = "__END__"
|
9
|
+
MAX_ATTEMPTS = 15
|
10
|
+
|
11
|
+
def initialize(dictionary)
|
12
|
+
self.dictionary = dictionary
|
13
|
+
@depth = dictionary.depth
|
14
|
+
#takes in a dictionary object
|
15
|
+
#constructs chain from dictionary object public interface
|
16
|
+
end
|
17
|
+
|
18
|
+
def make_sentence_starts_with(phrase)
|
19
|
+
chunk = get_chunk(phrase)
|
20
|
+
partial = generate_text(chunk)
|
21
|
+
"#{phrase} #{partial}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_sentence_of_length(how_long)
|
25
|
+
make_sentence_with_block {|sentence| sentence.length <= how_long}
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_sentences(amount, condition=true)
|
29
|
+
sentences = []
|
30
|
+
amount.times do
|
31
|
+
sentences << make_sentence(condition)
|
32
|
+
end
|
33
|
+
sentences.join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
def depth=(arg)
|
37
|
+
raise "Depth cannot be changed"
|
38
|
+
end
|
39
|
+
|
40
|
+
def make_sentence
|
41
|
+
raise "No corpus in memory" if dictionary.nil?
|
42
|
+
attempts = 0
|
43
|
+
while attempts < MAX_ATTEMPTS
|
44
|
+
sentence = generate_text
|
45
|
+
if is_valid_sentence?(sentence)
|
46
|
+
return sentence
|
47
|
+
else
|
48
|
+
attempts += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def make_sentence_with_block
|
57
|
+
attempts = 0
|
58
|
+
while attempts < MAX_ATTEMPTS
|
59
|
+
sentence = make_sentence
|
60
|
+
if yield(sentence)
|
61
|
+
return sentence
|
62
|
+
else
|
63
|
+
attempts += 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_chunk(phrase)
|
69
|
+
words = phrase.split(' ')
|
70
|
+
chunk = words.last(depth)
|
71
|
+
while chunk.size < depth
|
72
|
+
chunk.unshift(BEGINNING)
|
73
|
+
end
|
74
|
+
chunk
|
75
|
+
end
|
76
|
+
|
77
|
+
def pick_next(words)
|
78
|
+
word_list = dictionary.chain[words]
|
79
|
+
raise "No matching state found" if word_list.empty?
|
80
|
+
word_list.sample
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_markers(sentence)
|
84
|
+
#removes BEGINNING and ENDING markers
|
85
|
+
sentence.pop
|
86
|
+
sentence.shift(depth)
|
87
|
+
end
|
88
|
+
|
89
|
+
def is_valid_sentence?(sentence)
|
90
|
+
!dictionary.has_sentence(sentence)
|
91
|
+
end
|
92
|
+
|
93
|
+
def has_open_quote?(sentence)
|
94
|
+
count = sentence.count("\"")
|
95
|
+
count.odd?
|
96
|
+
end
|
97
|
+
|
98
|
+
def close_open_quote(sentence)
|
99
|
+
if has_open_quote?(sentence)
|
100
|
+
"#{sentence}\""
|
101
|
+
else
|
102
|
+
sentence
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def generate_text(current_chunk = [BEGINNING] * depth)
|
107
|
+
sentence = current_chunk
|
108
|
+
while current_chunk.last != ENDING
|
109
|
+
sentence << pick_next(current_chunk)
|
110
|
+
current_chunk = sentence.last(depth)
|
111
|
+
end
|
112
|
+
remove_markers(sentence)
|
113
|
+
sentence = sentence.join(' ')
|
114
|
+
close_open_quote(sentence)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# class that takes a training corpus and creates a hash that represents
|
2
|
+
# a markov chain state machine
|
3
|
+
|
4
|
+
class Dictionary
|
5
|
+
|
6
|
+
#make this a module???
|
7
|
+
BEGINNING = "__BEGIN__"
|
8
|
+
ENDING = "__END__"
|
9
|
+
|
10
|
+
attr_accessor :chain, :sentence_split, :sentences
|
11
|
+
attr_reader :depth
|
12
|
+
def initialize(sentence_split, depth = 2)
|
13
|
+
self.sentence_split = sentence_split
|
14
|
+
# The following line ensures a new array is created for each new key
|
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
|
+
# as the default value
|
17
|
+
self.chain = Hash.new { |h, k| h[k] = [] }
|
18
|
+
self.sentences = sentence_split.sentences
|
19
|
+
@depth = depth
|
20
|
+
construct_chain
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_sentence(sentence)
|
24
|
+
sentences.include?(sentence)
|
25
|
+
end
|
26
|
+
|
27
|
+
def depth=(arg)
|
28
|
+
raise "Depth cannot be changed"
|
29
|
+
end
|
30
|
+
|
31
|
+
def expand_chain(text)
|
32
|
+
new_sentences = sentence_split.expand_corpus(text)
|
33
|
+
sentences = sentence_split.sentences
|
34
|
+
construct_chain(new_sentences)
|
35
|
+
end
|
36
|
+
|
37
|
+
def construct_chain(new_sentences = nil)
|
38
|
+
new_sentences = new_sentences || sentences
|
39
|
+
raise "No sentences in memory" if new_sentences.empty?
|
40
|
+
new_sentences.each do |sentence|
|
41
|
+
words = sentence.split(" ")
|
42
|
+
# each chunk is an array that represents a state in the markov chain
|
43
|
+
# it is a key that points to the next possible states
|
44
|
+
chunk = [BEGINNING] * depth
|
45
|
+
words.each do |word|
|
46
|
+
# using a clone of the chunk ensures the VALUE
|
47
|
+
# of the chunk is used as the key, instead of
|
48
|
+
# whatever is stored at the memory address
|
49
|
+
# of the initial chunk
|
50
|
+
chain[chunk.clone] << word
|
51
|
+
chunk.shift
|
52
|
+
chunk.push(word)
|
53
|
+
end
|
54
|
+
chain[chunk] << ENDING
|
55
|
+
end
|
56
|
+
chain
|
57
|
+
end
|
58
|
+
|
59
|
+
def clear_chain
|
60
|
+
chain.clear
|
61
|
+
end
|
62
|
+
|
63
|
+
def clear_sentences
|
64
|
+
sentences.clear
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#class that takes a corpus and breaks it down into arrays.
|
2
|
+
#each array is one sentence.
|
3
|
+
|
4
|
+
class SplitSentence
|
5
|
+
|
6
|
+
SPLITTERS = ['\n', '?', '.', '!']
|
7
|
+
|
8
|
+
#look into detecting abbreviations!
|
9
|
+
|
10
|
+
attr_accessor :sentences, :corpus
|
11
|
+
|
12
|
+
def initialize(corpus)
|
13
|
+
self.corpus = corpus.dup
|
14
|
+
self.sentences = []
|
15
|
+
split_text
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear_sentences
|
19
|
+
sentences.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
# We will want to change this to something that splits the words into an
|
23
|
+
# array, then we will make another pass through the word array to find
|
24
|
+
# where a sentence begins and ends
|
25
|
+
|
26
|
+
# might be cool to count punct. separately, we can point to punct as a way to indicate the end. if the
|
27
|
+
# sentences are delimited by \n, we can have nil be the value it points to instead.
|
28
|
+
# This way, we can impose grammatical rules by making the first word of the sentence
|
29
|
+
# capitalized, and the end of the sentence will end with some sort of punctuation.
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def split_text(new_text = nil)
|
34
|
+
#not sure how elegant clear_sentence is here
|
35
|
+
clear_sentences unless new_text
|
36
|
+
new_text = new_text || corpus
|
37
|
+
current_sentence = ""
|
38
|
+
new_sentences = []
|
39
|
+
new_text.each_char do |char|
|
40
|
+
if SPLITTERS.include?(char)
|
41
|
+
current_sentence << char
|
42
|
+
new_sentences << current_sentence
|
43
|
+
self.sentences << current_sentence
|
44
|
+
current_sentence = ""
|
45
|
+
else
|
46
|
+
next if current_sentence == "" && char == " "
|
47
|
+
current_sentence << char
|
48
|
+
end
|
49
|
+
end
|
50
|
+
new_sentences
|
51
|
+
end
|
52
|
+
|
53
|
+
def expand_corpus(new_text)
|
54
|
+
corpus << "\n" + new_text
|
55
|
+
split_text(new_text)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def is_abbreviation
|
61
|
+
end
|
62
|
+
|
63
|
+
def is_url
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_sentence_end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/markovite.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "markovite/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "markovite"
|
8
|
+
spec.version = Markovite::VERSION
|
9
|
+
spec.authors = ["Alexandra Wright"]
|
10
|
+
spec.email = ["superbiscuit@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A markov chain generator that is simple to use and easy to hack."
|
13
|
+
spec.description = "Doctors hate this one weird trick that generates really good looking gibberish!"
|
14
|
+
spec.homepage = "https://github.com/f3mshep/ruby_markovify"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
|
30
|
+
spec.require_paths = ["lib", "config"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markovite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandra Wright
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Doctors hate this one weird trick that generates really good looking
|
56
|
+
gibberish!
|
57
|
+
email:
|
58
|
+
- superbiscuit@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".DS_Store"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- config/environment.rb
|
73
|
+
- lib/.DS_Store
|
74
|
+
- lib/markovite.rb
|
75
|
+
- lib/markovite/chainer.rb
|
76
|
+
- lib/markovite/dict.rb
|
77
|
+
- lib/markovite/splitter.rb
|
78
|
+
- lib/markovite/version.rb
|
79
|
+
- markovite.gemspec
|
80
|
+
- pkg/markovite-0.1.0.gem
|
81
|
+
- pkg/markovite-0.2.0.gem
|
82
|
+
homepage: https://github.com/f3mshep/ruby_markovify
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
allowed_push_host: https://rubygems.org
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
- config
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.7.4
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: A markov chain generator that is simple to use and easy to hack.
|
108
|
+
test_files: []
|