<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Web-based user-friendly Rules as Code</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jason Morris</string-name>
          <email>jason@lexpedite.ca</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>. Rules as Code</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>GDEASP '22: Workshop on Goal-Directed Execution of Answer Set Programs</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Lexpedite Legal Technology Ltd.</institution>
          ,
          <addr-line>Sherwood Park, Alberta</addr-line>
          ,
          <country country="CA">Canada</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Rules as Code</institution>
          ,
          <addr-line>s(CASP)</addr-line>
          ,
          <institution>Legal Technology</institution>
          ,
          <addr-line>Explainable AI, Expert Systems</addr-line>
        </aff>
      </contrib-group>
      <issue>42</issue>
      <abstract>
        <p>This paper describes Blawx, a prototype web-based user-friendly Rules as Code tool, powered by a goal-directed answer set programming. The paper briefly describes Rules as Code, and introduces desireable qualities for Rules as Code tools. It provides justifications for Blawx's implementation of the Google Blockly library, and the s(CASP) reasoning system. It then provides a step-by-step tour of how Blawx allows a user to generate an answer set program representing their understanding of a statute, and use that encoding to power an application. The paper concludes with a brief discussion of the current short term and anticipated long-term development objectives for Blawx.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>2. Blawx</title>
      <p>https://www.lexpedite.ca/ (J. Morris)</p>
      <p>© 2022 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).
CEUR
Workshop
Proceedings
• sophisticated reasoning features, to ensure the representations are as useful as possible
• natural language explanations for conclusions linked to legislative source material, to
earn trust of experts, developers, and users
• ease of integration with other technologies, to increase the value of encodings and promote
adoption</p>
      <p>While there are a number of commercial and open source oferings with some of these
qualities, several of which have inspired aspects of this work3, Blawx is to my knowledge the
only ofering with all of them.</p>
      <p>Since late 2021, development of Blawx has been guided primarily by the needs of the Rules
as Code Programme at the Canada School of Public Service, which is supporting departments
across the Government of Canada interested in exploring the Rules as Code methodology.</p>
      <sec id="sec-1-1">
        <title>2.1. Blockly</title>
        <p>Blawx features a drag-and-drop interface in which an answer set program is represented by
”blocks” which connect to one another in a way that is visually similar to connecting pieces of a
jigsaw puzzle.</p>
        <p>Blawx’s visual interface is developed using Google’s Blockly library4, which is based in
research on teaching programming to children, and utilized in very popular pedagogical tools
such as Scratch5. The puzzle-piece interface reduces the types of syntax errors that are possible
compared to a traditional programming environment, and provides more immediate feedback
with regard to others. This minimizes the cognitive load on beginning users who typically
struggle to diferentiate between syntactic and semantic errors.
2.2. s(CASP)
Work began in December of 2021 on re-implementing Blawx using s(CASP)6 as the back-end
reasoner, moving away from Flora-27. The decision to re-implement in s(CASP) was taken after
investigations into s(CASP) that took place in part at the Singapore Management University
Centre of Computational Law and continued inside the Digital Experience and Client Data
division of Service Canada’s Benefits Delivery Modernization programme. Those experiments
demonstrated its feasibility as a tool for diagnosing and correcting legislative drafting errors 8,
for powering expert systems9, and for dealing with the data types most commonly used in our
target use cases10.</p>
        <p>3See, in particular, AustLII’s Datalex at https://www.datalex.org
4Available at https://github.com/Google/Blockly
5Available at https://scratch.mit.edu
6Arias, Joaquin, et al. ”Constraint answer set programming without grounding.” Theory and Practice of Logic
Programming 18.3-4 (2018): 337-354.</p>
        <p>7Available at http://flora.sourceforge.net
