sgo.to

Business Logic

This is an early exploration of enabling the composition of multiple origins's business logic using a controlled natural language (e.g. Attempto) and markdown.

In this exploration, the registry is responsible for storing the programs, aggregating them and exposing a querying interface. While aggregating programs, the registry is responsible for dealing with conflicting business logics. While exposing a querying interface, the registry is responsible for offering a performant data structure (e.g. indexes built offline).

Logic languages primarily operates on top of logic statements (more specifically, a subset of first order logic). Controlled natural languages are semantically and syntactically a controlled/constrained subset of a root natural language (in Attempto's case, english). In addition to the grammatical structure and the deduction/reasoning rules implied, the language should come with a predefined set of words that can be used, e.g. a dictionary. Here is an example of what that language may look like.

> This is just a completely totally fake example to give you an idea of what the
> This is a comment
> This is another comment
> This is an import statement.
# import “family.en”

> These are specific data entries that exposes data supporting the business logic
> below.
Sam is a brazilian engineer who works at Google.
Sam’s birthday is 05/02/1982.
Sam is married to Daniela.
Sam is the father of Leo and Anna.
Dani is the mother of Leo and Anna.
Leo’s birthday is 05/02/2013.
Anna’s birthday is 10/18/2016.

And here is what a “standard library” could look like:

> The following is the business logic: the general description of the description space.
> These would probably live in a common library that .en program would #import.

If X is a parent of Y then Y is a child of X.
If Y is a child of X then X is a parent of Y.
If X is a parent of Y and X is male then X is the father of Y.
If X is a parent of Y and X is female then X is the mother of Y.
If X is a parent of Y and X is a parent of Z then Y and Z are siblings.
If X is a sibling of Y and Y is male then Y is the brother of X
If X is a sibling of Y and Y is female then Y is the sister of X
If X is a brother of Y then X is a sibling of Y
If X is a sister of Y then X is a sibling of Y
If X is a sibling of Y then Y is a sibling of X
If X is a parent of Y and Z is a parent of X then Z is an ancestor of Y.
If X is a mother of Y then X is a parent of Y.
If X is a father of Y then X is a parent of Y.
If X is a sibling of Y and X’s birthday is the same as Y’s birthday then X is a twin sibling of Y
If X is a twin sibling of Y then Y is a twin sibling of X
If X is a parent of Y and Z is a parent of Y and A is a parent of B and C is a parent of B and Z is the same as C then X is a cousin of A
If X is a cousin of Y then Y is a cousin of X

The language should be deliberately un-opinionated about its host environment and should be designed such that exposing programs in one environment (e.g. browsers) complements others (e.g. search).

The language should be a data and business logic exchange layer, and should be deliberately un-opinionated about the presentation and interface with the user, leaving that responsibility to the host environment.

Search Engines

Exposing programs published on web pages enable search engines to operate on structured data / business logic.

For example, take asking a search engine for public transportation schedule, e.g. bart.gov. If bart.gov exposed something along the lines:

A train leaves Mountain View at 10am and arrives at Palo Alto at 10h15am

A train leaves Palo Alto at 10:15am and arrives at San Bruno at 10h30am

If train X departures city A at T1 and arrives at city B at T2 and train Y departures city B at T2 and arrives at city C at T3 then there is a train Z that departures city A at T1 and arrives at city C at T3

Enables a user to ask: “What’s the next train leaving Mountain View to San Bruno?”

And the system is able to answer: “A train leaves Mountain View at 10am and arrives at San Bruno at 10h30am‘

This is assuming that users will be entering queries in the programming language which is probably going to be too cumbersome to enforce. Given how far machine translation has evolved, it may be feasible (with enough examples derived from, say, WikiData -> English and english Wikipedia, or schema.org -> English and web pages) to translate automatically from natural language to controlled natural language.

The language should also not opinionated about how the programs are displayed to the user. For example, another possible host with clearly defined provenance boundaries are chat-like conversational interfaces.

Examples

Here are a few examples of programs that could be written for some verticals.

Restaurants

Cascal is a restaurant located in the city of Mountain-View.
  
Its opening hours are:

-   Weekdays from 6pm to 10pm
-   Weekends from 6pm to 12am

A restaurant is open on day X if  X is in its opening hours and

X is not a holiday and the restaurant closes on holidays.

A day X is a weekday if X is a Monday, Tuesday, Wednesday, Thursday or Friday.

A day X is a weekend if X is a Saturday or a Sunday.

A day X is a holiday if X is Xmas, Thanksgiving or NYE.

There is an available reservation [X](http://api.opentable.com/cascal/reservations?partysize=${P}&date=${D}&time=${T}) whose party size is [P] and whose date is [D] and time is [T].

Trains

A train leaves Mountain View at 10am and arrives in Palo Alto at 10h15am.

A train leaves Palo Alto at 10:15am and arrives in San Bruno at 10h30am.

If train X departures city A at T1 and arrives at city B at T2 and train Y departures city B at T2 and arrives at city C at T3 then there is a train Z that departures city A at T1 and arrives at city C at T3.

Reservations

There is a flight X.

X’s departure date is 12/18/2017.

X’s return date is 01/15/2018. X is a round-trip flight.

X’s departure location is SFO. X’s arrival location is GRU.

If there is no flight X whose departure date is closer than flight Y, then flight Y is the next flight.

People

> This is a comment
> This is another comment
> The following is the business logic: the general description of the description space.
> These would probably live in a common library that .en program would #import.

If X is a father of Y then Y is a child of X.

If X is a parent of Y and X is a parent of Z then Y and Z are siblings.

If X is a parent of Y and Z is a parent of X then Z is an ancestor of Y.

If X is a mother of Y then X is a parent of Y.

If X is a father of Y then X is a parent of Y.

> These are specific data entries that exposes data supporting the business logic
> above.

Sam is the father of Leo and Anna.
Dani is the mother of Leo and Anna.

Packages

Events

Orders

TODO

  • Some form of now() and/or here() construct
  • Some form of > comments
  • Some form of # imports
  • Some form of object tree construction
  • Some form of array construction
  • Some form of # header / sectioning
  • Some form of linking
  • Some form of sameAs, reconciliation mechanism
  • Some form of namespacing, modularization mechanism
  • Some form of embracement that business logic conflict as the intrinsic nature of composition (e.g. parent-child relationships should be configurable by the developer, schema should be controlled by the developer), micro-theories are built-in and part of the natural course of discourse
  • Some form of isolation mechanisms
  • Some form of personal information
  • Not all data is available in the client and some will have to be fetched from the server (e.g. Abstract nodes)

Related Work

  • ACE is clearly the closest work that matches both the form and the substance of this work.
  • RDF/OWL is probably second in terms of expressivity but something leads me to believe that it is different in that (a) it is harder to read, (b) doesn’t come with a dictionary of words. TODO(goto): try to write down examples of things we would want to accomplish with English and how they would be accomplished with RDF/OWL. It is still largely TBD to me if English will be more or less ergonomic to write things down, so this is probably where we should compare and contrast the most.
  • schema.org and JSON-LD are similar but less expressive in terms of the logical relationships TODO(goto): check if this is actually the case. For example, can one say “If X is a parent of Y and X is a parent of Z then Y and Z are siblings”?