poefy 1.1.1 → 2.0.0
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 +5 -5
- data/.rspec +1 -1
- data/LICENSE +13 -13
- data/README.md +844 -844
- data/Rakefile +6 -6
- data/bin/poefy +347 -310
- data/bin/poefy_make +91 -91
- data/data/st_therese_of_lisieux.txt +3700 -3700
- data/data/whitman_leaves.txt +17815 -17815
- data/lib/poefy/core_extensions/array.rb +121 -121
- data/lib/poefy/database.rb +151 -151
- data/lib/poefy/db_type.rb +57 -57
- data/lib/poefy/generation.rb +1 -1
- data/lib/poefy/poem_base.rb +114 -112
- data/lib/poefy/poetic_forms.rb +529 -529
- data/lib/poefy/self.rb +39 -39
- data/lib/poefy/version.rb +26 -26
- data/lib/poefy.rb +46 -46
- data/poefy.gemspec +5 -3
- data/settings.yml +2 -2
- data/spec/poefy_unit_spec.rb +621 -621
- data/spec/spec_helper.rb +11 -11
- metadata +9 -12
data/lib/poefy/poem_base.rb
CHANGED
@@ -1,112 +1,114 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: UTF-8
|
3
|
-
|
4
|
-
################################################################################
|
5
|
-
# Base internals for the Poem class.
|
6
|
-
################################################################################
|
7
|
-
|
8
|
-
module Poefy
|
9
|
-
|
10
|
-
module PoemBase
|
11
|
-
|
12
|
-
attr_reader :corpus, :local, :overwrite
|
13
|
-
|
14
|
-
def initialize db_name, options =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
lines
|
23
|
-
|
24
|
-
|
25
|
-
.
|
26
|
-
|
27
|
-
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@
|
60
|
-
@
|
61
|
-
@poetic_form
|
62
|
-
@poetic_form =
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
output[:
|
81
|
-
output[:
|
82
|
-
output[:
|
83
|
-
output[:
|
84
|
-
output[:
|
85
|
-
output[:
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: UTF-8
|
3
|
+
|
4
|
+
################################################################################
|
5
|
+
# Base internals for the Poem class.
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
module Poefy
|
9
|
+
|
10
|
+
module PoemBase
|
11
|
+
|
12
|
+
attr_reader :corpus, :local, :overwrite
|
13
|
+
|
14
|
+
def initialize db_name, options = nil
|
15
|
+
options ||= {}
|
16
|
+
handle_options options
|
17
|
+
@corpus = Poefy::Database.new db_name, @local
|
18
|
+
end
|
19
|
+
|
20
|
+
# Make a database using the given lines.
|
21
|
+
def make_database input, description = nil, overwrite = @overwrite
|
22
|
+
lines = validate_lines input
|
23
|
+
lines.map! do |line|
|
24
|
+
line.force_encoding('utf-8')
|
25
|
+
.gsub("\u00A0", ' ')
|
26
|
+
.strip
|
27
|
+
end
|
28
|
+
@corpus.close if @corpus
|
29
|
+
if overwrite
|
30
|
+
@corpus.make_new! lines, description
|
31
|
+
else
|
32
|
+
@corpus.make_new lines, description
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def make_database! input, description = nil
|
36
|
+
make_database input, description, true
|
37
|
+
end
|
38
|
+
|
39
|
+
# Close the database.
|
40
|
+
def close
|
41
|
+
@corpus.close
|
42
|
+
end
|
43
|
+
|
44
|
+
# Validate the lines. Arg could be a filename,
|
45
|
+
# newline delimited string, or array of lines.
|
46
|
+
def validate_lines input
|
47
|
+
|
48
|
+
# If the input is a file, then read it.
|
49
|
+
lines = File.exist?(input.to_s) ? File.read(input) : input
|
50
|
+
|
51
|
+
# If lines is not an array, assume string and split on newlines.
|
52
|
+
lines.respond_to?(:each) ? lines : lines.split("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Handle the optional initialize options hash.
|
58
|
+
def handle_options options
|
59
|
+
@overwrite = !!options[:overwrite]
|
60
|
+
@local = !!options[:local]
|
61
|
+
@poetic_form = {}
|
62
|
+
@poetic_form[:proper] = true
|
63
|
+
@poetic_form[:proper] = !!options[:proper] if options[:proper]
|
64
|
+
@poetic_form = validate_poetic_form options
|
65
|
+
end
|
66
|
+
|
67
|
+
# Make sure the options hash is in order.
|
68
|
+
def validate_poetic_form poetic_form
|
69
|
+
input, output = poetic_form, {}
|
70
|
+
form_string = get_valid_form input[:form]
|
71
|
+
|
72
|
+
# Apply ':form_from_text' before any others.
|
73
|
+
if input[:form_from_text]
|
74
|
+
lines = validate_lines input[:form_from_text]
|
75
|
+
form = poetic_form_from_text lines
|
76
|
+
input = form.merge input
|
77
|
+
end
|
78
|
+
|
79
|
+
# Handle obvious inputs.
|
80
|
+
output[:form] = form_string if form_string
|
81
|
+
output[:rhyme] = input[:rhyme] if input[:rhyme]
|
82
|
+
output[:indent] = input[:indent] if input[:indent]
|
83
|
+
output[:syllable] = input[:syllable] if input[:syllable]
|
84
|
+
output[:regex] = input[:regex] if input[:regex]
|
85
|
+
output[:acrostic] = input[:acrostic] if input[:acrostic]
|
86
|
+
output[:acrostic_x] = input[:acrostic_x] if input[:acrostic_x]
|
87
|
+
output[:transform] = input[:transform] if input[:transform]
|
88
|
+
|
89
|
+
# Tokenise string to arrays and hashes.
|
90
|
+
if output[:rhyme]
|
91
|
+
output[:rhyme] = tokenise_rhyme output[:rhyme]
|
92
|
+
end
|
93
|
+
rhyme = get_poetic_form_rhyme_longest(output)
|
94
|
+
if output[:syllable] and rhyme != ' '
|
95
|
+
output[:syllable] = transform_input_syllable output[:syllable], rhyme
|
96
|
+
end
|
97
|
+
if output[:regex]
|
98
|
+
output[:regex] = transform_input_regex output[:regex], rhyme
|
99
|
+
end
|
100
|
+
|
101
|
+
# Get from instance by default.
|
102
|
+
output[:proper] = input[:proper].nil? ?
|
103
|
+
@poetic_form[:proper] : input[:proper]
|
104
|
+
|
105
|
+
# Tiny amendment to solve later errors.
|
106
|
+
output[:rhyme] = ' ' if output[:rhyme] == ''
|
107
|
+
output
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
################################################################################
|