'prolog to SQL converter
Without thinking to much, it seems to me that a large set of Prolog's functionality could be implemented as relational calculus (a.k.a. SQL).
Has anyone heard of any tools to automatically convert Prolog to SQL?
Solution 1:[1]
Yes, of course.
A premise for skeptics: any semi-decent book on database theory mentions Datalog (which is Prolog-like) and theorems which demonstrate that is possible to translate it to/from Relational Algebra (RA) (under specific restrictions).
SQL is not faithful to RA or relational calculi, but is enough to support Prolog:
- Christoph Draxler has developed a Prolog to SQL compiler (PL2SQL) for his thesis, available for download (.tgz) - also here at CMU Artificial Intelligence Repository (it was adapted and included in at least: Ciao Prolog and SWI-Prolog via Blipkit - Biomedical LogIc Programming Knowledge Integration Kit);
- Igor Wojnicki has developed for his PhD (A Rule-based Inference Engine Extending Knowledge Processing Capabilities of Relational Database Management Systems) a prototype system implementing his Jelly View technology called ReDaReS, but it seems not available for download;
- Relational Abstract Machine (RAM) translates Prolog to Relational Algebra, but it doesn't seems to have a SQL backend;
- Walter D. Potter has a couple of papers on Prolog/RDBMS integration;
- Kevin Boone's paper on Using SQL with Prolog to improve performance with large databases is also interesting;
- and so on...
Solution 2:[2]
The mapping isn't very good. SQL, for example, doesn't do backtracking, unification, lists, or adhoc nested structures.
Prolog doesn't deal well with composite objects, indexes, etc.
I'd say it's a no-go.
Solution 3:[3]
It makes more sense to do an sql query from prolog, which can then be translated into prolog facts. e.g. Prolog ODBC Library
This removes all restrictions and keeps the two languages separated into their proper places.
Solution 4:[4]
I wrote a translator that converts a subset of Prolog into SQL user-defined functions.
This predicate in Prolog can be translated into SQL:
is_between(A,B,C) :-
A<B,B<C.
This is the translator's output as a MySQL function:
CREATE FUNCTION is_between(A double,B double,C double) RETURNS BIT BEGIN
RETURN A>B and B>C;
END
Similarly, there is a Prolog-to-SQL compiler compiler for SWI-Prolog, and another translator that converts a non-recursive subset of Datalog into SQL.
Solution 5:[5]
CQL, a SWI Prolog add-on pack, compiles Prolog, or rather a Prolog DSL, to SQL:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MaD70 |
| Solution 2 | MarkusQ |
| Solution 3 | Timothy Allen |
| Solution 4 | |
| Solution 5 | Erik Kaplun |
