Add parts of speech model and database ingest rake task
This commit is contained in:
		
							
								
								
									
										21
									
								
								lib/tasks/database.rake
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								lib/tasks/database.rake
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user