Skip to content

logicmoo/ace_llm_logic

Repository files navigation

ace_llm_logic

A command-line pipeline that converts natural English into first-order logic (FOL) using:

  • ✅ LLM (OpenAI GPT-4o) to rewrite to ACE-compatible Controlled English
  • ✅ APE parser with ERG grammar to derive formal logical representations
  • ✅ LLM again to reintroduce tense, aspect, and passive voice
  • ✅ Optional mock mode for development and testing without ACE
  • ✅ Automatic APE HTTP server startup with --use-http-ape override

📁 Project Structure

ace_llm_logic/
├── python/ace_llm_logic/      # Python source code (CLI & pipeline)
├── APE/                       # Bundled Attempto Parsing Engine
├── tests/                     # Pytest tests
├── requirements.txt
├── pyproject.toml
├── Dockerfile
├── .gitignore
└── README.md

🔧 Requirements

  • Python 3.8+
  • OpenAI Python SDK v1.x
  • SWI-Prolog (e.g. apt install -y swi-prolog-full)
  • OpenAI API key
  • Bundled APE parser executable

Install dependencies:

apt update -y
apt install -y swi-prolog-full
pip install -r requirements.txt
pip install -e .

🛠️ APE Parser

This repository ships with the Attempto Parsing Engine under APE/. After installing SWI-Prolog, the CLI automatically launches APE in HTTP mode. Use --use-http-ape host:port to connect to an existing server if desired.


🚀 Usage

From a file:

export OPENAI_API_KEY=sk-...
ace-llm-logic --file input.txt

Interactively:

ace-llm-logic

Mock Mode (no ACE required):

ace-llm-logic --mock

Connect to an existing APE HTTP server with:

ace-llm-logic --use-http-ape host:port

✅ Example

Input:

The report was written by Alice after she reviewed the data.

ACE-friendly rewrite (via GPT):

Alice writes the report. Alice reviews the data before that.

Final adjusted logic:

past(write(alice, report1)).
past(review(alice, data1)).
after(write(alice, report1), review(alice, data1)).
passive_form(write(alice, report1)).

❌ Unparsable Sentence Example

If the APE server cannot parse a sentence, it responds with an XML error block. Running the server and sending a nonsense sentence like Blah. results in:

curl "http://localhost:5000?text=Blah.&solo=fol"

which returns

<?xml version="1.0" encoding="UTF-8"?>
<messages>
  <message importance="error" type="ape" sentence="" token="" value=""
           repair="Fatal error. Please send screenshot to APE developers."/>
</messages>

🧪 Testing

pytest tests/

Tests require access to an OpenAI API key and will launch a local APE HTTP server.


🐳 Docker

To run inside a container:

docker build -t ace-llm-logic .
docker run -e OPENAI_API_KEY=sk-... ace-llm-logic

🧠 Why Use This?

This pipeline allows you to:

  • Accept natural, unrestricted English
  • Normalize it to a controlled syntax (ACE)
  • Parse it into precise formal logic
  • Recover the original nuance (tense, passive, etc.)

Useful for knowledge extraction, rule-based agents, FOL-based reasoning, or explainable AI.


📜 License

MIT

About

A pipeline that uses ACE and an LLM to convert natural English into Logical Form

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •