Rules as Code Demo with SWISH and s(CASP)

I just finished a demo of doing Rules as Code inside SWISH using the SWI-Prolog reimplementation of s(CASP). SWISH – r34v2.swinb (swi-prolog.org)

The first half is the encoding itself. The second half is a series of queries that can be run interactively inside the document to demonstrate different things that you can do with the encoding.

It demonstrates:

  • literate programming (statute and other explanations interspersed with code)
  • structural isomorphism (small pieces of law correspond to small pieces of code)
  • the LPDAT approach to defeasibility (oppose/4,override/4, according_to/2)
  • answering specific queries about specific fact scenarios
  • answering specific queries with incomplete inputs
  • generating natural-language explanations for answers
  • the ability to pose questions about negatives and get explanations for them
  • analyzing the contents of different stable models to understand whether you need more information to answer the question, or not
  • using the number of models returned as a means of “debugging” your code or your legislation
  • running queries with no facts at all, as a means of analyzing the code or the legislation
  • how s(CASP) returns models with constraints attached to the variables

If you have any feedback on it, I’d love to hear from you.