GithubHelp home page GithubHelp logo

linearregression / datalog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fogfish/datalog

0.0 2.0 0.0 172 KB

simplified query engine based on logic programming paradigm

License: Apache License 2.0

Makefile 23.65% Erlang 76.35%

datalog's Introduction

datalog

The library implements a simplified version of query engine using logic programming paradigm. The logic program consists of finite set of facts (knowledge base) and rules. The rules are used to deduce new facts from other facts. The knowledge base is abstracted using streams to retrieve ground facts and feed them to logic engine.

The Horn clauses formally defines rules

   L0 :- L1, ..., Ln

L0 is a rule head, it is a producer of new facts deducted by body expression. The body is a conjunction of statement, built-in functions and filters. Each Li consist of predicate symbol and terms sucn as p(t1, ..., tk). A term is either a constant or a variable. The library reflect each predicate to another horn clause or stream of facts.

Each datalog program has a goal that defines a subset of required relation.

Example of datalog program

?- id(X, "Ridley Scott").
id(X, Y) :- like(X, name, Y). 

syntax

The library supports two notations for datalog:

  • the original as string(), it is compliant with @todo
  • Erlang native format as term()

native format

-type(datalog() :: {atom(), bind(), [horn()]}).
-type(horn()    :: {atom(), bind(), [pred()]}).
-type(pred()    :: {atom(), bind()}).
-type(bind()    :: [any()]).

Example of Erlang native datalog

{id, [x, <<"Ridley Scott">>], 
   [
      {id, [x,y], [ {like, [x, name, y]} ]}
   ]
}.

datalog to predicate

match all

?- id(X, Y). 
id(X, Y) :- like(X, Y).

like('_', '_')

pattern match

?- id("A", Y). 
id(X, Y) :- like(X, Y).

like(<<"A">>, '_')

pattern match with clauses

?- id("A", Y). 
id(X, Y) :- like(X, Y), Y > 10.

like(<<"A">>, [{'>', 10}])
?- id("A", Y). 
id(X, Y) :- like(X, Y), Y > 10, Y < 20.

like(<<"A">>, [{'>', 10}, {'<', 20}])

relation algebra vs datalog

intersection

   a(X,Y) ⋀ b(X,Y)
   h(X,Y) :- a(X,Y), b(X,Y) 

union

   a(X,Y) ⋁ b(X,Y)
   h(X,Y) :- a(X,Y)
   h(X,Y) :- b(X,Y)

references

  1. http://ion.uwinnipeg.ca/~ychen2/journalpapers/StratifiedDB.pdf
  2. http://www.cs.toronto.edu/~drosu/csc343-l7-handout6.pdf

datalog's People

Contributors

fogfish avatar

Watchers

 avatar  avatar

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.