Using Prolog to make a prediction based on the data in a Relational Database

152 views
Skip to first unread message

rajiv...@gmail.com

unread,
Jun 24, 2015, 11:16:01 AM6/24/15
to swi-p...@googlegroups.com

I have recently come across Prolog.I was wondering whether it is possible for Prolog to make a prediction based on data which is in SQL Server.

Database

Day    Weather  Taken out Umbrella
Monday Cloudy   Yes 
Tuesday Sunny   No
Wednesday Rain   Yes 
Thursday  Sunny  No    

Can Prolog use this data in the database and make a prediction whether to take out the umbrella or not

Alan Baljeu

unread,
Jun 25, 2015, 10:34:05 AM6/25/15
to rajiv...@gmail.com, swi-p...@googlegroups.com
Prolog is a programming language, so yes.  It doesn't have specific tools to recognize patterns in data, but if libraries exist I'm interested.

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.

Jan Wielemaker

unread,
Jun 25, 2015, 10:50:33 AM6/25/15
to Alan Baljeu, rajiv...@gmail.com, swi-p...@googlegroups.com
On 06/25/2015 04:34 PM, Alan Baljeu wrote:
> Prolog is a programming language, so yes. It doesn't have specific
> tools to recognize patterns in data, but if libraries exist I'm interested.

Well, as you probably know, there is library(odbc) to access databases
and library(cql) which provides a high level view. The high level view
is probably not worth the trouble for this really simple case, but it
can be if you must pose much more complicated queries.

Given a predicate

weather_forecast(Day, Weather) :-
odbc_query(...).

the rest is of course simple :-)

take_umbrella('Cloudy').
take_umbrella('Rain').

If you have lots of facts and you want to learn when to use an umbrella
you need machine learning. There are several libraries for that,
depending on what kind of model you want to learn. I'm afraid I don't
have a clear overview what is readily available and works out-of-the-box
on SWI-Prolog.

Cheers --- Jan


> On Wed, Jun 24, 2015 at 11:16 AM, <rajiv...@gmail.com
> <mailto:rajiv...@gmail.com>> wrote:
>
> I have recently come across Prolog.I was wondering whether it is
> possible for Prolog to make a prediction based on data which is in
> SQL Server.
>
> Database
>
> |Day Weather Taken out Umbrella
> Monday Cloudy Yes
> Tuesday Sunny No
> Wednesday Rain Yes
> Thursday Sunny No|
>
> Can Prolog use this data in the database and make a prediction
> whether to take out the umbrella or not
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.

nicos.ang...@gmail.com

unread,
Jun 25, 2015, 4:37:35 PM6/25/15
to swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com


On Thursday, June 25, 2015 at 3:50:33 PM UTC+1, Jan Wielemaker wrote:
On 06/25/2015 04:34 PM, Alan Baljeu wrote:
> Prolog is a programming language, so yes.  It doesn't have specific
> tools to recognize patterns in data, but if libraries exist I'm interested.

Well, as you probably know, there is library(odbc) to access databases
and library(cql) which provides a high level view. The high level view
is probably not worth the trouble for this really simple case, but it
can be if you must pose much more complicated queries.

Given a predicate

weather_forecast(Day, Weather) :-
        odbc_query(...).

the rest is of course simple :-)

take_umbrella('Cloudy').
take_umbrella('Rain').

If you have lots of facts and you want to learn when to use an umbrella
you need machine learning. There are several libraries for that,
depending on what kind of model you want to learn. I'm afraid I don't
have a clear overview what is readily available and works out-of-the-box
on SWI-Prolog.

        Cheers --- Jan




Dear all

As a general note to readily available machine learning packs:

pepl  - implements Cussen's failure adjusted maximisation to fit parameter to stochastic/labelled clauses [1]
bims - implements MCMC (Bayesian inference over model structures) builds classification trees and Bayesian networks [2][3]

These are  two packs I have co-developed, it is not supposed to be an exhaustive list.

As far as I know there is also at least
cplint -  which mentions that it learns in the context of probabilistic logic programs [4]

Would be interested to hear of others. Yap has Aleph, a pack of that would be nice.
Finally SWI also has Real you can throw Prolog data across to R and do the learning there.

