Skip to content

Commit 568b3d2

Browse files
Rake task to import labels for citations
1 parent ddc2398 commit 568b3d2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/tasks/citation.rake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,26 @@ namespace :citations do
6060
end
6161
end
6262
end
63+
64+
# The import task is used to ingest labels for use by the citation scoring
65+
# process. This process will overwrite any existing labels for records in the
66+
# provided CSV file.
67+
#
68+
# This is meant to be used to load local data only.
69+
desc 'Import labels for citations'
70+
task :import, %i[path] => :environment do |_task, args|
71+
raise ArgumentError.new, 'Path is required' if args.path.blank?
72+
73+
# Again, this task is only meant for local data.
74+
data = File.read(args.path)
75+
76+
CSV.parse(data, headers: true) do |row|
77+
Rails.logger.info("Parsing new row for term #{row['TermID']}, label: #{row['Label']}")
78+
term = Term.find_by(id: row['TermID'])
79+
80+
term.label = row['Label']
81+
82+
term.save
83+
end
84+
end
6385
end

0 commit comments

Comments
 (0)