Expression Pattern Language (eXPL)

eXPL Queries

Queries are declared in eXPL and are executed by Java programs to find solutions expressed in eXPL.

Here is example of a simple eXPL query:

axiom charge()
{"Athens", 23 ),
{"Sparta", 13 ),
{"Milos", 17);

axiom customer()
{"Marathon Marble", "Sparta"}
{"Acropolis Construction", "Athens"}
{"Agora Imports", "Sparta"}
{"Spiros Theodolites", "Milos"};

template freight(city, charge);
template customer_freight(
  name,
  city ? city == freight.city,
  charge
);

query customer_charge(charge:freight, customer:customer_freight);

The tutorial2 GreekConstruction is a code example runs this query. When the query is run, the console output* is:

freight(city = Athens, charge = 23)
customer_freight(name = Acropolis., city = Athens, charge = 23)
freight(city = Sparta, charge = 13)
customer_freight(name = Marathon., city = Sparta, charge = 13)
freight(city = Sparta, charge = 13)
customer_freight(name = Agora., city = Sparta, charge = 13)
freight(city = Milos, charge = 17)
customer_freight(name = Spiros., city = Milos, charge = 17)

* customer names shown truncated

The "customer_charge" query is declared having 2 unify/evaluate steps which are described as axiom/template pairs:

(charge:freight, customer:customer_freight)

Axiom "charge" is paired to template "freight" and then axiom "customer" is paired to template "customer_freight". The query attempts unification exhaustively until all possible pairing combinations are tested. However, the results of a unification+evaluation step are preserved only if all templates in the query contain a complete solution. We see that the final solution consists of axioms, with each axiom a snapshot of a template captured after successful unification+evaluation.

The solution shows each "city" term of the "customer:customer_freight" unification is matched on the "city" term of a "charge:freight" unification. eg. when we hit freight(city = Sparta, charge = 13), then the two customers in Sparta are resolved. The "city" match is specified by the expression "city == freight.city". For more information on the use of variables in expressions, go to eXPL Expressions. Also note that customer_freight charge is set implicitly by unification. This is because the incoming template to a unification step is transformed to an axiom and passed down the query chain.

The above sample is the most elegant way to form the eXPL query, but sample NameGreekConstruction shows a slightly more verbose query that is more robust. Firstly the axiom terms are given names, so they can match template terms regardless of order. Secondly, the charge term in the customer_freight template is explicitly set to the term from the freight template.

axiom charge (city, charge)
{"Athens", 23 },
{"Sparta", 13 },
{"Milos", 17};

axiom customer (name, city)
{"Marathon Marble", "Sparta"},
{"Acropolis Construction", "Athens"},
{"Agora Imports", "Sparta"},
{"Spiros Theodolites", "Milos"};

// Terms reversed - so match by name
template freight(charge, city);
template customer_freight(
  name,
  city ? city == freight.city,
  charge = freight.charge
);

query customer_charge(charge:freight, customer:customer_freight);
Queries can be extended by chaining using the special << operator and one or more combinations of:
  • Logic chain query adds additional unification+evaluation step
  • Calculator processes information to shape the solution to meet specific requirements