function-service-items.taq

$ java -jar taq.jar function-service-items

Running query scan_service_items in global scope 
charges(Service=83057, Amount=USD60.00)
charges(Service=10800, Amount=USD30.00)
charges(Service=10661, Amount=USD45.00)
charges(Service=78587, Amount=USD15.00)
charges(Service=99585, Amount=USD10.00)
charges(Service=99900, Amount=USD5.00)
accumulator(total=165.00)

Description

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.

$ template<term> service_amount (string service, string amount)

Note how the provider is declared is in the “service’ scope and the provider Java class is specified as a”provider” scope parameter.

scope service(provider = “service.ServiceProvider”) {

axiom<service_amount> function amount(string item)

}


$ template<term> service_amount (string service, string amount)

scope service(provider = "service.ServiceProvider") {
function axiom<service_amount> amount(string item)
}

export axiom accumulator(total) { 0.0 }

flow scan_items
{
export list<axiom> charges,
list<term> summary = list accumulator,
cursor<string> item
}
(
{
? fact item,
axiom survice_amount =
service.amount(item++),
currency.USD amount =
survice_amount
->amount,
summary->total += amount,
charges += axiom {
Service = survice_amount->service,
Amount = amount.format() }
}
)

query scan_service_items(items : scan_items)

list<string> account_info =
{
"Service #83057 $60.00",
"Service #10800 $30.00",
"Service #10661 $45.00",
"Service #78587 $15.00",
"Service #99585 $10.00",
"Service #99900 $5.00"
}
axiom items(item) { list account_info }