Prolog digit to word conversion help 
Author Message
 Prolog digit to word conversion help

I need a predicate that will take a given list and convert its values into
english words.  For example:

    translate(N,T).

where N is a list of digits and T is the translated list, for example:

    translate([3,5,2,8],L).

will return

    L=[three,five,two,eight]

Any suggestions or ideas will be greatly appreciated.
-Mike



Sat, 23 Apr 1994 15:04:29 GMT  
 Prolog digit to word conversion help

Quote:

> I need a predicate that will take a given list and convert its values into
> english words.  

[ ... ]

Quote:
> for example:

>     translate([3,5,2,8],L).

> will return

>     L=[three,five,two,eight]

Does anyone else share my feeling that this looks suspiciously like
a homework assignment in an intro Prolog course?

--
Saumya Debray           CS Department, University of Arizona, Tucson


     uucp:       uunet!arizona!debray



Sat, 23 Apr 1994 23:36:17 GMT  
 Prolog digit to word conversion help

   I need a predicate that will take a given list and convert its values into
   english words.  For example:

       translate([3,5,2,8],L).

   will return

       L=[three,five,two,eight]

this sure _sounds_ like homework.

but what the hell ...

program follows, don't peek if you are doing homework

translate_digit(one, 1).
translate_digit(two, 2).
translate_digit(three, 3).
translate_digit(four, 4).
translate_digit(five, 5).
translate_digit(six, 6).
translate_digit(seven, 7).
translate_digit(eight, 8).
translate_digit(nine, 9).
translate_digit(zero, 0).

translate([], []).
translate([D|Ds], [W|Ws]) :-
        translate_digit(D,W),
        translate(Ds, Ws).

                - or, more slowly in most prologs -

translate(L, D) :- bagof(X, Y^(member(Y,L), translate_digit(Y,X)), D).



Sun, 24 Apr 1994 05:35:46 GMT  
 Prolog digit to word conversion help
so much so for the home work problem.

i suspected that something was wrong with the code. tried it on
Quintus prolog.

i have corrected the program here ..........

translate_digit(1, one).
translate_digit(2, two).
translate_digit(3, three).
translate_digit(4, four).
translate_digit(5, five).
translate_digit(6, six).
translate_digit(7, seven).
translate_digit(8, eight).
translate_digit(9, nine).
translate_digit(0, zero).

translate([], []).
translate([D|Ds], [W|Ws]) :-
        translate_digit(D,W),
        translate(Ds, Ws).

good work, though.

ramesh

--------------------------------------------------------------------
USMail: 608 Dreese Labs, 2015 Neil Av.,   |    
        The Ohio State University,        |    613, Tuscarawas Ct.
        Columbus, OH 43210                |    Columbus, OH 43210
Phone: (614)-292-2906                     |    (614)-293-0019


--------------------------------------------------------------------



Mon, 25 Apr 1994 07:21:05 GMT  
 Prolog digit to word conversion help

Quote:

> I need a predicate that will take a given list and convert its values into
> english words.  For example:

>     translate(N,T).

> where N is a list of digits and T is the translated list, for example:

>     translate([3,5,2,8],L).

> will return

>     L=[three,five,two,eight]

> Any suggestions or ideas will be greatly appreciated.
> -Mike

I think the following is the solution for your problem:

means(0, zero).
means(1, one).
means(2, two).
means(3, three).
means(4, four).
means(5, five).
means(6, six).
means(7, seven).
means(8, eight).
means(9, nine).

translate([],[]).
translate([Head|Tail], [Head1|Tail1]) :-
        means(Head,Head1),
        translate(Tail,Tail1).

I hope that this is what you want.

Bye

P.S.: Pleas excuse my English, cause I am not very well in this.



Tue, 26 Apr 1994 00:33:33 GMT  
 Prolog digit to word conversion help
Having seen the third implementation of translate/2, I'd like to point out
that Prolog systems usually have a built-in or library predicate map/3,
which, with facts like
   word_of(0, zero).
   word_of(1, one).
   ...
can be used as in the query
   :- map(word_of, [3,5,2,8], Words).
which yields the desired result
   Words = [three,five,two,eight]

Another often-seen example is a predicate like
   double(X, Y) :- Y is X+X.
The query
   :- map(double, [3,5,2,8], Ds).
results in
   Ds = [6,10,4,16]

In its simplest form (where the map function has only two parameters),
map/3 is of course implemented similar to the translate/2 predicate.

   map(_, [], []).
   map(P, [X|Xs], [Y|Ys]) :-
     P(X, Y),
     map(P, Xs, Ys).

Markus Fromherz





Tue, 26 Apr 1994 22:17:53 GMT  
 Prolog digit to word conversion help


writes:

Quote:
>   map(_, [], []).
>   map(P, [X|Xs], [Y|Ys]) :-
>     P(X, Y),
>     map(P, Xs, Ys).

This may work on some Prologs, but in others it is necessary to do a bit
more work to construct the function call:

map(_,[],[]).

map(P,[X|Xs],[Y|Ys]) :-
        functor(T,P,2),
        arg(1,T,X),
        arg(2,T,Y),
        call(T),
        map(P,Xs,Ys).

Now then: any more homework you want us to do while we're at it?

--
Ken Johnson, A I Applications Institute //// ``Always keep cool''
80 South Bridge, EDINBURGH EH1 1HN      ////    (Wm Low's ham sandwich wrapper)

031-650 2756 direct line                //// Muslims say: Hands Off Shoplifters



Sat, 30 Apr 1994 00:39:33 GMT  
 Prolog digit to word conversion help

Quote:

>    I need a predicate that will take a given list and convert its values into
>    english words.  For example:
>        translate([3,5,2,8],L).
>    will return
>        L=[three,five,two,eight]
> this sure _sounds_ like homework.

> but what the hell ...
> program follows, don't peek if you are doing homework

I am sure the Prolog problem was a psychological test of hacking responses
amongst AI programmers. You were supposed to show restraint and professional
integrity rather than jumping into solving the trivial 1st year Prolog
assignment.  Noughty, noughty hacker you are!

Jacob



Fri, 29 Apr 1994 12:03:48 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Problem: More Low Digits in String to Float conversion

2. Conversion of UPC numbers from 13 to 15 digits

3. Word 97 and word 2000 - calling from clarion - HELP

4. Batch conversion of MS-WORD *.DOC files

5. Amount to words conversion

6. real to word conversion

7. Useful words for C-to-Forth conversion

8. Word to PDF file conversion

9. Help Needed, J "Digits" function

10. help-Orexx and numeric digits

11. adding 2 double digit numbers HELP

12. Student needs help wtih Modulo 11 check digit.

 

 
Powered by phpBB® Forum Software