In general it might be a good idea to have a web-page with area-specific code and papers that cite SWI-Prolog.
Ggle scholar shows 172 papers citing the TPLP paper. Not bad, but it could be better and ideally all people using
SWI should cite the paper. It would be interesting/useful to know which areas these papers come from, and what it is the trend.
A stack with the SWI web server and a bibtex parser could easily be set so people can upload their citing papers and areas.
 
And in the context of packs, a controlled vocabulary of topics that each pack belongs to, would be a useful first step towards
view by "subject".
  

Regards,

Nicos Angelopoulos
----
http://stoics.org.uk/~nicos

[1]  Parameter estimation in stochastic logic programs
      James Cusses, 2001.
      Machine Learning 44(3), 245-271
 
[2]  Bayesian learning of Bayesian Networks with informative priors.
Nicos Angelopoulos and James Cussens (2008).
Special issue on BN learning. Journal of Annals of Mathematics and Artificial Intelligence 54(1-3), 53-98.

[3]  more publication at http://stoics.org.uk/~nicos/sware/bims/

[4] http://www.swi-prolog.org/pack/list?p=cplint

Jan Wielemaker

unread,
Jun 26, 2015, 2:50:35 AM6/26/15
to nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
On 06/25/2015 10:37 PM, nicos.ang...@gmail.com wrote:

> As a general note to readily available machine learning packs:
>
> pepl - implements Cussen's failure adjusted maximisation to fit
> parameter to stochastic/labelled clauses [1] bims - implements MCMC
> (Bayesian inference over model structures) builds classification
> trees and Bayesian networks [2][3]
>
> These are two packs I have co-developed, it is not supposed to be
> an exhaustive list.
>
> As far as I know there is also at least cplint - which mentions that
> it learns in the context of probabilistic logic programs [4]

Thanks pointing these out!

> Would be interested to hear of others. Yap has Aleph, a pack of that
> would be nice. Finally SWI also has Real you can throw Prolog data
> across to R and do the learning there.

Aleph runs on SWI-Prolog. I should have a version lying around
somewhere. Would indeed be good to turn it into a pack.

> In general it might be a good idea to have a web-page with
> area-specific code and papers that cite SWI-Prolog. Ggle scholar
> shows 172 papers citing the TPLP paper. Not bad, but it could be
> better and ideally all people using SWI should cite the paper. It
> would be interesting/useful to know which areas these papers come
> from, and what it is the trend. A stack with the SWI web server and a
> bibtex parser could easily be set so people can upload their citing
> papers and areas.
>
> And in the context of packs, a controlled vocabulary of topics that
> each pack belongs to, would be a useful first step towards view by
> "subject".

A first step would be to actually do something with the keywords that
appear in the pack meta-data. We now have 124 registered packs and it
is getting a bit hard to find the right one. I think that should be
considered good news :-)

Cheers --- Jan

>
>
> Regards,
>
> Nicos Angelopoulos ---- http://stoics.org.uk/~nicos
>
> [1] Parameter estimation in stochastic logic programs James Cusses,
> 2001. Machine Learning 44(3), 245-271
>
> [2] Bayesian learning of Bayesian Networks with informative priors.
> Nicos Angelopoulos and James Cussens (2008). Special issue on BN
> learning. Journal of Annals of Mathematics and Artificial
> Intelligence 54(1-3), 53-98.
>
> [3] more publication at http://stoics.org.uk/~nicos/sware/bims/
>
> [4] http://www.swi-prolog.org/pack/list?p=cplint
>

nicos.ang...@gmail.com

unread,
Jun 26, 2015, 4:51:32 AM6/26/15
to swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com, nicos.ang...@gmail.com


On Friday, June 26, 2015 at 7:50:35 AM UTC+1, Jan Wielemaker wrote:
On 06/25/2015 10:37 PM, nicos.ang...@gmail.com wrote:

>
> And in the context of packs, a controlled vocabulary of topics that
> each pack belongs to, would be a useful first step towards view by
> "subject".

A first step would be to actually do something with the keywords that
appear in the pack meta-data.  We now have 124 registered packs and it
is getting a bit hard to find the right one.  I think that should be
considered good news :-)



Apologies, I kind of hijacked the thread.

