Add parts of speech model and database ingest rake task

This commit is contained in:
maddiebaka
2023-10-12 20:02:10 -04:00
parent b58f54943b
commit 6f46b1be7c
3 changed files with 52 additions and 0 deletions

21
lib/tasks/database.rake Normal file
View File

@@ -0,0 +1,21 @@
namespace :database do
desc "TODO"
task ingest: :environment do
ingest_data
end
end
def ingest_data
if PartOfSpeech.count > 0
puts "Data already exists in table! Aborting."
return
end
parts_of_speech = JSON.parse(File.read('db/dataset_en/toki-partsofspeech.json'))
parts_of_speech.each do |pos|
PartOfSpeech.create(pos: pos['pos'], definition: pos['definition'])
end
puts "Ingest complete."
end