A resource is a binding to an external data supplier and/or consumer. Data is exchanged using Axioms. Resources should be declared at the beginning of an TAQ program to make them stand out.
Basic Format
A basic resource declaration starts with the keyword resource followed by the name of the resource and then one or two role qualifiers, enclosed in braces. Role qualifiers define the resource as a data source or a data consumer, or both (a bi-directional resource).
dictionary.taq has a dual role resource reads words from a dictionary file and writes the solution to the console. This is the "lexicon" resource declared to provide an axiom source named "dictionary" with term names "word" and "definition", a nd consume the output of a template named "in_words"
{
template in_words
The "axiom" role qualifier has the format of an axiom header and indicates the resource is a data source . The "template" role qualifier indicates the resource is also a data consumer. It names the "in_words" template as the data source to which the resource will connect.
The lexicon resource reads a text file named "i-words.taq" where each line contains a word beginning with the letter 'i' and a definition. Each line is translated to "dictionary" axiom. The "query_in_words" query, by means of the "in_words" template generates a solution axiom for each word beginning with "in" which the lexicon resource translates to a line of text written to the console.
System Format
Each resource provider has a system name used to select it out of all available providers. The resource name of the basic format doubles as the system name. The system format extends the basic format by adding a system name and optional properties. The system name appears in quotes following the resource name and separated by a ':' colon. The properties, if included, are a comma-delimited set of key=value pairs enclosed in parentheses.
Scope Example
The following example consists of of 2 programs. The first one is foreign-lexicon2.taq. This has 2 country scopes, one trench and the other german. In each scope a resource is declared with a role to write to disk a names for colors aqua, black, blue and white in the scope language
{ template german.colors }
resource french_colors : "xstream" ( filename="FR")
{ template french.colors }
Here we see a system name "xstream" used for both resources as they share the same provider. Also, a 2-part name is given the template in each role to place it in a specific scope. However, the "colors" template referred to in the role is not defined in the program. This is not an oversight as the compiler automatically creates one in it's absence using the query axiom source as the archetype. In this case, the axiom header names are (aqua, black, blue, white). Here are the axioms that feed the query and the "color_query" query
query color_query (german.colors:german.colors) ->
The second program is foreign-colors2.taq. This features a context list named "colors"
This list is implemented by resource roles. There is one role placed in the french scope and the other in the german scope
{ axiom german.colors(aqua, black, blue, white) }
resource french_colors : "xstream" ( filename="FR")
{ axiom french.colors(aqua, black, blue, white) }
The "color" select is declared with a first header name of "colors" to bind it to the context list and this enables translation of color names from foreign languages to English. Here is the solution to the "german.color_query" query for color name "Wasser" which is "aqua" in English
color_query(name=Wasser, red=0, green=255, blue=255)
Resource Cursor
A resource cursor can be declared in a flow body in order to access a resource one record at a time. The postfix '++' increment operator is used to progress through the resource content. dictionary2.taq demonstrates accessing a "lexicon" resource using a resource cursor.
Object Method Examples
The resource provider reads a dictionary file containing words beginning with "i" and selects words starting with characters input as property named "filter". The program selects words starting with "in" followed by "im".
The reason for doing 2 separate searches is to demonstrate resource object methods. These are used to delay opening the dictionary file until the filter property has been set. The program demonstrates that the resource cursor keeps in sync with the resource as it is opened and closed using object methods.
Declaration auto()
The "lexicon" resource declaration has a body so normal automatic resource open can be suppressed.
{
(
Scanning Dictionary File
In the following flow sequence, the lexicon search characters are configured, the resource is opened and the cursor loops providing hits until the end of the file is reached, at which point, the resource is closed.
lexicon.open(),
list<term> item,
{ ?? (item = words++)