It is very good news indeed, but if you want to have "views" it seems natural to
have a number of "recognised" terms. What if one developer has DCG' another has 'grammar'  and the
third one goes for NLP ? I am optimistic the management team and advisors will come with
a good solution.

As someone that develops  packs, I would like to thank you for your excellent work.
I hope you feel that the grief that some people gave you on the old list has been justified.
Not only the packs have given an avenue of adding functionality to SWI, but
in as far as I can see from occasionally reading the list,
they have also reduced the number of pest-requests for features.

Finally, the stack with bibtex and maybe prosqlite, could be a nice showcase, and a useful pack for others.

Thanks again,

Nicos Angelopoulos.
---
http://stoics.org.uk/~nicos

Sam Neaves

unread,
Jun 26, 2015, 8:54:21 AM6/26/15
to nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
Would be great to have Aleph as a pack. 

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.

Jan Wielemaker

unread,
Jun 26, 2015, 11:07:40 AM6/26/15
to Sam Neaves, nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
On 06/26/2015 02:54 PM, Sam Neaves wrote:
> Would be great to have Aleph as a pack.

I have a copy of Aleph that Steve Moyle and I ported to SWI back in 2003
to do an experiment on concurrent Aleph. A quick test shows this still
runs, even in SWI7 :-) It is quite a mess tough. There are three
copies of Aleph in there various dummy test files and text files with
all kinds of remarks on the things we were doing back then.

I don't know whether other stuff happened to the Aleph sources since.

If anyone likes to package it up, I'm happy to put it on my personal
GitHub page, so someone can fork and `packify' it.

Cheers --- Jan

Jan Wielemaker

unread,
Jun 26, 2015, 11:20:55 AM6/26/15
to nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
Hi Nicos,

Would be great if some people could pick up a `pack version 2'. You
probably have most experience with it. Surely you added most popular
packs. The software in spread over three places:

- boot/packs.pl adds packs to Prolog at startup.
- library/prolog_pack.pl manages the installation of packs

The server is defined in the plweb.git repo that implements
www.swi-prolog.org. There we find:

- pack_analyzer.pl
Performs analysis of the pack Prolog code
- pack_info.pl
Provides general info on the content of packs
- pack_mirror.pl
Creates a mirror of the pack for analysis.
- pack.pl
Implements the web frontend.

You can clone plweb.git and run a pack server locally.

Cheers --- Jan

Anne Ogborn

unread,
Jun 26, 2015, 1:00:35 PM6/26/15
to Jan Wielemaker, nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com


> It is very good news indeed, but if you want to have "views" it seems
> natural to have a number of "recognised" terms. What if one
> developer has DCG' another has 'grammar' and the third one goes for
> NLP ? I am optimistic the management team and advisors will come
> with a good solution.
>


Actually, that's a classic example of the sort of problem RDF was intended to solve.

Maybe we could start promulgating some sort of ontology for packs.

Stassa Patsantzis

unread,
Jun 26, 2015, 5:16:52 PM6/26/15
to swi-p...@googlegroups.com, alanb...@gmail.com, nicos.ang...@gmail.com, rajiv...@gmail.com, sam.n...@gmail.com
Hi Jan,

This is a bit of a long shot but - since you mentioned Aleph - would you also happen to have a copy of Problog (v1) that will run on Swi? It comes  with Yap as a library but I haven't managed to run it on either YAP or SWI.

Kind regards,
Stassa

Wouter Beek

unread,
Jun 27, 2015, 2:49:10 AM6/27/15
to Anne Ogborn, Jan Wielemaker, nicos.ang...@gmail.com, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
On Fri, Jun 26, 2015 at 6:59 PM, Anne Ogborn <an...@theelginworks.com> wrote:

Actually, that's a classic example of the sort of problem RDF was intended to solve.
Maybe we could start promulgating some sort of ontology for packs.
​These ontologies already exist, e.g., DOAP.​ Most of properties currently expressed in Prolog Packs are already covered by FOAF, DCTERMS and PROV.

---
​Cheers!,
Wouter.

E-mail: w.g.j...@vu.nl
WWW: www.wouterbeek.com
Tel.: 0647674624

Nicos Angelopoulos

unread,
Jun 29, 2015, 7:18:41 AM6/29/15
to Jan Wielemaker, swi-p...@googlegroups.com

Dear Jan,

On Fri, 26 Jun 2015 17:20:53 +0200
Jan Wielemaker <J.Wiel...@vu.nl> wrote:

> Hi Nicos,
>
> Would be great if some people could pick up a `pack version 2'. You
> probably have most experience with it. Surely you added most popular
> packs. The software in spread over three places:
>
> - boot/packs.pl adds packs to Prolog at startup.
> - library/prolog_pack.pl manages the installation of packs
>
> The server is defined in the plweb.git repo that implements
> www.swi-prolog.org. There we find:
>
> - pack_analyzer.pl
> Performs analysis of the pack Prolog code
> - pack_info.pl
> Provides general info on the content of packs
> - pack_mirror.pl
> Creates a mirror of the pack for analysis.
> - pack.pl
> Implements the web frontend.
>
> You can clone plweb.git and run a pack server locally.
>
> Cheers --- Jan
>
>

it will indeed be very good if people can contribute.
I think you are quite modest though. you made substantial enhancements recently and as far as
i can see there is only one possible bug and one improvement that can put some structure to
looking for packs could go quite a long way. The straightforward way of making some keywords "hot"
is really not a bad idea, hope you will consider it. Also as discussed in another thread by others this weekend,
some conventions such as new facts in pack.pl would tidy things up nicely with minimal work centrally.

As I promised off-line, I will try to hunt the "dependency" counter bug (if it exists) over the summer,
but my current employment does not allow me to commit to maintaining critical infrastructure.

In my opinion, the pack manager is critical to the central SWI system and its husbandry should
be with acknowledged maintainers of the core system- my views on the current development model are well documented
so i will not bore people with reiterating them here. In passing let me also note, that the LP community is
very immature in promoting well maintained, dependable code. Other communities are thriving by accepting
papers describing such code. This is not a zero-sum game.

I hope the pack system will go from strength to strength and it will attract citations to main SWI and the packs.
For my part I have added citations to SWI in 4 recent pubmed-ed
publications: 26089344, 26022350, 25758319, 25447308.
1 ICLP technical contribution (the bouncers of ICLP murdered the paper for TPLP)
1 ICLP workshop paper (under review).
I have also emailed on the mailing-list with suggestions about the pack manager.
So I hope you don't feel I am a freeloader.

On the other hand prosqlite has 171 downloads and Real 135. But only 1 no-self citation for Real.
I think it would be nice if LP and SWI communities start to get serious about robust publicly available maintained software, but it is
not my show. The people I work for will fire me on the spot if they realise how non-standard the tools I use are.

Apologies (again) for hijacking, the hijacked thread.
Thanks for the technical info, provisio of counters being updated centrally and ability to only serve own packs,
I would eventually like to run a stoics package server.

Many thanks for your kind words and for maintaining a fantastic piece of cutting edge software,

Nicos

----
Nicos Angelopoulos
http://stoics.org.uk/~nicos

Fabrizio Riguzzi

unread,
Jul 10, 2015, 9:50:58 AM7/10/15
to Jan Wielemaker, Sam Neaves, Nicos Angelopoulos, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com
Dear all,
I have created a pack with aleph. It's called aleph. Enjoy!

Best
Fabrizio

Sam Neaves

unread,
Jul 11, 2015, 8:29:07 AM7/11/15
to Fabrizio Riguzzi, Jan Wielemaker, Nicos Angelopoulos, SWI-Prolog, Alan Baljeu, rajiv...@gmail.com
Fantastic :)

Fabrizio Riguzzi

unread,
Jul 13, 2015, 4:00:05 AM7/13/15
to Sam Neaves, Jan Wielemaker, Nicos Angelopoulos, SWI-Prolog, Alan Baljeu, rajiv...@gmail.com
By the way, the cplint pack contains also the probabilistic ILP system SLIPCOVER.

Nicos Angelopoulos

unread,
Jul 14, 2015, 3:19:10 AM7/14/15
to Fabrizio Riguzzi, Jan Wielemaker, Sam Neaves, swi-p...@googlegroups.com, alanb...@gmail.com, rajiv...@gmail.com

Dear Fabrizio,

Very public spirited of you.

Many thanks.

Nicos Angelopoulos.
---
http://stoics.org.uk
Reply all
Reply to author
Forward
0 new messages