scope-chain.taq

$ java -jar taq.jar scope-chain

Running query item_query in global scope 
item(
 mug,
 charge_plus_tax(de_DE, Gesamtkosten 14.567,89 EUR, 18% Steuer)
 charge_plus_tax(fr_FR, le total 14 197,52 EUR, 15% impôt)
 charge_plus_tax(fr_BE, le total 13 703,69 EUR, 11% impôt)
 charge_plus_tax(nl_BE, totale kosten 13.703,69 EUR, 11% belasting)
)
item(
 cap,
 charge_plus_tax(de_DE, Gesamtkosten 10.735,65 EUR, 18% Steuer)
 charge_plus_tax(fr_FR, le total 10 462,71 EUR, 15% impôt)
 charge_plus_tax(fr_BE, le total 10 098,79 EUR, 11% impôt)
 charge_plus_tax(nl_BE, totale kosten 10.098,79 EUR, 11% belasting)
)
item(
 t-shirt,
 charge_plus_tax(de_DE, Gesamtkosten 659,61 EUR, 18% Steuer)
 charge_plus_tax(fr_FR, le total 642,84 EUR, 15% impôt)
 charge_plus_tax(fr_BE, le total 620,48 EUR, 11% impôt)
 charge_plus_tax(nl_BE, totale kosten 620,48 EUR, 11% belasting)
)

Description

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.

There are 4 european scopes declared and the “item_query” query invokes the “charge_plus_tax” template for each one. A final “item” template collects each solution axiom using a variable with a qualified template name, which is a 2-part name with an at @ symbol placed in front

term @german.charge_plus_tax


$ list<term> locale

scope german (language="de", region="DE")
{
axiom locale
( tax_rate, Total, Tax )
{ 0.18, "Gesamtkosten", "Steuer" }
}

scope french (language="fr", region="FR")
{
axiom locale
( tax_rate, Total, Tax )
{ 0.15, "le total", "impôt" }
}

scope belgium_fr (language="fr", region="BE")
{
axiom locale
( tax_rate, Total, Tax )
{ 0.11, "le total", "impôt" }
}

scope belgium_nl (language="nl", region="BE")
{
axiom locale
( tax_rate, Total, Tax )
{ 0.11, "totale kosten", "belasting" }
}

include "locales/item-list.xpl"

template item_amount(string item, string amount)

template charge_plus_tax
{
double percent,
string item,
currency amount,
currency total_amount
}
(
percent = locale->tax_rate * 100,
total_amount = amount * 1.0 + locale->tax_rate),
term scope.locale,
term locale->Total + " " + total_amount.format),
term percent.format) + "% " + locale->Tax
)

flow item
(
term item_amount.item,
term @german.charge_plus_tax,
term @french.charge_plus_tax,
term @belgium_fr.charge_plus_tax,
term @belgium_nl.charge_plus_tax
)

query<axiom> item_query
(stock : item_amount)
->
(german.charge_plus_tax) ->
(french.charge_plus_tax) ->
(belgium_fr.charge_plus_tax) ->
(belgium_nl.charge_plus_tax) ->
(item)