Add dictionary ingest and view

Dictionary json ingest to database, view populated with database contents
This commit is contained in:
maddiebaka
2023-10-12 22:24:31 -04:00
parent 6f2e074a0a
commit f5e9f3699f
8 changed files with 90 additions and 6 deletions

View File

@@ -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