The BoaC Programming Guide - Output Aggregators

To generate output, BoaC provides a specific type called output types. Logically, an output variable can be thought of as a process running in the system that collects and aggregates data. When processing a single paper, BoaC code emits values which are sent to output variables. After all papers are processed (in parallel), the output variables aggregate the data and produces the final output of the query.

Output types specify an aggregator function to use. Users select from one of the predefined aggregators shown below. When defining aggregators users can specify one or more indices. If an aggregator contains indices, this is a grouping operation. All values sent to the output variable will be grouped by their indices and then each group will be aggregated.

Some aggregators also specify parameters. These allow controlling the aggregation, for example by setting limits on the output it generates.

AggregatorType
bottomoutput bottom [param] [indices] of T [weight T2]
A statistical sampling that records the bottom [param] number of elements, of type T.
collectionoutput collection [indices] of T
A collection of data points. No aggregation is performed and every value appears in the output.
maximumoutput maximum [param] [indices] of T [weight T2]
A precise sample of the [param] highest weighted elements, of type T.
meanoutput mean [indices] of T
An arithmetic mean of the data, of type T. Types supported currently are: int, float.
minimumoutput minimum [param] [indices] of T [weight T2]
A precise sample of the [param] lowest weighted elements, of type T.
setoutput set [param] [indices] of T
A set of the data, of type T. If [param] is specified, the set can have at most that many elements.
sumoutput sum [indices] of T
An arithmetic sum of the data, of type T. Types supported currently are: int, float.
topoutput top [param] [indices] of T [weight T2]
A statistical sampling that records the top [param] number of elements, of type T.

Parameters

Some aggregators are parameterized (look for [param] above). The syntax for parameters is to give parentheses with the parameter value inside. For example, the top aggregator requires a parameter to indicate how many values it should keep.

var: output top(10) of string weight int;

computes the top-10 values of type string, using integers as weights (see below for more description of weights).

Indices

Aggregators optionally take 1 or more indices. This allows grouping data sent to the aggregator and performing aggregation on each group. For example, if you wanted to compute the sum of something for each paper, you could add an index for the paper id:

var: output sum[string] of int;

The aggregator will group all values with the same index, and then perform aggregation (in this case sum) for each grouping. To use such an aggregator, you must specify the concrete value for each index when emitting values to the output variable:

var[input.id] << 1;

So in this case, the values 1 are being sent to the output variable. They will be grouped by each paper ID and then for each paper ID a separate aggregation is performed. In the final output, there will be 1 result per unique index.

Weights

Some aggregators support item weights. Aggregation is first done by taking values sent to the output variable, grouping by each unique value, and then summing their total weights. Then aggregation is performed based on that total weight. For example,

var: output top(10) of string weight int;

will take values of type string with associated integer weights. It will group by each unique string, sum the weights, and then take the 10 with the highest total weight.

Example 1 - Counting Features

Now we will provide a few examples, showing how to define and use output variables for a few sample tasks.

First consider a simple task: let's count how often a particular feature appears. For this we would want to use the sum aggregator to sum integer values:

var: output sum of int;

We can use this variable by emitting integer values to it:

var << 1;

The final result in the output will be a single integer value that adds all the integer values emitted to the variable, for all papers analyzed. Thus the output looks something like:

var[] = 28449

Note the name of the variable appears in the output. Also note the empty square brackets, indicating there were no indices used.

Example 2 - Grouping by Paper

Now instead let's assume we wanted to sum all values, but group them by each paper analyzed. For this we need to use an index (of type string):

var: output sum[string] of int;

To use this output variable, we again emit integers to it. However we also indicate what the index value is:

var[input.id] << 1;

In this case we used the paper ID to group values. The final output here will include one sum, per unique paper ID (indicated as the index):

..
var[001259ae6d9bfa9376894f61aa6b6c5f18be2177] = 1
var[00142f93c18b07350be89e96372d240372437ed9] = 1
var[0015023cc06b5362d332b3baf348d11567ca2fbb] = 1
var[0016983545c217458b711d5aaad5fba583d81171] = 1
..

Example 3 - Top-N

Finally, consider the case where you may want to find the top-N weighted elements, perhaps the top-10. You can define an output variable:

var: output top(10) of string weight int;

In this case, we are defining a variable that will produce the top-10 string values, based on the total weight seen for each unique value. To use the variable, we need to emit both a value and a weight:

var << "foo" weight 1;

The aggregator will group by all unique string values, then sum the weights, sort by total weight, and keep the top-10 based on highest total weight. The output will contain 10 entries, with the value and their total weight listed:

var[] = Presatovir, 1.0
var[] = Remsdesivir, 1.0
var[] = Rolipram/oseltamivir, 1.0
var[] = Rupintrivir, 1.0
..