glueckskeks 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/README.md +1 -1
- data/exe/glueckskeks +11 -5
- data/lib/glueckskeks.rb +5 -5
- data/lib/glueckskeks/corpus_reader.rb +5 -2
- data/lib/glueckskeks/substitutor.rb +3 -0
- data/lib/glueckskeks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d596fe9089e8325ffdda0c275925c96df62946
|
4
|
+
data.tar.gz: e76338be2e23856908d413b9a2528c5a2a753dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91215a0d6b09e922b73d9d7b6106868e48a09795624453c05fd2c2c759cfabe6d3228f64fec859100d7722595ed769a8e6692d1cd690d256184feb387775916c
|
7
|
+
data.tar.gz: d984b3216a4b6c19fff24fb31d03ac6f034517cefb424db94f5b5383cf9f59c4788ab0946c9d013207ba4933bffe7b665662a0959013469cad4a25b8b96ea59d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ To install the gem (to use its executable):
|
|
12
12
|
|
13
13
|
$ gem install glueckskeks
|
14
14
|
|
15
|
-
To play with its functionality from your own (ruby) code
|
15
|
+
To play with its functionality from your own (ruby) code add this line to your application's Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
gem 'glueckskeks'
|
data/exe/glueckskeks
CHANGED
@@ -3,16 +3,22 @@
|
|
3
3
|
require 'glueckskeks'
|
4
4
|
require 'optparse'
|
5
5
|
|
6
|
-
options = {}
|
6
|
+
options = {corpus: 'corpus', base: 'base'}
|
7
7
|
|
8
8
|
optparse = OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
10
10
|
opts.separator ""
|
11
|
-
opts.separator "Generate phrase from files in corpus
|
11
|
+
opts.separator "Generate phrase from files (default: in corpus/)."
|
12
12
|
opts.separator ""
|
13
13
|
|
14
|
-
opts.on('-
|
15
|
-
options[:
|
14
|
+
opts.on('-b', '--base=BASE', 'Start extension from BASE file (default: \'base\')') do |b|
|
15
|
+
options[:base] = b
|
16
|
+
end
|
17
|
+
opts.on('-c', '--corpus=DIRECTORY', 'Read .corpus files from DIRECTORY (default: \'./corpus\'') do |c|
|
18
|
+
options[:corpus] = c
|
19
|
+
end
|
20
|
+
opts.on('-d', '--debug', 'Print debug messages to STDOUT') do |d|
|
21
|
+
options[:debug] = d
|
16
22
|
end
|
17
23
|
opts.on_tail('--version', 'Show version and exit.') do
|
18
24
|
puts "#{$PROGRAM_NAME} #{Glueckskeks::VERSION}"
|
@@ -26,6 +32,6 @@ end.parse!
|
|
26
32
|
|
27
33
|
Glueckskeks.logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
|
28
34
|
|
29
|
-
phrase = Glueckskeks.generate
|
35
|
+
phrase = Glueckskeks.generate(options[:corpus], options[:base])
|
30
36
|
puts phrase
|
31
37
|
puts Glueckskeks::Collapser.collapse(phrase)
|
data/lib/glueckskeks.rb
CHANGED
@@ -16,16 +16,16 @@ module Glueckskeks
|
|
16
16
|
@logger = new_logger
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.generate
|
20
|
-
@corpus = CorpusReader.read_corpus_files
|
21
|
-
if @corpus
|
19
|
+
def self.generate(corpus_dir='corpus', entry='base')
|
20
|
+
@corpus = CorpusReader.read_corpus_files(corpus_dir)
|
21
|
+
if @corpus && @corpus.empty?
|
22
22
|
STDERR.puts "Empty corpus, are any data files present in ./corpus ?"
|
23
23
|
exit 1
|
24
24
|
end
|
25
|
-
if @corpus[
|
25
|
+
if @corpus[entry].nil? || @corpus[entry].empty?
|
26
26
|
STDERR.puts "Corpus does not contain a base (corpus/base.corpus) file, or it does not contain any patterns."
|
27
27
|
exit 2
|
28
28
|
end
|
29
|
-
Templater.fill(@corpus[
|
29
|
+
Templater.fill(@corpus[entry].sample, @corpus)
|
30
30
|
end
|
31
31
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Glueckskeks
|
2
2
|
class CorpusReader
|
3
|
-
def self.read_corpus_files
|
3
|
+
def self.read_corpus_files(corpus_dir='corpus')
|
4
4
|
result_map = {}
|
5
5
|
|
6
|
-
Dir.glob(
|
6
|
+
Dir.glob("#{corpus_dir}/*.corpus").each do |filename|
|
7
7
|
Glueckskeks.logger.debug "Reading corpus file #{filename}"
|
8
8
|
file = File.new(filename)
|
9
9
|
|
@@ -13,6 +13,9 @@ module Glueckskeks
|
|
13
13
|
lines.reject!(&:empty?)
|
14
14
|
|
15
15
|
Glueckskeks.logger.debug "#{lines.count} valid line(s) found"
|
16
|
+
if lines.count == 0
|
17
|
+
Glueckskeks.logger.error "#{filename} does not contain any pattern"
|
18
|
+
end
|
16
19
|
result_map[File.basename(file, '.corpus')] = lines
|
17
20
|
end
|
18
21
|
|
@@ -3,6 +3,9 @@ module Glueckskeks
|
|
3
3
|
def self.replace(str, corpus)
|
4
4
|
/.*<(?<type>[^>]*)>.*/ =~ str
|
5
5
|
if type
|
6
|
+
if !(corpus.has_key? type)
|
7
|
+
Glueckskeks.logger.error "No corpus entry for #{type} found"
|
8
|
+
end
|
6
9
|
replace_with = corpus[type].sample
|
7
10
|
str.gsub!("\<#{type}\>", replace_with)
|
8
11
|
end
|
data/lib/glueckskeks/version.rb
CHANGED