Add dictionary ingest and view
Dictionary json ingest to database, view populated with database contents
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
namespace :dataset do
|
||||
desc "TODO"
|
||||
task ingest: :environment do
|
||||
ingest_data
|
||||
ingest_pos
|
||||
ingest_dictionary
|
||||
puts "Ingest complete."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def ingest_data
|
||||
def ingest_pos
|
||||
if PartOfSpeech.count > 0
|
||||
puts "Data already exists in table! Aborting."
|
||||
puts "Parts of speech data already exists in table! Aborting."
|
||||
return
|
||||
end
|
||||
|
||||
@@ -17,5 +19,26 @@ def ingest_data
|
||||
parts_of_speech.each do |pos|
|
||||
PartOfSpeech.create(pos: pos['pos'], definition: pos['definition'])
|
||||
end
|
||||
puts "Ingest complete."
|
||||
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
|
||||
|
Reference in New Issue
Block a user