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/bin/poefy_make
CHANGED
@@ -1,91 +1,91 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: UTF-8
|
3
|
-
|
4
|
-
################################################################################
|
5
|
-
# Determine which database interface to use, based on the gems installed.
|
6
|
-
# Generate initial corpora.
|
7
|
-
################################################################################
|
8
|
-
|
9
|
-
require_relative '../lib/poefy.rb'
|
10
|
-
|
11
|
-
Poefy.console = true
|
12
|
-
|
13
|
-
################################################################################
|
14
|
-
|
15
|
-
# Determine which database interface to use, based on the gems installed.
|
16
|
-
# Attempt to load exactly one of the below files.
|
17
|
-
# Array is ordered by priority, so use PostgreSQL before SQLite.
|
18
|
-
# (This code shouldn't really be necessary, unless the user has explicitly
|
19
|
-
# deleted their settings file.)
|
20
|
-
def determine_database_interface
|
21
|
-
loaded_file = nil
|
22
|
-
[
|
23
|
-
'poefy/pg',
|
24
|
-
'poefy/sqlite3'
|
25
|
-
].each do |file|
|
26
|
-
begin
|
27
|
-
require file
|
28
|
-
loaded_file = File.basename(file)
|
29
|
-
break
|
30
|
-
rescue LoadError
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Exit the program if no file loaded.
|
35
|
-
if loaded_file.nil?
|
36
|
-
e = Poefy::MissingDBInterface.new
|
37
|
-
STDERR.puts e.console_msg
|
38
|
-
exit 1
|
39
|
-
end
|
40
|
-
|
41
|
-
loaded_file
|
42
|
-
end
|
43
|
-
|
44
|
-
# If the user already has a database interface setup, then use that.
|
45
|
-
# If they don't, then determine based off installed gems.
|
46
|
-
if Poefy.database_type(false).nil?
|
47
|
-
Poefy.database_type = determine_database_interface
|
48
|
-
end
|
49
|
-
|
50
|
-
# Should already be setup, but just run this to confirm no error is thrown.
|
51
|
-
Poefy.require_db
|
52
|
-
|
53
|
-
################################################################################
|
54
|
-
|
55
|
-
# Create corpora from the text files included with the repository.
|
56
|
-
# Exclude all lines which do not contain lowercase letters.
|
57
|
-
def make_db database, textfile, description
|
58
|
-
file = Poefy.root + '/data/' + textfile
|
59
|
-
input = File.readlines(file).keep_if { |i| i =~ /[a-z]/ }
|
60
|
-
poefy = Poefy::Poem.new database
|
61
|
-
poefy.make_database! input, description
|
62
|
-
poefy.close
|
63
|
-
end
|
64
|
-
|
65
|
-
[
|
66
|
-
[
|
67
|
-
'shakespeare',
|
68
|
-
'shakespeare_sonnets.txt',
|
69
|
-
"Shakespeare's sonnets"
|
70
|
-
],[
|
71
|
-
'therese',
|
72
|
-
'st_therese_of_lisieux.txt',
|
73
|
-
"St. Thérèse of Lisieux"
|
74
|
-
],[
|
75
|
-
'whitman',
|
76
|
-
'whitman_leaves.txt',
|
77
|
-
"Walt Whitman, Leaves of Grass"
|
78
|
-
],[
|
79
|
-
'dickinson',
|
80
|
-
'emily_dickinson.txt',
|
81
|
-
"Emily Dickinson"
|
82
|
-
],[
|
83
|
-
'spoke',
|
84
|
-
'english_as_she_is_spoke.txt',
|
85
|
-
"English As She Is Spoke"
|
86
|
-
]
|
87
|
-
].each do |i|
|
88
|
-
make_db(*i)
|
89
|
-
end
|
90
|
-
|
91
|
-
################################################################################
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: UTF-8
|
3
|
+
|
4
|
+
################################################################################
|
5
|
+
# Determine which database interface to use, based on the gems installed.
|
6
|
+
# Generate initial corpora.
|
7
|
+
################################################################################
|
8
|
+
|
9
|
+
require_relative '../lib/poefy.rb'
|
10
|
+
|
11
|
+
Poefy.console = true
|
12
|
+
|
13
|
+
################################################################################
|
14
|
+
|
15
|
+
# Determine which database interface to use, based on the gems installed.
|
16
|
+
# Attempt to load exactly one of the below files.
|
17
|
+
# Array is ordered by priority, so use PostgreSQL before SQLite.
|
18
|
+
# (This code shouldn't really be necessary, unless the user has explicitly
|
19
|
+
# deleted their settings file.)
|
20
|
+
def determine_database_interface
|
21
|
+
loaded_file = nil
|
22
|
+
[
|
23
|
+
'poefy/pg',
|
24
|
+
'poefy/sqlite3'
|
25
|
+
].each do |file|
|
26
|
+
begin
|
27
|
+
require file
|
28
|
+
loaded_file = File.basename(file)
|
29
|
+
break
|
30
|
+
rescue LoadError
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Exit the program if no file loaded.
|
35
|
+
if loaded_file.nil?
|
36
|
+
e = Poefy::MissingDBInterface.new
|
37
|
+
STDERR.puts e.console_msg
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
loaded_file
|
42
|
+
end
|
43
|
+
|
44
|
+
# If the user already has a database interface setup, then use that.
|
45
|
+
# If they don't, then determine based off installed gems.
|
46
|
+
if Poefy.database_type(false).nil?
|
47
|
+
Poefy.database_type = determine_database_interface
|
48
|
+
end
|
49
|
+
|
50
|
+
# Should already be setup, but just run this to confirm no error is thrown.
|
51
|
+
Poefy.require_db
|
52
|
+
|
53
|
+
################################################################################
|
54
|
+
|
55
|
+
# Create corpora from the text files included with the repository.
|
56
|
+
# Exclude all lines which do not contain lowercase letters.
|
57
|
+
def make_db database, textfile, description
|
58
|
+
file = Poefy.root + '/data/' + textfile
|
59
|
+
input = File.readlines(file).keep_if { |i| i =~ /[a-z]/ }
|
60
|
+
poefy = Poefy::Poem.new database
|
61
|
+
poefy.make_database! input, description
|
62
|
+
poefy.close
|
63
|
+
end
|
64
|
+
|
65
|
+
[
|
66
|
+
[
|
67
|
+
'shakespeare',
|
68
|
+
'shakespeare_sonnets.txt',
|
69
|
+
"Shakespeare's sonnets"
|
70
|
+
],[
|
71
|
+
'therese',
|
72
|
+
'st_therese_of_lisieux.txt',
|
73
|
+
"St. Thérèse of Lisieux"
|
74
|
+
],[
|
75
|
+
'whitman',
|
76
|
+
'whitman_leaves.txt',
|
77
|
+
"Walt Whitman, Leaves of Grass"
|
78
|
+
],[
|
79
|
+
'dickinson',
|
80
|
+
'emily_dickinson.txt',
|
81
|
+
"Emily Dickinson"
|
82
|
+
],[
|
83
|
+
'spoke',
|
84
|
+
'english_as_she_is_spoke.txt',
|
85
|
+
"English As She Is Spoke"
|
86
|
+
]
|
87
|
+
].each do |i|
|
88
|
+
make_db(*i)
|
89
|
+
end
|
90
|
+
|
91
|
+
################################################################################
|