Skip to content

LogicalContracts/LogicalEnglish2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

299 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logical English 2.0

Logical English (LE) is a controlled natural language for legal and business logic. It allows experts to write executable rules that look like plain English, which are then automatically translated into formal logic (Prolog) for reasoning and explanation.

LE 2.0 is a modernized, high-performance implementation of the original Logical English project.

🚀 Try the Live Demo


📖 The Language

Logical English is designed to be readable by non-programmers while remaining mathematically precise.

  • Template-based: Define your own natural language patterns (e.g., *a person* acquires British citizenship on *a date*).
  • Rule-oriented: Write logic using if, and, or.
  • Explainable: Every answer comes with a justification tree in natural language.
  • Typed: Built-in support for types, dates, and arithmetic.

Learn more about LE Syntax | Cheat sheet | View Examples


🛠 The Editor

The LE 2.0 environment provides a powerful, web-based IDE for developing and testing logic:

  • Real-time Feedback: Instant syntax highlighting and error reporting as you type.
  • Integrated Debugger: Step through logic and visualize explanation trees.
  • Scenario Testing: Define "Scenarios" (facts) and "Queries" within the same file to verify behavior.
  • LSP Support: Modern editor features including autocompletion and hover information.

Editor Summary | Debugger Design


🐳 Deployment

Environment Variables

You can configure the deployment using the following environment variables:

  • NO_RESTRICTIONS: Set to true to disable example path restrictions.
  • ALLOWED_LE_EXPORTS: Comma-separated list of allowed /source web endpoint export paths.
  • OPENAI_API_KEY: API key for OpenAI models.
  • ANTHROPIC_API_KEY: API key for Anthropic models.
  • GEMINI_API_KEY, GOOGLE_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY: API key for Google Gemini models.
  • GROQ_API_KEY: API key for Groq models.
  • TOGETHER_API_KEY, TOGETHERAI_API_KEY: API key for Together AI models.

Local Installation (SWI-Prolog)

To run Logical English 2.0 on your local machine:

  1. Install SWI-Prolog: Download and install SWI-Prolog (version 9.0 or later recommended).
  2. Clone the Repository:
    git clone https://github.com/mcalejo/LogicalEnglish2.git
    cd LogicalEnglish2
  3. Start the Server:
    swipl -g "use_module(classic_web_api), start_api_server(3050)" classic_web_api.pl
    The editor will be available at http://localhost:3050/editor/.

Testing

The quickest way to run everything is the aggregate runner in testing/ (it always runs from the repo root, regardless of your current directory):

testing/run_tests.sh            # run all suites and report a combined pass/fail
testing/run_tests.sh --no-e2e   # skip the browser tests (fast: unit + LE examples)
testing/run_tests.sh unit       # only the Prolog plunit suite
testing/run_tests.sh le         # only the Logical English example tests
testing/run_tests.sh e2e        # only the Playwright browser tests

It exits non-zero if any suite that ran failed. The Playwright suite is skipped (not failed) when its prerequisites are missing, unless CI is set. Override the interpreter with SWIPL=/path/to/swipl testing/run_tests.sh.

The individual suites can also be run directly:

  • Prolog unit tests (plunit): swipl -q -g run_tests -t halt testing/test_session_reaper.pl (covers testing/test_*.pl).
  • Logical English example tests: swipl -g "use_module(le_kbs), runTests, halt." (runs the .le / .le.tests examples and refreshes testSuiteStatus.txt).
  • E2E Tests (Playwright):
    cd editor
    npm install
    npm run build
    npm run test:e2e
    To run tests visibly, use npm run test:e2e -- --headed or npx playwright test --ui.

Docker Deployment

Logical English 2.0 is also available as a pre-configured Docker image.

Quick Start

docker run -p 3050:3050 logicalcontracts/le2

The editor will be available at http://localhost:3050/editor/.


🏗 Architecture & API

LE 2.0 is built on SWI-Prolog for the reasoning engine and TypeScript/Monaco for the frontend.

  • Web API: A JSON-RPC and REST API for loading KBs and running queries.
  • MCP Server: Built-in support for the Model Context Protocol, allowing LLMs (like Claude) to interact directly with your logic.

API Documentation | MCP Setup


📝 Roadmap & To-Do

We are actively expanding LE 2.0. Under consideration:

Features & Integration

  • LLM assistant: Generate programs and scenario facts from free-form text or URLs.
  • Inter-module Calling: Importing and calling logic across different LE files.
  • Prolog Bridge: Calling arbitrary Prolog predicates with explanations.
  • Time & Durations: Time expressions and intervals.
  • Debug Adapter Protocol (DAP): Implement DAP for deeper integration with VS Code and other IDEs.
  • Generators: Standalone Prolog and s(CASP) target generation.

Language Evolution

  • Globals: Support for global entities (e.g., *The TaxPayer*).
  • Proprietary Extensions: Allow additions to the LE grammar and reasoner.

⚖️ Licensing and Copyright

All software in this repository is licensed under the Apache License 2.0 except where noted.

Copyright holders by country:

  • LodgeIT (AU)
  • AORA Law, Axiome (UK)
  • AINexus (USA)
  • Bob Kowalski (UK)
  • Miguel Calejo (PT)
  • Jacinto Dávila (VE)

Special thanks to: Andrew Noble, John Cummins, Chris and Bruce Mennell, Galileo Sartor and Faramarz Farhoodi.

For the legacy implementation and historical context, visit the original Logical English repository.


About

A full reimplementation of Logical English

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors