Code Monkey home page Code Monkey logo

loreleai's Introduction

loreleai

Lorelai aims to be Keras for Logical reasoning and learning in AI. It provides a unified language for expressing logical theories and connects it to various backends (Prolog, Answer Set Programming, Datalog, ...) to reason with the provided theories.

THIS IS STILL WORK IN PROGRESS, EXPECT CHANGES!

Installation

loreleai depends on pylo to interface with Prolog engines. Follow the instructions to install pylo here.

If you will be using a Datalog engine, follow the instructions to install z3.

Then clone this repository and run

pip install .

Quick start

loreleai allows you to easy specify you knowledge and ask queries about it

More details: for more details on usage of logic and Prolog engines, check the instructions of pylo

from loreleai.language.lp import c_const, c_var, c_pred
from loreleai.reasoning.lp.datalog import MuZ

p1 = c_const("p1")                      # create a constant with the name 'p1'
p2 = c_const("p2")
p3 = c_const("p3")

parent = c_pred("parent", 2)            # create a predicate/relation 'parent'
grandparent = c_pred("grandparent", 2)

f1 = parent(p1, p2)                     # create the fact 'parent(p1, p2)'
f2 = parent(p2, p3)

V1 = c_var("X")                         # create a variable named 'X'
V2 = c_var("Y")
V3 = c_var("Z")

# create a clause defining the grandparent relation
cl = (grandparent(V1, V3) <= parent(V1, V2) & parent(V2, V3))

solver = MuZ()                          # instantiate the solver
                                        # Z3 datalog (muZ)I pro
solver.assert_fact(f1)                  # assert a fact
solver.assert_fact(f2)
solver.assert_rule(cl)                  # assert a rule

solver.has_solution(grandparent(p1, p3))# ask whether there is a solution to a query
solver.query(parent(V1, V2))    # ask for all solutions
solver.query(grandparent(p1, V1), max_solutions=1)# ask for a single solution

Alternatively, loreleai provides shortcuts to defining facts

from loreleai.language.lp import  c_pred

parent = c_pred("parent", 2)            # create a predicate/relation 'parent'
grandparent = c_pred("grandparent", 2)

f1 = parent("p1", "p2")                 # 'p1' and 'p2' are automatically parsed into a Constant
f2 = parent("p2", "p3")

query_literal = grandparent("p1", "X")  # 'X' is automatically parsed into a Variable

Reasoning engines are located in loreleai.reasoning.lp followed by the specific type of logic programming

  • prolog: supported Prolog engines:
    • SWIProlog for SWI Prolog
    • GNUProlog for GNU Prolog
    • XSBProlog for XSB Prolog
  • datalog: supported Datalog engines:
    • MuZ for Z3's datalog engine
  • kanren: for relational programming
    • MiniKanren

Supported reasoning engines

Prolog

Currently supported (via pylo):

Relational programming

Prolog without side-effects (cut and so on)

Currently supported:

Datalog

A subset of Prolog without functors/structures

Currently supported:

Considering:

Deductive databases

Currently supported:

  • none yet

Considering:

Answer set programming

Currently supported:

  • none yet

Considering:

Roadmap

First direction: reasoning engines

  • integrate one solver for each of the representative categories
  • add support for external predicates (functionality specified in Python)
  • SWI prolog wrapper
  • include probabilistic engines (Problog, PSL, MLNs)
  • add parsers for each dialect
  • different ways of loading data (input language, CSV, ...)

Second directions: learning primitives

  • add learning primitives such as search, hypothesis space generation
  • wrap state of the art learners (ACE, Metagol, Aleph)

Code structure

The language constructs are in loreleai/language folder. There is a folder for each dialect of first-order logic. Currently there are logic programming (loreleai/language/lp) and relational programming (loreleai/language/kanren). The implementations of all shared concepts are in loreleai/language/commons.py and the idea is to use __init__.py files to provide the allowed constructs for each dialect.

The reasoning constructs are in loreleai/reasoning folder. The structure is the same as with language. Different dialects of logic programming are in the folder lorelai/reasoning/lp.

The learning primitives are supposed to be in the loreleai/learning folder.

Requirements

  • pyswip
  • problog
  • ortools
  • minikanren
  • z3-solver
  • black

Notes for different engines

SWI Prolog

For using SWI prolog, check the install instructions: https://github.com/yuce/pyswip/blob/master/INSTALL.md

Z3

Z3Py scripts stored in arbitrary directories can be executed if the 'build/python' directory is added to the PYTHONPATH environment variable and the 'build' directory is added to the DYLD_LIBRARY_PATH environment variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.