8Morris, Jason. ”Constraint answer set programming as a tool to improve legislative drafting: a rules as code
experiment.” Proceedings of the Eighteenth International Conference on Artificial Intelligence and Law. 2021.
9Docassemble-L4 is available at https://github.com/smucclaw/docassemble-l4
10Presented at Programming Languages and the Law 2022 workshop as ”Prevalence of Expression Types in
Legislative Text”, see
https://popl22.sigplan.org/details/prolala-2022-papers/11/Prevalence-of-Expression-Types-inLegislative-Text</p>
        <p>These experiments revealed several potentially important benefits from using s(CASP) that
were not anticipated. In addition to the critically important feature of natural language
explanations for conclusions, experience showed that multiple stable models, dual programs, and
abducibility provide the legal knowledge engineer with a vastly better understanding of what
their encoding actually means in the development phase, and in turn much greater confidence
that the semantic meaning of the code is consistent with their interpretation of the rules.</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>3. Rules as Code in Blawx</title>
      <p>The user experience of using Blawx for Rules as Code involves providing the legislative text,
encoding the legislative text in a structurally-isomorphic way, testing those encodings, and
then integrating those encodings into other systems.</p>
      <sec id="sec-2-1">
        <title>3.1. Step 1: Getting the Law Into Blawx</title>
        <p>In order for encodings to be structurally isomorphic to the law from which they are derived,
Blawx needs to be aware of the structure of the source law. Akoma Ntoso11 (also known as
LegalDocML), is used to represent legislative texts inside the Blawx system. Open source,
user-friendly editors for LegalDocML are rare, and those that do exist use styles of legislative
drafting unfamiliar in the Canadian context.</p>
        <p>For that reason, I created CLEAN12 (Canadian Legislative Enactments in Akoma Ntoso),
which is a markdown-like plain text syntax for legislative text, with tools for converting it into
Akoma Ntoso. Blawx allows the user to specify legislation in CLEAN. The interface is shown in
Figure 1.</p>
      </sec>
      <sec id="sec-2-2">
        <title>3.2. Step 2: Encoding the Law</title>
        <p>Once the law has been entered, the user is presented with a side-by-side coding environment
with the text of the law on the left, and the Blawx coding environment on the right. The text
of the law is annotated with radio button selectors, which are used to select the hierarchical
section of the law for which the user wants to generate code. If the user wants to encode parts
smaller than a numbered section of the law, CLEAN allows for a span syntax to divide a block
of text into arbitrarily deeply nested named parts, which Blawx will treat as though they were
numbered sections of the law. This interface is seen in Figure 2.</p>
        <p>The user selects one section of the law, and represents that section of law in the coding
window. Ontology (categories, attributes, and objects) declared in any section of the law become
available for use in all sections of the law, eliminating the need to redefine terms that have been
defined elsewhere.</p>
        <p>When sections of the law are expressed in a non-monotonic way, such as defaults and
exceptions, the user has access to language elements that allow them to attribute a conclusion to
a section of law, specify which conclusions conflict, and specify how to resolve those conflicts as
11Palmirani, Monica, and Fabio Vitali. ”Akoma-Ntoso for legal documents.” Legislative XML for the semantic
Web. Springer, Dordrecht, 2011. 75-100.</p>
        <p>12Available at https://github.com/lexpedite/CLEAN
between two rules. In this way, the user is able to maintain structural isomorphism regardless
of whether in the legislative text the conflict is explicitly resolved in the default (e.g. ”subject to
following sections”), or in the exception (e.g. ”despite section 3 above”). These statements are
resolved using a very simple argumentation theory inspired by the approach taken in Flora-213.
An example of an encoding using defaults and exceptions is shown in figure 3.</p>
      </sec>
      <sec id="sec-2-3">
        <title>3.3. Step 3: Testing the Encoding</title>
        <p>Once the law has been encoded, the user is able to create ”tests”, which are another coding
environment with access to all of the ontology declared in the encoding of the law itself. Here,
the user can create a fact scenario and a query, have the reasoner run that query, and display
the results. If the conclusion is one to which the defeasibile argumentation theory applies, there
is a version of the query that allows the user to ask whether a given legal conclusion holds,
despite being defeasible. The user can also ask whether a conclusion held according to any
section of the law. An example test is shown in Figure 4.</p>
        <p>13Wan, Hui, et al. ”Logic programming with defaults and argumentation theories.” International Conference on
Logic Programming. Springer, Berlin, Heidelberg, 2009.</p>
        <p>s(CASP) code is generated from the Blawx code, and saved to the server. When the test is
run, the server collects all of the s(CASP) code for the sections of the law, adds the s(CASP) code
generated for the test, and adds libraries that are used for defeasibility and date calculations.
The query is then sent to SWI-Prolog14 using the s(CASP) library15, and the results are displayed
to the user. Models with the same bindings are grouped into an ”answer”. Each ”answer” shows
its bindings (if applicable) and one or more ”explanations”, which are a collapsible tree view of
the natural language justification provided by the s(CASP) reasoner. When the defeasibility
elements of the encoding refer to sections of the source law, those sections are highlighted in
the text of the explanation. Hovering over the highlighted text display the text of the legislative
section to which they refer. An example of the answer display is shown in Figure 5.</p>
      </sec>
      <sec id="sec-2-4">
        <title>3.4. Step 4: Deploying the Encoding</title>
        <p>Each test that is created in Blawx automatically generates three web API endpoints designed to
allow the user to collect information about the ontology defined in a given test, and to run the
included queries with or without information about what additional inputs might be relevant to
14Avaialble at https://swi-prolog.org
15Available at https://github.com/JanWielemaker/sCASP
ifnding stable models for the query. These interfaces are designed to allow the Blawx encoding
to be able to power expert systems and other tools elsewhere on the web. As a demonstration
of the use of these interfaces, an example expert system called ”BlawxBot” is available. Running
BlawxBot displays a chatbot-style user interface where the user is prompted to provide the
details of a relevant fact scenario. As soon as a stable model exists the interview is terminated
and the result is displayed to the user. An example of the BlawxBot interface is shown in Figure
6.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>4. Future Work</title>
      <p>Work on Blawx in the near term will continue to be guided by the needs of the Canada School
of Public Service and its client departments. Currently, our priorities are:
• Complete BlawxBot expert system chatbot interface
• Enhance documentation, examples, and training materials</p>
      <p>We then hope to test Blawx extensively with real-use world cases, and use feedback from the
users to guide future development.</p>
    </sec>
    <sec id="sec-4">
      <title>5. Conclusion</title>
      <p>The Rules as Code movement suggests that legal knowledge representation has great potential
benefits for policy design, legislative drafting, public administration, compliance, and other
endeavours. Our experiments have shown that s(CASP) has great potential as a tool for statutory
legal knowledge representation. Blawx is an attempt to facilitate the use of s(CASP) by
nonprogrammer subject matter experts for Rules as Code tasks, to explore how we might unlock
that potential. Recent months have seen a focus on developing a prototype which is now almost
complete. Work will continue inside the Government of Canada testing that prototype against
real-world use cases to improve both the tool and our understanding of the Rules as Code
methodology generally.</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments</title>
      <p>My thanks to Pia Andrews, and to the DECD team at the Benefits Delivery Modernization
Programme in Service Canada. Thanks also to the visionary leaders at the Canada School
of Public Service who are leading the world in commitment to exploring the Rules as Code
approach in the public sector. In particular, thanks to Marty Perron of CSPS, who has provided
valuable direct feedback on Blawx’s development.</p>
      <p>Thanks also to the leadership and staf of the Singapore Management University Centre for
Computational Law.</p>
      <p>Thank you also the developers of s(CASP) for their support and assistance, and to the
organizers of this conference for their interest in my work in the legal domain.</p>
      <p>Research having occurred at the Singapore Management University Centre for Computational
Law was supported by the National Research Foundation (NRF), Singapore, under its Industry
Alignment Fund – Pre-Positioning Programme, as the Research Programme in Computational
Law. Any opinions, findings and conclusions or recommendations expressed in this material are
those of the author(s) and do not reflect the views of National Research Foundation, Singapore.</p>
    </sec>
  </body>
  <back>
    <ref-list />
  </back>
</article>