Another Rules as Code example from ICAIL 2019

Jason Morris
6 min readJun 21, 2019

A short while ago I wrote a post about how you can use AustLII’s DataLex to take legislation and turn it into code.

This week I’m attending the International Conference on Artificial Intelligence and Law (ICAIL 2019) at the University of Montreal Cyberjustice Lab. As I type, I’m in a tutorial session discussing a new open-source tool for Rules as Code, called NAI.

Encoding The Law

I decided to re-implement the same code from the previous post in order to see the differences. As you might recall, it was section 2 of Alberta’s Mental Health Act, and reads as follows:

Admission certificate

2 When a physician examines a person and is of the opinion that the person is

(a) suffering from mental disorder,

(b) likely to cause harm to the person or others or to suffer substantial mental or physical deterioration or serious physical impairment, and

(c) unsuitable for admission to a facility other than as a formal patient,

the physician may, not later than 24 hours after the examination, issue an admission certificate in the prescribed form with respect to the person.

In NAI, you set out the law and the questions you want to ask in different contexts. To set out the law, you create what NAI calls a “legislation” file.

You start with the text of the legislation, and then you highlight sections of the legislation and annotate them as either “terms” or “connectives”. So in the picture below, the paragraph as a whole you can see has been highlighted in a grey box, which creates a “if permission” connective. The smaller grey boxes are all “and” connectives, and the coloured boxes are terms.

I found it easier to get the demo (which is still in beta) to work by getting rid of all the line breaks in the legislation and taking out section numbers, but I’m not sure either was necessary.

Image of the annotated version of s2 of the MHA in NAI.

When you are annotating “terms” (the coloured boxes), it allows you to re-use the terms you have already defined, or create new ones. From these annotations it builds a formalization, which you can review.

Jason Morris

Rules as Code Director at Service Canada, CEO Previous: Lawyer; ABA Innovation Fellow; Sessional Instructor; Computational Law Researcher