Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 12th, 2006, 04:52 PM
javaWalk javaWalk is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: NY
Posts: 79 javaWalk Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 3 h 31 m 21 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Question Prolog problem

How should I go about modifying this code to be able to perform arithmetic operations on the numerical values?

Code:
% File:  e.p
%      - convert a text number to a numeral
%      - Using grammars
%      - Extracting "value" from sentence (semantics)
%      - removes restriction that all numbers of form dddd
%      - handles "teens"

:- consult('aux.p').

cvt :- 
  read_sentence(Sentence),
  butlast(Sentence,Sentenc),
  Sentenc \== [quit],
  write_sentence(Sentenc), !,
  (
     phrase(four_digit(Value),Sentenc,[]),
     write_string(" -- translation succeeded"),
     nl,
     write_string("yielding value "),
     write(Value),
     write_string(" decimal.");
     write_string(" -- translation failed")
  ),
  nl,
  cvt.

cvt.

four_digit(Value) -->
   thousands(V1), three_digit(V2), {Value is 1000 * V1 + V2}.

three_digit(Value) -->
   hundreds(V1), two_digit(V2), {Value is 100 * V1 + V2}.

two_digit(Value) --> tens(V1), one_digit(V2), {Value is 10 * V1 + V2}.
two_digit(Value) --> teens(V), {Value is V}.

one_digit(Value) --> ones(V), {Value is V}.

thousands(Value) --> digit(V), thousand, {Value is V}.
thousands(0) --> [].

hundreds(Value) --> digit(V), hundred, {Value is V}.
hundreds(0) --> [].

tens(Value) --> digity_thing(V), {Value is V}.
tens(0) --> [].

teens(Value) --> teen_thing(V), {Value is V}.

ones(Value) --> digit(V), {Value is V}.
ones(0) --> [].

thousand --> [thousand].
hundred --> [hundred].

digity_thing(2) --> [twenty].
digity_thing(3) --> [thirty].
digity_thing(4) --> [forty].
digity_thing(5) --> [fifty].
digity_thing(6) --> [sixty].
digity_thing(7) --> [seventy].
digity_thing(8) --> [eighty].
digity_thing(9) --> [ninety].

teen_thing(10) --> [ten].
teen_thing(11) --> [eleven].
teen_thing(12) --> [twelve].
teen_thing(13) --> [thirteen].
teen_thing(14) --> [fourteen].
teen_thing(15) --> [fifteen].
teen_thing(16) --> [sixteen].
teen_thing(17) --> [seventeen].
teen_thing(18) --> [eighteen].
teen_thing(19) --> [nineteen].

digit(1) --> [one].
digit(2) --> [two].
digit(3) --> [three].
digit(4) --> [four].
digit(5) --> [five].
digit(6) --> [six].
digit(7) --> [seven].
digit(8) --> [eight].
digit(9) --> [nine].

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Prolog problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway