Commits

Pierre Carbonnelle  committed 94433d9 Draft

Edited online

  • Participants
  • Parent commits 34d36f7

Comments (0)

Files changed (1)

-== Table of Contents ==
-* Why use it ?
-* Features
-* Example
-* [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Tutorial%201|Tutorial 1]] - Datalog
-* [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Tutorial%202|Tutorial 2]] - Datalog in python
-* [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Python%20prolog%20and%20datalog|Python prolog and datalog]]
-* [[Reference]]
-* [[Installation]]
-* [[https://bitbucket.org/account/notifications/send/?receiver=pcarbonn|Support]]
-* [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Roadmap%20and%20change%20log|Roadmap and change log]]
-* [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Documentation%20for%200.5|Documentation for older versions]]
 
-== Why use it ? ==
-
-pyDatalog embeds [[http://en.wikipedia.org/wiki/Logic_programming|logic programming]] in python.  
-It is inspired by [[http://www.datalog20.org/slides/aref.pdf|LogicBlox]].
-
-[[http://en.wikipedia.org/wiki/Datalog|Datalog]] is a subset of Prolog that complements python very well for:
-* querying large sets of related information (e.g. in data integration or the semantic web). 
-* simulating intelligent behavior (for games or expert systems), 
-* performing recursive algorithms (e.g. in network protocol, code and graph analysis) 
-
-Datalog statements can be specified in any order, as formula in a spreadsheet, eliminating the need for [[http://en.wikipedia.org/wiki/Sequence_diagram|sequence analysis]] and the associated risk of tricky errors.  
-Datalog programs are often shorter than their python equivalent.  
-
-== Features of version 0.8 ==
-
-pyDatalog embeds logic programming in python:
-* you can assert facts in a datalog knowledge base, and query it.
-* you can define attributes of python classes through [[http://en.wikipedia.org/wiki/Clause_(logic)|logic clauses]], and use logic queries on python objects (see example below).
-* you can use logic clauses to query relational database via [[http://sqlalchemy.org|SQLAlchemy]], the [[http://en.wikipedia.org/wiki/Object-relational_mapping|object-relational mapping]] and [[http://en.wikipedia.org/wiki/Data_access_layer|data access layer]] for python.
-* you can use an interactive console to run datalog queries
-
-More specifically:
-* you can assert logic clauses of the form {{{head <= body}}}, where head is a single literal with one or more variables, and body is a list of literals separated by '&' : {{{p(X) <= q(X) & R(X,Y)}}}
-* each variable in the head must also appear in the body.  The body may include equality and comparison predicates : {{{N1 == N-1}}}, or {{{N > 0}}}, and contain lambda expressions
-* you can negate a literal in the body: {{{not(p(X))}}}
-* the argument of a literal cannot be another predicate : {{{p(q(a))}}} is not allowed
-* you can define logic functions by a formula: {{{p[X]=expression}}} (similar to an assignment)
-* you can define aggregate functions, e.g. {{{p[X]=len(Y) <= body}}} : len, sum, concat, min, max
-* you can use prefixed literals and functions (e.g. {{{Employee.name[X]==Y)}}}) to refer to python objects in logic clauses, or to run logic queries in python programs
-
-pyDatalog is fast and lightweight:
-* it is based on the [[http://www.cs.sunysb.edu/~tswift/webpapers/jlp-95.pdf|SLG resolution]] algorithm with [[http://en.wikipedia.org/wiki/Memoization|memoization]]
-* it can run on [[http://pypy.org|pypy]] (python with Just-In-Time compiler)
-* it has less than 2 K lines of code.
-
-The depth of recursion is not limited by the stack size.
-
-pyDatalog is open-source (LGPL).  It has been tested with python 2.7, python 3.2, pypy 1.9, SQLAlchemy 0.7.
-
-== Example ==
-
-Let's define an Employee class, create some objects, and run logic queries on them.
-
-1. define python class and business rules
-
-{{{
-#!python
-
-from pyDatalog import pyDatalog
-
-class Employee(pyDatalog.Mixin):   # --> Employee inherits the pyDatalog capability to use logic clauses
-    
-    def __init__(self, name, manager, salary): # method to initialize Employee instances
-        super(Employee, self).__init__() # calls the initialization method of the Mixin class
-        self.name = name
-        self.manager = manager           # direct manager of the employee, or None
-        self.salary = salary             # monthly salary of the employee
-    
-    def __repr__(self): # specifies how to display an Employee
-        return self.name
-
-    @pyDatalog.program() # indicates that the following method contains pyDatalog clauses
-    def _():
-        # the salary class N of employee X is computed as a function of his/her salary
-        # this statement is a logic equality, not an assignment !
-        Employee.salary_class[X] = Employee.salary[X]//1000
-        
-        # all the indirect managers Y of employee X are derived from his manager, recursively
-        Employee.indirect_manager(X,Y) <= (Employee.manager[X]==Y)
-        Employee.indirect_manager(X,Y) <= (Employee.manager[X]==Z) & Employee.indirect_manager(Z,Y)
-}}}
-
-2. create python objects
-
-{{{
-#!python
-
-John = Employee('John', None, 6800)
-Mary = Employee('Mary', John, 6300)
-}}}
-
-3. Query the objects using the datalog engine
-
-The following python statements implicitly use the datalog clauses in the class definition.  
-Notice the similarity to a pyDatalog query.
-
-{{{
-#!python
-
-# What is the salary class of Mary ?
-print(Mary.salary_class)
-
-# who has a salary of 6300 ?
-X = pyDatalog.Variable()
-Employee.salary[X]==6300
-print(X) # prints (Mary,)
-
-# Who are the employees with a salary class of 6 ?
-Employee.salary_class[X]==6
-print(X) # prints (John, Mary)
-
-# who are the indirect managers of Mary (recursively) ?
-Employee.indirect_manager(Mary, X)
-print(X) # prints (John,)
-
-}}}
-
-[[https://bitbucket.org/pcarbonn/pydatalog/src/88cc95f9d2b4/pyDatalog/_example%20SQLAlchemy.py|This similar example]] shows how to write a similar program to add business logic to a relational database using SQLAlchemy.
-[[https://bitbucket.org/pcarbonn/pydatalog/src/88cc95f9d2b4/pyDatalog/_example%20datalog.py|This one]] is using a pure datalog knowledge base.  These modes can be mixed freely.
-
-See the [[https://bitbucket.org/pcarbonn/pydatalog/wiki/Tutorial%201|Tutorial 1]] for more explanations.
-
-[[Home|Return to top]]
+   Please visit [[https://sites.google.com/site/pydatalog/|our main website]]