high_cities.taq demonstrates a simple TAQ query as an introduction to the TAQ language. The goal of a query is to take the facts input to it and apply logic to arrive at new facts. A fact is packaged in a structure called an "axiom" and new facts are manufactured in a structure called a "template".
continent-scopes.taq shows how an identifier can refer to a specific scope by creating a 2-part name where the first part is the scope name. Here there are 2 scopes representing continents "Asia" and "Europe" and 2 scope-specific queries - asia_megacities and euro_megacities. The difference between the two queries is how they refer to the "megacities" template - "Asia.megacities" and "Europe.megacities" respectively.
continent-scopes2.taq illustrates address identifiers where an '@' symbol is used to signify the scope part of the identifier. The only change from the original program is to use addresses in the query declarations.
customer-charge.taq demonstrates a cascading query used to aggregate data from 2 different tables organized as axiom lists. The first, named "shipping", contains freight charged for delivery to a particular city and the second, named "customer", contains customer details. The "customer_delivery" query returns for each customer, name, city, and freight charge.
logic-chain.taq demonstrates a chained query used to aggregate data from 3 different tables organized as axiom lists. The "greek_business" query consists of 3 stages which do the following operations in turn
To chain a query stage, link it to the preceding stages using a `->` right arrow.
high_cities2.taq demonstrates query parameterization..The "high_cities" query returns a list of cities which are above 5,000 feet elevation. The height threshold is set as a query parameter appended to the query declaration.
types.taq shows the result of unifying a template containing 6 untyped variables with an axiom containing literal terms of 6 different types. The "types" query returns a single axiom with terms that reflect the original literal values.
high_cities3.taq demonstrates how to pass anonymous terms to the solution. This is achieved using the term keyword which has the effect of making the term both anonymous and non-private,
euro_cities.taq demonstrates using a period '.' to prevent a term being passed to the solution. It is placed at the start of the line.
american_megacities.taq demonstrates a logic selection set. which contains one or more comma-delimited items to match on and enclosed in `{}` braces. The "american_megacities" template selects cities in either of the North and South America continents
query_in_words.taq shows a regular expression used to select words starting with "in" from a dictionary of words starting with "i". The first term of the "in_words" template performs the selection logic and has the form of a function with 2 parameters. The function name is regex and the first parameter is a variable containing the text to match on and the second parameter is the actual regular expression
multi-currency.taq shows the capability for TAQ to deal with amounts in various currencies. The "price_query" query imports file "world_currency.taq" which declares an axiom list with each axiom containing a 2-character country code and an amount expressed in the country's decimal format.
expressions.taq performs a sequence of arithmetic operations to demonstrate that TAQ follows Java notation and precedence in regard to those operations.
scope-cycles.taq demonstrates how variables declared in a scope behave from one query to the next. It shows scopes are initialized in the order they are declared. It also shows that scope variables are independent of template unification/evaluation cycles except when deliberately updated.
declarations.taq reveals important details about variable declarations made in what is called the "template scope". This is optionally placed before the template body. enclosed in `{}` braces and contains declarations that are private to the template. One important reason for privacy may be to prevent input data being relayed to the template solution.
asia_top_ten.taq provides an example of filtering data according to a couple of conditions. In this case we are selecting the ten top Asian cities from a list of 30 highly populated cities from 5 continents. The list is already sorted by population size, so this makes getting the top 10 cities simply a matter of selecting the first 10 cities.
grouping.taq shows a simple way to sort data into categories, otherwise known as "grouping". The categories here are defined in the "continents" axiom list and the order of the continents in this list is reflected in the query solution.
more_agriculture.taq demonstrates numerical analysis of data. The 'more_agriculture' query produces a list of countries which have increased the area under agriculture by more than 1% over the twenty years between 1990 and 2010.
The query is performed in 2 stages. The first stage filters countries which meet the surface area increase criteria. This stage is chained to the second stage which converts the percentage increase to surface area.
personalities.taq demonstrates that a term can refer to a list. In this case, the list is a set of personality traits associated with a person's zodiac sign. Hence there are 12 trait lists. A list is referenced in an axiom declaration using the list keyword.
lists.taq declares, and references by index, all the list types:
integer, double, boolean, string, decimal, axiom, term
assign-marks.taq shows a list being created with 18 items and has an index range of 1 to 18 instead of 0 to 17. The list is also initialized in reverse as it is intuitive that alpha grades appear in descending order.
sale-items.taq demonstrates growing a list by appending items to it. The "format_stock" query produces a text list with each item containing information originating from a "stock" axiom list
personalities2.taq introduces cursor which steps through a list going forward from the start or working backwards from the end. Here a cursor is bound to a list simply by declaring it with the same name as the list.
black-is-white.taq shows the various ways to access an axiom in order to update term values. In this example color "black" is turned to "white" The color is specified by both name and red-green-blue components.
gaming.taq demonstrates dynamic axiom list initialization with parameters. In this case the parameters are 3 pseudo-generated random numbers to achieve an unpredictable result of every query.
high-cities-dynamic.taq demonstrates exporting an axiom list as a means to returning a query result. This approach allows the axiom list to be accessed while processing the query. It also provides a channel to output additional information from a query such as statistics. However, this example just shows how to export a list.
who-is-vaxxed.taq demonstrates a-template that provides a solution using only unification. There are three queries using this template, two of which provide a correct solution and one that returns an empty result. The question to be answered is what determines success or failure.
birds.taq throws the spotlight on the normally hidden role archetypes play in unifying axioms with templates. An archetype records the names and order of the participating terms, It allows axiom terms to be paired with template terms efficiently.
In this example, data on birds is segmented into categories "order", "family" and "species". This data is incomplete as not all attributes apply to any particular bird. A question mark is implemented as a special type of term called a "blank term". An archetype recognizes a blank term as a wild card match when paired with any other term.
convert_mi2.md demonstrates a branch applied to correct an inconsistency in the incoming data. The "convert_areas" query takes a list of British Commonwealth countries and their surface areas in a mix of metric and imperial units and creates a new list where they are all metric.
factorial.taq demonstrates a compact loop being used to calculate the factorial of numbers 4 and 5.
high-cities-sorted.taq shows a non-trivial loop with 2 exit criteria. The loop performs an insert sort on a list of cities so they are ordered by ascending altitude.
nested-loops.taq demonstrates a loop nested inside a loop. The aim is to sort a list of numbers into ascending order. As it is an insert sort being implemented, the outer loop feeds in the next number to be inserted and the inner loop does a shuffle to maintain the desired number ordering.
pet-names.taq contrasts a forward cursor to a reverse cursor. The "pets" query progresses in the forward direction and therefore the "pet" cursor increments.
A second "reverse_pets" query operates the cursor in reverse. The "pet" cursor decrements
currency-cursor.taq demonstrates a currency cursor assigned to the Euro currency locale designated by the country code "EUR". The query axiom source is a list named "euro_amounts". Values are presented in text format and the cursor converts each one to a currency type as it traverses the list.
high-cities-sorted2.taq shows a cursor working to perform an insertion sort, The "high_cities" query produces a list of high cities sorted by elevation. Notable is that an indexed cursor reference to a list is relative to the current cursor index and can be employed successfully even when the cursor has stepped beyond the end of the list.
empty-list.taq demonstrates that a cursor deals gracefully when assigned to an empty list. The cursor declaration is normal, but the "high_cities" axiom list to which it is assigned is not populated before a sequence of operations is performed.
proto-select.taq reveals the inner workings of the select operation. This example maps an account number to an account type.
dynamic-grouping.taq demonstrates grouping using a map operation to route each item to a specific group list. This allows the grouping to be completed in a single pass through the incoming collection.
bank-accounts.taq demonstrates both a map and a select operation. The select matches a numeric prefix to a bank name and branch. Unlike the map, the select is declared separately from where it is used.
color-swatch.taq demonstrates a final "everything else" default. color-swatch2.taq demonstrates execution on a branch if the selection result is not a fact.
stamp-duty.taq demonstrates a select default strategy where an execution step is skipped when none of the available choices match.
perfect-match.taq shows selection default strategy of simply skipping over items that fail to match any of the available choices.
types2.taq demonstrates a function declaration requesting a alternative return type from the default. Function system.timestamp() calls system library function timestamp() and normally it returns a Date object. The function declaration here puts the return type as string and this is supported.
function-service-items.taq demonstrates a function which returns a term list declared as a "service_amount" template archetype. This list contains a "service" term to identify the service and an "amount" term. Both values are extracted from a line of text passed to the function.
function-student-scores.taq demonstrates a function which returns an axiom list declared as an "alpha_grades" template archetype. Each axiom in this list has a "subject" term and a "mark" term. Both values are derived from an integer term with a subject name and in this example there are 3 subjects passed as function parameters - english, maths and history.
birds2.taq demonstrates a query made by a function call operation. The "waterfowl" query returns an axiom list containing distinguishing attributes of birds living in watery habitats. The "list_waterfowl" query calls the "waterfowl" query and converts each returned axiom into a list of strings skipping over blank terms representing attributes which are not relevant.
circum.taq demonstrates making a query to a template using a function call operation. The "x_by_factor" template belongs to the "math" scope and is designed to take 2 decimal numbers, multiply one by the other and return a decimal result in a term named "product". The template query has the format of a function call, The fact it performs a query is hidden. However, a template can only return a term list.
query-student-scores.taq demonstrates making a query to a flow using a function call operation. The "report" flow belongs to the "school" scope and is designed to take 3 integer numbers, convert each one into a subject + alpha mark axiom and return an axiom list result in a term named "subjects".
stamp-duty2.taq demonstrates a select receiver template used with a skip on default strategy. The "stamp_duty_query" query calculates the tax on a real estate purchase. There is a threshold below which a flat rate applies and no tax calculation is required.
birds3.taq demonstrates using a receiver to handle the value returned from a function call instead of assigning that value to a list variable. The receiver has a cursor with the same name as the function.
receive-student-scores.taq demonstrates a receiver template used with a function which returns an axiom list . The axiom list type is declared as an archetype declaration. receive-student-scores2.taq demonstrates how to pass an axiom list to a receiver template when the function only returns a term list.
receive-service-items.taq demonstrates a receiver template resolving the ambiguity of having the same name, "amount", for both the function being called and for one of the terms in the returned term list.
charge-plus-tax.taq demonstrates a select receiver template with a map nested inside. This produces a locale-specific invoice. A "district" select operation sets variable "region" and a receiver then maps "region" to "percent" sales tax.
calc-square-miles3.taq demonstrates usage of a scope property and how the absence of a property is handled.
foreign-total.taq demonstrates using a context list to perform language translation.
lists2.taq displays the contents and size of 7 context lists.
lists3.taq differs from lists2.taq only in that a cursor is used to access the each list.
foreign-colors.taq demonstrates using a context list to translate a selection value.
german-colors.taq streamlines the foreign colors example by collecting the axiom returned from selection operation instead of using selection variables.
show-locale.taq shows the name and locale attributes of 2 separate scopes.
euro-total.taq demonstrates locale scope attributes.
euro-total2.taq improves the first version using a context list and a cascading query
scope-chain.taq demonstrates a sequence of records being processed by a template in several scopes, This is achieved using a query chain where the final link aggregates the output from the preceding links.
group_in_words.taq shows a regular expression used to select words starting with "in" from a dictionary of words starting with "i". In addition, it uses grouping to extract the description from the dictionary definition.
service-items.taq demonstrates a regular expression pattern used to filter incoming items as well as extract text. Each item contains a service number prefixed with a '#' character, and in most cases, an amount. A missing amount indicates a free service. Using a regular expression combines data capture from eligible services with skipping over the ineligible services.
regex-pet-names.taq shows a cursor used in combination with a regular expression. It is critical that the cursor either increments or decrements when accessed by the regular expression or else an infinite loop is created when the first non-match occurs. Hence for query "pets" progressing in the forward direction, the "pet" cursor increments
A second "reverse_pets" query operates the cursor in reverse.
pets.taq demonstrates case-insensitive regular pattern matching. The "pet_query" query produces a list of statements containing the name of a dog and what color it is. The source is an XML document containing information on cats and dogs. As an extra challenge for text pattern matching, the species, dog or cat, appears in mixed case.
dictionary.taq demonstrates a bi-directional resource. The data source reads a file containing words starting with "i" and the data consumer sends the query result to the console. The "lexicon" resource is declared at the top of dictionary.taq and this is a requirement as it is referenced everywhere only by this name.
foreign-lexicon2.taq demonstrates a resource with a provider system name which is enclosed in quotes to allow any naming convention to be used. A system name is used here because the provider is named "xstream", a reference to the underlying technology which serializes objects to XML and back again, and there are two resources, both using the same provider - "german_colors" and "french_colors".
foreign-lexicon2.taq demonstrates a resource that consumes the files created by foreign-lexicon2.taq. It has the same provider system name as in foreign-lexicon2.taq. There are two resources "german_colors" and "french_colors" which each declare in a data source role qualifier, that the provider is an axiom source.
dictionary2.taq demonstrates operations a resource can perform. It also shows that a cursor can be bound to a resource and keep in sync as the resource is opened and closed. The "lexicon" resource declares a data source which reads a file containing words starting with "i". The "query_in_words" query uses the resource to select words starting with "in" and then "im".
towers-of-hanoi.taq demonstrates flow recursion and how to supply the initial parameters to start the recursion. The puzzle involves moving a stack of disks across three rods following some simple rules, the main one being that only one disc can be moved at a time.
sudoku.taq demonstrates numeric analysis of a 4x4 matrix to fill in the missing cells of a Sudoku puzzle. Two things stand out in this example
cities.taq creates the "cities" database required to run high-cities-sorted3.taq. The "cities" resource has a data-consumer role to write city records to the "cities" database.
high-cities-sorted3.taq demonstrates two database resources sharing an entity class used to define the database records. The "sort_cities" query takes a list of cities read from one database and writes to another database the high cities in order of ascending altitude. The database records are revealed by a separate "show-high-cities" program using a custom SQL resource provider. Each record id is shown to verify the sort took place.
perfect-match2.taq demonstrates a database resource data collector with an entity class used to define the database records. The "star_people" query creates a dating profile for each person in a database that is 20 years old and over.
agriculture-report.taq demonstrates two highly customized database resource providers. The 'more_agriculture' query produces a list of countries which have increased the area under agriculture by more than 1% over the twenty years between 1990 and 2010. The database records are revealed by a separate "show-agri20-year1" program using a custom SQL resource provider.
agriculture-report2.taq demonstrates a database resource provider which uses two entity classes to support a schema with two tables.