postgresqlpython-2.7database-schemadjango-1.9

What is the best data structure to store chunks of a text that can be conditionally shown as part of a text file?


Let's set up the scenario. This is a text file:

INTRODUCTION

Paragraph 01
Paragraph 02
Paragraph 03

SECTION XXXXXX

Paragraph 01
Paragraph 02

SECTION YYYYYY

Paragraph 01

SECTION ZZZZZZ

Paragraph 01
Paragraph 02
Paragraph 03

Each paragraph can contain more paragraphs inside, but let's keep things simple.

We want to programatically build text files like those by following simple rules:

The type of texts to be built are terms of use, privacy policy, etc. As simplification, legal texts containing more or less content based on web form responses.

EDIT: The text is generated separately from the forms. We only have the responses.

So, my approach is to store the chunks of text (paragraphs) as columns of a database. Each column along with:

As we can have one or more conditions to evaluate to determine if a chunk of text will be included or not in the final text, I'm not sure about what kind of data structure to use.

Relational database? The number of columns would be dynamic, due to the existence of an initially unlimited number of conditions to be evaluated in each case.

NoSQL database?, storing the structure as a JSON, containing text + array of conditions?

Any other approach?


Solution

  • I solved the problem with a different approach.

    We build the text file in the frontend, by drag&dropping 2 types of widgets into a canvas (representing the content of the text file):

    Then we compile the full text, also in the frontend.

    So, the backend just stores chunks of text. No need to translate conditional logic to database. It even sounds silly now...