For Programmers: Free Programming Magazines  


Home > Archive > Prolog > June 2007 > Howto access to a prolog database









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Howto access to a prolog database
philippenewsgroup@inetsoft.fr

2007-05-23, 4:22 am

Hello
I have to access to a prolog database (.d)
In this database, there are elements that are readable but i have to
exploit it programmaticaly
I don't know a word of prolog and i want to convert it into txt, csv,
sql (something i can exploit)
does someone has a piece of code that do it or does someone know a
software for that ?

thanks
Philippe

djame

2007-05-23, 7:06 pm

philippenewsgroup@inetsoft.fr wrote:
> Hello
> I have to access to a prolog database (.d)
> In this database, there are elements that are readable but i have to
> exploit it programmaticaly
> I don't know a word of prolog and i want to convert it into txt, csv,
> sql (something i can exploit)
> does someone has a piece of code that do it or does someone know a
> software for that ?
>
> thanks
> Philippe
>

Hello,
if this really a prolog database, it might be expressed as a set of
facts of a given arity (think about tables in a spreadsheet, each line
corresponds to a predicate (ie fact) and each cell of this line to one
argument of this predicate) . One way to see it, would be a listing wich
will print all recorded facts.
Of course it can be way more complicated but one way quick way to write
them to a file or something
would be

write_fact:-
tell('/tmp/toto.facts'),
listing(facts/X),
% with facts and X respectively the predicate name of the facts and X
the number of row of your table
told.

?-write_fact.

then it's relatively easy to use a script language to parse the file and
create whatever format you want to use



Bon courage,

Djamé
Jan Wielemaker

2007-05-24, 8:04 am

On 2007-05-23, djame <djame@biensur.com> wrote:
> philippenewsgroup@inetsoft.fr wrote:
> Hello,
> if this really a prolog database, it might be expressed as a set of
> facts of a given arity (think about tables in a spreadsheet, each line
> corresponds to a predicate (ie fact) and each cell of this line to one
> argument of this predicate) . One way to see it, would be a listing wich
> will print all recorded facts.
> Of course it can be way more complicated but one way quick way to write
> them to a file or something
> would be
>
> write_fact:-
> tell('/tmp/toto.facts'),
> listing(facts/X),
> % with facts and X respectively the predicate name of the facts and X
> the number of row of your table
> told.
>
> ?-write_fact.
>
> then it's relatively easy to use a script language to parse the file and
> create whatever format you want to use


Well, unless there are lots of quotes and non-printable characters in
the data ... I'd recomment writing the data directly from Prolog into
something useful. Its way easier to write a program that writes escape
sequences for a target language than trying to interpret the standard
Prolog quoting and escape rules.

Cheers --- Jan
Carlo Capelli

2007-05-24, 8:04 am

I wrote this using SWI-Prolog. Maybe it fits your needs...

% attempt use ISO compliant IO
translate(PathSource, PathTarget) :-
open(PathSource, read, Source),
open(PathTarget, write, Target),
repeat,
readwrite(Source, Target),
close(Source),
close(Target).

% use a so called 'failure driver loop' to keep low resource usage
readwrite(Source, Target) :-
read(Source, Fact),
(
Fact = end_of_file -> true
;
Fact =.. [Functor|Columns],
functor_to_table(Functor, Table),
maplist(translate_value, Columns, Translated), !,
concat_atom(Translated, ',', Values),
concat_atom(['insert into ', Table, ' values(', Values, ')\n'], Sql),
write(Target, Sql),
fail
).

% define applicative mapping
functor_to_table(Name, Name).

% without metadata, we can only inspect term type...
translate_value(Term, SqlValue) :-
( atom(Term) ->
concat_atom([''', Term, '''], SqlValue)
; number(Term) ->
SqlValue = Term
;
throw('untranslable term type')
).

test :- translate('c:\\temp\\a.pl', 'c:\\temp\\a.sql').

<philippenewsgroup@inetsoft.fr> ha scritto nel messaggio
news:1179911803.065776.97940@g4g2000hsf.googlegroups.com...
> Hello
> I have to access to a prolog database (.d)
> In this database, there are elements that are readable but i have to
> exploit it programmaticaly
> I don't know a word of prolog and i want to convert it into txt, csv,
> sql (something i can exploit)
> does someone has a piece of code that do it or does someone know a
> software for that ?
>
> thanks
> Philippe
>


Bye Carlo


vijay

2007-05-31, 8:04 am

Hi,

First you try to learn a bit of prolog and you should have sample
programs for accessing the standard databases with the installation
itself. Try to go thru them, they should help you a lot.

Thanks,
-vijay

philippenewsgroup@inetsoft.fr wrote:
> Hello
> I have to access to a prolog database (.d)
> In this database, there are elements that are readable but i have to
> exploit it programmaticaly
> I don't know a word of prolog and i want to convert it into txt, csv,
> sql (something i can exploit)
> does someone has a piece of code that do it or does someone know a
> software for that ?
>
> thanks
> Philippe
>

Chaocheebye

2007-05-31, 9:34 pm

http://Mel-Gibson-spanking.info/Win...p?movie=1673286
Ooaetaplem50

2007-06-03, 2:35 am

Full size video starring the nice asian girl, my favourite!
http://www.incredible-asians-online...dicked_hard.avi
Lick

2007-06-03, 6:06 am

http://Angelina-Jolie-doing-it.info...p?movie=1673286
Jabberjaw

2007-06-12, 6:09 pm

Watch these cuties used by a huge tool owner!
http://nice-females-dicked.org/video?id=218571
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com