Template-Axiom-Query (TAQ)

Data Flow

Data flow expresses the concept of streaming data in and out of a system in order to extract information from one or possibly several sources. The incoming data may be incomplete, requiring validation or needing to be translated from one format to another. Possible operations that may be required are transformations, filtering, sorting and grouping. Here are three examples of data flow, the last being more complex than the first two.

Numbering, Filtering and Formating

asia_top_ten.taq selects the first 10 Asian cities from a list of 35 mega cities. The cities are numbered from 1 to 10 and the population numbers are formated according to the system locale. This is a sample of an incoming datum:

7,"Beijing","China","Asia",21650000

The first value is a rank out of 35, followed by city, country, continent and population. This is the program:

include "mega_city.taq"

template asia_top_ten
{ integer rank }
(
rank ??
Continent == "Asia" && rank++ < 10,
term rank,
city = Megacity, country = Country, population = Population.format()
)

query<axiom> asia_top_ten (mega_city : asia_top_ten)

These are the first two cities of the solution:

asia_top_ten(1, city=Tokyo, country=Japan, population=37,900,000)
asia_top_ten(2, city=Delhi, country=India, population=26,580,000)...

We see the double question mark criterion used with a non-trivial boolean expression that not only filters cities, but increments the 'rank' variable too rank++.

Note that population value produced by the built-in format function will vary according to system locale.

Grouping

Grouping is arranging items into categories. A minimal coding approach is to do a 2-step cascading query, with the first step selecting from a list of categories, and the second step creating an item record. This approach is used in grouping.taq which groups cities by continent.

include "mega_city.taq"

axiom list continents(continent)
{ "Asia" }
{ "Africa" }
{ "Europe" }
{ "South America" }
{ "North America" }

template group
(
continent
)

template group_by_continent
{ integer Population }
(
continent ? Continent,
city = Megacity,
country = Country,
rank = Rank,
population = Population.format()
)

query<axiom> mega_cities_by_continent
(
continents : group,
mega_city : group_by_continent
)

Note there are more efficient approaches to grouping which will be covered later in the reference.