File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -60,4 +60,26 @@ namespace :citations do
60
60
end
61
61
end
62
62
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
63
85
end
You can’t perform that action at this time.
0 commit comments