Quintus to SWI-prolog conversion

View: New views
5 Messages — Rating Filter:   Alert me  

Quintus to SWI-prolog conversion

by Pauline Kra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

 

I am trying to convert to SWI-prolog a parser which is written in Quintus prolog. Our program extracts information from journal articles in molecular biology. We currently use the Quintus read_in/1 predicate to input an article as a Prolog list. What SWI-prolog predicate could we use to read in the articles?

 

 

Thank you for your help.

 

Pauline


Re: Quintus to SWI-prolog conversion

by Jan Wielemaker-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 28 May 2008 17:40:26 Pauline Kra wrote:
> Hello,
>
> I am trying to convert to SWI-prolog a parser which is written in Quintus
> prolog. Our program extracts information from journal articles in molecular
> biology. We currently use the Quintus read_in/1 predicate to input an
> article as a Prolog list. What SWI-prolog predicate could we use to read in
> the articles?

I don't know what read_in/1 does exactly, but I suggest to have a look
at library(readutil).

        Cheers --- Jan

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Quintus to SWI-prolog conversion

by Richard O'Keefe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 29 May 2008, at 3:40 am, Pauline Kra wrote:
> I am trying to convert to SWI-prolog a parser which is written in  
> Quintus Prolog. Our program extracts information from journal  
> articles in molecular biology. We currently use the Quintus read_in/
> 1 predicate to input an article as a Prolog list. What SWI-prolog  
> predicate could we use to read in the articles?

library(read_in) is just 90 lines.
If you throw away the module declaration, the comments,
and the blank lines, there are just 46 lines left.
It was derived from the DEC-10 Prolog library, and
honestly, there wasn't a lot of difference.

Hmm.  This needs to be modernised anyway, so here is a
modernised version.

NOTE:  while typing this in, I ran into a rather nasty lexical
bug in SWI Prolog:
        ?- X = 0' .
        ERROR: Syntax error: Unexpected end of file
        ERROR: X = 0'
        ERROR: ** here **
        ERROR:
I need hardly point out that there is no EOF here.
Quintus provided \s for a visible space, but 0'\s
gives you the code for "s" instead of " ", so pace Bart
Demoen if you want a space code, it's
        X = 32 /* space */
or X is " "

I have *not* had time to test this code.  In particular, it
refers to predicates
        is_white_space/1
        is_letter/1
        is_digit/1
which have to be filled in by the reader, and there are
dealings with "_" which might not be appropriate for the
original poster's application.  (People were always *meant*
to feel free to take the Quintus library and adapt and
extend it for their own needs.)  Also, you might prefer
a different response to EOF.


read_in(Words) :-
     get_code(C),
     read_in_sentence(C, Words).

read_in_sentence(C, Words) :-
     (   C < 0 ->
        Words = ['']
     ;   is_white_space(C) -> % originally, C <= " "
        get_code(D),
        read_in_sentence(D, Words)
     ;   Words = [Word|Words1],
        (   C =:= 0'. ->
            Word = .,
            get_code(F),
            read_in_after_stop(F, Words1)
        ;   C =:= 0'! ->
            Word = !,
            get_code(F),
            read_in_after_stop(F, Words1)
        ;   C =:= 0'? ->
            Word = ?,
            get_code(F),
            read_in_after_stop(F, Words1)
        ;   is_letter(C) ->
            get_code(E),
            read_in_word(E, Codes, F),
            atom_codes(Word, Codes),
            read_in_sentence(F, Words1)
        ;   is_digit(C) ->
            get_code(E),
            read_in_number(E, Codes, F),
            number_codes(Word, [C|Codes]),
            read_in_sentence(F, Words1)
        ;   get_code(F),
            atom_codes(Word, [C]),
            read_in_sentence(F, Words1)
        )
     ).


read_in_after_stop(C, Words1) :-
     (   is_white_space(C) ->
        (   C =:= "\n" ->
            Words1 = []
        ;   get_code(D),
            read_in_after_stop(D, Words1)
        )
     ;   read_in_sentence(C, Words1)
     ).


read_in_word(C, Codes, F) :-
     (   is_letter(C) ->
        to_lower(C, L),
        Codes = [L|Codes1],
        get_code(D),
        read_in_word(D, Codes1, F)
     ;   (is_digit(C) ; C =:= 0'_) ->
        Codes = [C|Codes1],
        get_code(D),
        read_in_word(D, Codes1, F)
     ;   Codes = [], F = C
     ).


read_in_number(C, Digits, F) :-
     (   is_digit(C) ->
        Digits = [C|Digits1],
        get_code(D),
        read_in_number(D, Digits1, F)
     ;   C =:= 0'_ ->
        get_code(D),
        read_in_number(D, Digits, F)
     ;   Digits = [], F = C
     ).





_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Quintus to SWI-prolog conversion

by Ulrich Neumerkel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> NOTE:  while typing this in, I ran into a rather nasty lexical
> bug in SWI Prolog:
>         ?- X = 0' .
>         ERROR: Syntax error: Unexpected end of file
>         ERROR: X = 0'
>         ERROR: ** here **
>         ERROR:

This problem has been present prior to 5.6.40.  Now:

[ulrich@gupu ~]$ /opt/gupu/pl-life-gc/bin/pl -f none
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.6.55)
Copyright (c) 1990-2008 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
 
