45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| namespace :dataset do
 | |
|   desc "TODO"
 | |
|   task ingest: :environment do
 | |
|     ingest_pos
 | |
|     ingest_dictionary
 | |
|     puts "Ingest complete."
 | |
|   end
 | |
| 
 | |
| end
 | |
| 
 | |
| def ingest_pos
 | |
|   if PartOfSpeech.count > 0
 | |
|     puts "Parts of speech 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 "Parts of speech ingest complete."
 | |
| end
 | |
| 
 | |
| def ingest_dictionary
 | |
|   if Word.count > 0
 | |
|     puts "Dictionary data already exists in table! Aborting."
 | |
|     return
 | |
|   end
 | |
| 
 | |
|   dictionary = JSON.parse(File.read('db/dataset_en/toki-dictionary.json'))
 | |
| 
 | |
|   dictionary.each do |entry|
 | |
|     if entry['word'] == "a"
 | |
|       puts entry
 | |
|     end
 | |
|     word = Word.create(word: entry['word'])
 | |
| 
 | |
|     entry['definitions'].each do |definition|
 | |
|       word.definitions.create(pos: definition['pos'], definition: definition['definition'])
 | |
|     end
 | |
|   end
 | |
|   puts "Dictionary ingest complete."
 | |
| end
 |