Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: Tim MeagherHi,
You're exactly right with this being around initialization of the fields.
It's essentially setting up the way that data will be output and the mappings that will take place in all of the subsequent "do output" statements (unless explicitly overriden in a do output iteration).
I'm not sure what version of the software you are using, but in the latest release (LAE 5.1) the brainscript help for the "do output" statement has been updated to hopefully clarify this a little.
From the 5.1 brainscript help for "do output":
Used to configure output for a node which is not necessarily based on the input. The statements contained within the do output block will control what is sent to the given output.
Requirements:
- The output on which the do output block operates must have already been defined within the script (using the output operator)
- The do output cannot specify an output name - only an output number
- All of the fields which are to be output must have been defined via emit statements in the original output statement - no new fields can be defined in the do output block
- Only specifically named fields can be used within an emit statement in the do output block - emit pattern, emit * etc cannot be used
For any fields or variables which are to be sent to the output for each iteration in the do output statement, these can all simply be configured within the output definition. Then, within the do output statement, only the fields which are modified on each iteration need to be configured in the do output statement. In practice, the output statement will generally be constructed with a "where false" option, such that the definition is only defined in the output statement. The records are then only written on each execution of the do output statement.
Example:
#In the following example, the output is defined to pass through all of the input fields,
#along with a "RecordNum" field.
#The do output statement then specifies that "outputCount" records are to be written - where outputCount is a field on the input.
#If outputCount is less than equal to zero, no records will be output.
#Otherwise, for a given input record, "outputRecord" records will be written.
#Define the output - required prior to using do output
output 1 {
#Pass through all of the input fields
emit *
#Additionally define an output field "RecordNum"
#but don't actually write the records here
emit null.int() as "RecordNum"
where false
}
#Now, loop through 'outputCount' times
i = 0
while (i < 'outputCount') {
#Each time, define to write a record to output 1
do output 1 {
#Write the iteration count as the "RecordNum" field
emit i as "RecordNum"
}
i = i + 1
}
#In this example, the output statement is defined using the output name ("Data")
#However the do output statement still operates on the output number.
#In this example, assume there is an output "Data" which is the second node output
#Define the output - required prior to using do output
output "Data" {
#Pass through all of the input fields
emit *
#Additionally define an output field "RecordNum"
#but don't actually write the records here
emit null.int() as "RecordNum"
where false
}
#Now, loop through 'outputCount' times
i = 0
while (i < 'outputCount') {
#Each time, define to write a record to output 2 ("Data")
do output 2 {
#Write the iteration count as the "RecordNum" field
emit i as "RecordNum"
}
i = i + 1
}