For help, use ?- help(Topic). or ?- apropos(Word).
 
?- X = 0' .
X = 32.

You might be interested to upgrade. Recent versions contain for
example a better occurs-check.
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

compiling in Windows

by Pauline Kra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone,

With the read_in module Richard sent me I am running successfully in
SWI-prolog a parser which was originally written for Quintus prolog.
My question is how to compile the program in Windows.
The commands in the Manual section 2.10.2.4 do produce myprog.exe,
but trying to run it gives the error:
"The procedure entry point PL_warning could not be located in the dynamic
link library libpl.dll."
My start.pl file is the following:
#!/'c:/program files/pl'

start :-

['c:/rapport/switesting/load.pl'],

['c:/rapport/switesting/lexicon.pl'],

 autoload.



I shall be very grateful for your instructions how to do it right.

Pauline

>
> library(read_in) is just 90 lines.
> If you throw away the module declaration, the comments,
> and the blank lines, there are just 46 lines left.
> It was derived from the DEC-10 Prolog library, and
> honestly, there wasn't a lot of difference.
>
> Hmm.  This needs to be modernised anyway, so here is a
> modernised version.
>
> NOTE:  while typing this in, I ran into a rather nasty lexical
> bug in SWI Prolog:
> ?- X = 0' .
> ERROR: Syntax error: Unexpected end of file
> ERROR: X = 0'
> ERROR: ** here **
> ERROR:
> I need hardly point out that there is no EOF here.
> Quintus provided \s for a visible space, but 0'\s
> gives you the code for "s" instead of " ", so pace Bart
> Demoen if you want a space code, it's
> X = 32 /* space */
> or X is " "
>
> I have *not* had time to test this code.  In particular, it
> refers to predicates
> is_white_space/1
> is_letter/1
> is_digit/1
> which have to be filled in by the reader, and there are
> dealings with "_" which might not be appropriate for the
> original poster's application.  (People were always *meant*
> to feel free to take the Quintus library and adapt and
> extend it for their own needs.)  Also, you might prefer
> a different response to EOF.
>
>
> read_in(Words) :-
>      get_code(C),
>      read_in_sentence(C, Words).
>
> read_in_sentence(C, Words) :-
>      (   C < 0 ->
> Words = ['']
>      ;   is_white_space(C) -> % originally, C <= " "
> get_code(D),
> read_in_sentence(D, Words)
>      ;   Words = [Word|Words1],
> (   C =:= 0'. ->
>     Word = .,
>     get_code(F),
>     read_in_after_stop(F, Words1)
> ;   C =:= 0'! ->
>     Word = !,
>     get_code(F),
>     read_in_after_stop(F, Words1)
> ;   C =:= 0'? ->
>     Word = ?,
>     get_code(F),
>     read_in_after_stop(F, Words1)
> ;   is_letter(C) ->
>     get_code(E),
>     read_in_word(E, Codes, F),
>     atom_codes(Word, Codes),
>     read_in_sentence(F, Words1)
> ;   is_digit(C) ->
>     get_code(E),
>     read_in_number(E, Codes, F),
>     number_codes(Word, [C|Codes]),
>     read_in_sentence(F, Words1)
> ;   get_code(F),
>     atom_codes(Word, [C]),
>     read_in_sentence(F, Words1)
> )
>      ).
>
>
> read_in_after_stop(C, Words1) :-
>      (   is_white_space(C) ->
> (   C =:= "\n" ->
>     Words1 = []
> ;   get_code(D),
>     read_in_after_stop(D, Words1)
> )
>      ;   read_in_sentence(C, Words1)
>      ).
>
>
> read_in_word(C, Codes, F) :-
>      (   is_letter(C) ->
> to_lower(C, L),
> Codes = [L|Codes1],
> get_code(D),
> read_in_word(D, Codes1, F)
>      ;   (is_digit(C) ; C =:= 0'_) ->
> Codes = [C|Codes1],
> get_code(D),
> read_in_word(D, Codes1, F)
>      ;   Codes = [], F = C
>      ).
>
>
> read_in_number(C, Digits, F) :-
>      (   is_digit(C) ->
> Digits = [C|Digits1],
> get_code(D),
> read_in_number(D, Digits1, F)
>      ;   C =:= 0'_ ->
> get_code(D),
> read_in_number(D, Digits, F)
>      ;   Digits = [], F = C
>      ).
>
>
>
>
>
> _______________________________________________
> SWI-Prolog mailing list
> SWI-Prolog@...
> https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
LightInTheBox - Buy quality products at wholesale price