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.
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
+ ################################################################################