Add Language model and LanguageController

This commit is contained in:
maddiebaka
2023-10-24 23:47:01 -04:00
parent ed00e69a13
commit 206c4da31f
28 changed files with 298 additions and 18 deletions

View File

@@ -1,14 +1,24 @@
namespace :dataset do
desc "TODO"
task ingest: :environment do
ingest_pos
ingest_dictionary
english = create_english_lang
ingest_pos(english)
ingest_dictionary(english)
puts "Ingest complete."
end
end
def ingest_pos
def create_english_lang
if Language.count > 0
puts "Language English already exists! Skipping step."
return
end
return Language.create(name: "English")
end
def ingest_pos(language)
if PartOfSpeech.count > 0
puts "Parts of speech data already exists in table! Aborting."
return
@@ -17,12 +27,12 @@ def ingest_pos
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'])
PartOfSpeech.create(pos: pos['pos'], definition: pos['definition'], language_id: language.id)
end
puts "Parts of speech ingest complete."
end
def ingest_dictionary
def ingest_dictionary(language)
if Word.count > 0
puts "Dictionary data already exists in table! Aborting."
return
@@ -37,7 +47,7 @@ def ingest_dictionary
word = Word.create(word: entry['word'])
entry['definitions'].each do |definition|
word.definitions.create(pos: definition['pos'], definition: definition['definition'])
word.definitions.create(pos: definition['pos'], definition: definition['definition'], language_id: language.id)
end
end
puts "Dictionary ingest complete."