Expertsystemen

 

Repeating text fragments

This section assumes you have done the guided tour and are familiar with both repeating and text fragments. It is also useful to take a look at model structure.

The model

When working on a model, it often occurs that you would like to add a list of items of a certain kind with a previously unknown length, for example a list of contact details of customers or an overview of all outstanding invoices of customers. In order to do this, you can make use of the loop-tag. The loop-tag makes sure that all the repeated iterations are returned and placed in the document you are creating. The use of the loop-tag will be illustrated by means of an example.

In this example, we will develop a model which asks the user to fill in the some information about your contact persons. You will be able to determine how many persons you want to fill in. The result is a list of contact persons in a Word-document.

The model we will be making exists of four nodes: introduction, information, document and final. The node information contains a sub graph gcontacts. In the sub graph gcontacts there is one node information.

creating the model
creating the model

Add a few questions to the node gcontacts.information, such as name, surname, age, email, and remarks. These questions will be repeated.

In the node information in the main graph, add a question that asks how many times the loop has to be run through. Then, add a loop to repeat the sub graph. The loop will make sure that the sub graph is repeated until the condition set in the loop is satisfied.

The last thing to do in the model, is to create a text fragment. The text fragment will be placed in the node gcontacts.information. Add the different variables that you have created in the node gcontacts.information to the text fragment. This can be done by using the finder (press [F6] to open the finder).

The main.information-node and actions-panel:

the node with the repeat
the node with the repeat

The gcontacts.information node and actions-panel:

the node with information
the node with information

The document

As the model has been created, is it time to put the text fragment in the word document. Simply drag-and-drop the text fragment on the right place. If you forgot how to add text fragments, take a look at adding text fragments. Note that if you would run your model now, it would only return the first iteration of the loop.

In order to get all iterations of the loop in the document, you use the loop-tag. The loop-tag has a begin-tag and an end-tag, <loop> and </loop>. These are placed in the document, ensuring that the text fragment containing the loop is enclosed.

The last thing to do is to add the name of the graph over which is looped to the begin-tag. In this case, the sub graph ‘gcontacts’ is the graph that is looped over. Thus, our document will look as follows:

The end-tag of the loop-tag has deliberately been put on the next line by an enter. This ensures that the different iterations of the loop will be put on a new line.

Looping in tables

If you want to loop your text fragments in a table, loop will not work. The structure of the table has to be preserved, so to make a table with loops, you will need to use rloop, which stands for rowloop. The usage is the same as a normal loop. Place the start (<rloop>) in the first column, and the end of the loop (</rloop>) in the last column of your table.

rloop in table
rloop in table

In the examples the graph was used to loop over the fragments. Loops can loop over graphs, datasets or text fragments. The <loop> will look as follows:

  • Graph: <loop graph="gmygraph"></loop>
  • Dataset: <loop dataset="mydataset"></loop>
  • Text fragments: <loop textfragment="myfragment"></loop>