在关系数据库中存储不同类型的问题和答案

发布于 2025-01-01 07:59:44 字数 875 浏览 0 评论 0原文

我有三种类型的问题:

  1. 词汇(由 question:answer 对表示)
  2. 语法(由 question:[list, of,answers] 表示)
  3. 听力(由 >question:answer --其中值是 .oog/.wav 音频文件)。

我在这里避免使用术语key:value,因为我不确定字典是否可以存储音频。

我的问题:

如何将这组表建模为易于管理的设计?

languages         lessons        lesson_types
=========         ========       ============
lang_id           lesson_id      lt_id
lang_name         lang_id        lt_name
                  lesson_name    lt_desc
                  lt_id

这就是简单的部分。

我无法理解的部分是如何在 python 中序列化不同类型的对象以克服每种类型问题提出的差异。在严格的、仅限 DBMS 的方法中,我将为每种类型的问题使用单独的表(因为 BLOB 保存音频,语法问题可以有多达十几个部分来描述其时态、性别等)。我很高兴看到 sqlalchemy 在简化数据库结构方面能够发挥什么作用。

如何设计一个可以处理字典以及可序列化、sqlite3 友好的音频格式的 questions 表?

I have three types of questions:

  1. Vocab (represented by question:answer pairs)
  2. Grammar (represented by question:[list, of, answers])
  3. Listening (represented by question:answer --where value is an .oog/.wav audio file).

I avoided the term key:value here since I'm not sure dictionaries can store audio.

My question:

How can I model this set of tables into a manageable design?

languages         lessons        lesson_types
=========         ========       ============
lang_id           lesson_id      lt_id
lang_name         lang_id        lt_name
                  lesson_name    lt_desc
                  lt_id

And that's the simple part.

The part I am having trouble understanding is how I can serialize different types of objects in python to overcome the differences each type of question proposes. In a strict, DBMS-only approach, I would use a separate table for each type of question (since BLOBs hold audio, grammar questions can have upwards to a dozen parts to describe its tense, gender, etc). I'm excited to see what sqlalchemy is able to do in terms of simplifying a database's structure.

How can I go about designing a questions table that can handle dictionaries as well as serializable, sqlite3-friendly audio formats?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2025-01-08 07:59:44

Questions 表 (question_id, Question_text)、Answers 表 (question id,answer_text) 和 Audio_Answers 表 (question_id, audio_blob) 有什么问题代码>? (即:每个答案行包含一个问题ID和一个答案。如果问题有多个答案,则该问题的答案表中将有多个条目。这以完全相同的方式应用于 Audio_Answers 表。)

这将允许您以最大的灵活性对所有三种类型的问题进行建模。具有单个或多个答案的问题可以以完全相同的方式处理。两个答案表保存所有答案,每行一个答案。

What's wrong with a table Questions (question_id, question_text), a table Answers (question id, answer_text), and a table Audio_Answers (question_id, audio_blob)? (That is: Each Answer row contains one question id, and one answer. Where a question has multiple answers, there will be multiple entries the answer table for that question. This applies in the exact same way to the Audio_Answers table.)

That would allow you to model all three types of question with maximum flexibility. questions with a single or multiple answers can be handled in the exact same way. The two answers tables hold all of the answers, one answer per row.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文