从文档到关系数据库的数据转换

Data conversion from document to relational database

我正在尝试将一些法律文本转换为关系表。我已经用尽了所有在线资源,这就是为什么我决定问这个问题,因为我对下一步该做什么一无所知。

我有一个句子保存到数据库中,它遵循以下结构:

标题 -> 章节 -> 文章 -> 小节 -> 小节 -> 句子

问题是句子可以在任何地方,而且结构中的任何项目都不必有 parent:

Ex1:
Title 1
   sentence 1
   sentence 2
   sentence 3
   Chapter 1
       sentence 4
   Chapter 2
       Article 1
           sentence 5
           Section 1
               Subsection 1
                   sentence 6

Ex2:
Article 1
   sentence 7
   sentence 8
   Section 1
       sentence 9
       sentence 10

当前的案例是面向文档的数据模型比关系模型更适合的一个很好的例子。但是,您始终可以将任何层次数据库模式映射到关系数据库模式。例如。

item_types
----------
id  name
--- ----------
1   Title
2   Chapter
3   Article
4   Section
5   Subsection
6   Sentence

textes
------
id  name
--- -----------
1   Test text 1
2   Test text 2

text_structure (Key: text_id + item_index)
--------------
text_id  item_index parent_index item_type content
-------  ---------- ------------ --------- ------------
1        1          NULL         1         Title 1
1        2          1            6         sentence 1
1        3          1            6         sentence 2
1        4          1            6         sentence 3
1        5          1            2         Chapter 1
1        6          5            6         sentence 4
...
2        1          NULL         3         Article 1
2        2          1            6         sentence 7
2        3          1            6         sentence 8
2        4          1            4         Section 1
2        5          4            6         sentence 9
2        6          4            6         sentence 10