-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
90 lines (80 loc) · 2.08 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'rake/testtask'
require 'nbayes'
require 'pry'
require 'csv'
require 'smarter_csv'
require 'parallel'
require_relative './lib/process_lexicon.rb'
require_relative './lib/dbconnect.rb'
task :default => [:test]
def db_name
# puts "Enter the database name: "
# answer = STDIN.gets.chomp
ENV['TEXT_ANALYZER_ACCURACY_DATABASE']
end
def set_db
DBConnect.new(db_name)
end
desc 'Initial insertion of data into local PostgreSQL database.'
task :create_lexicon do
db = set_db
if db.connect && (db.token_count < 1 && db.category_count < 1)
CreateLexicon.new(db_name)
else
puts "Lexicon already created."
end
end
desc 'Stats of current text-analyzer database.'
task :stats do
db = set_db
puts <<~STATS
Distinct Tokens: #{db.distinct_token_count}
Token Count: #{db.token_count}
Category Count: #{db.category_count}
User Entry Count: #{db.user_entry_count}
STATS
end
desc 'Pass a single filename ("/path/to/file") to add to the lexicon database.'
task :insert_tokenfile do
argument = ARGV[1..ARGV.length - 1]
if argument.length < 1
puts "Please pass a filename argument."
elsif argument.length == 2
if argument[0].class != String
puts "Argument must be a string"
elsif File.exist?(argument[0])
if argument[1]
AddFileToLexicon.new(argument[0], db_name, argument[1].to_i)
else
AddFileToLexicon.new(argument[0], db_name)
end
else
puts "File does not exist."
end
else
puts "Command only takes one filename argument."
end
end
desc 'Adds minimum tokens to database.'
task :add_minimum_tokens do
AddMinimumTokens.new(db_name)
end
desc 'Deletes current tokens and re-adds them to database.'
task :reinsert_minimum_tokens do
db = set_db
db.delete_all_tokens
CreateLexicon.new(db_name)
end
desc 'Creates and/or updates the token_stats database table'
task :token_stats_table do
db = set_db
db.create_token_stats
db.insert_token_stats
end
desc 'Run tests.'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/*_test.rb']
t.warning = false
end