在关系数据库中存储不同类型的问题和答案
我有三种类型的问题:
- 词汇(由
question:answer
对表示) - 语法(由
question:[list, of,answers]
表示) - 听力(由
>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:
- Vocab (represented by
question:answer
pairs) - Grammar (represented by
question:[list, of, answers]
) - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.