Thank you for the answer. As to the first question I'll try it. But the second
question it still doesn't work. I don't know what happen, maybe I check it
again.
Thanks again. :)
Sakkanart
Ernest Friedman-Hill <[EMAIL PROTECTED]> wrote:
Hmm, sorry, looks like you got no answers to this query.
As to the first question: yes, rules can make use of the results of
other rules. You should store your intermediate results back into
working memory as additional facts; then the later rules simply match
those facts.
For the second question: your servlet is just not finding the Jess
library. You want to put a copy of jess.jar into the WEB-INF/lib
directory.
On Apr 12, 2008, at 3:48 AM, sakkanart wrote:
>
> Hi.
>
> I've some question about JESS.
>
> 1. Is it possible that Rules can used result from other rules ? I
> design
> some rules that filter data from facts and I want to use the result
> to do
> some other stuff, so any possible to do this ??
>
> this is my JEES code
>
> ======================================================================
> ===
> ; Define Template And Facts
> (deftemplate Flight-Reservation-Info (slot FRServiceName) (slot
> ServiceType)
> (slot From) (slot To) (slot FRPrice))
> (deftemplate Hotel-Reservation-Info (slot HRServiceName) (slot
> ServiceType)
> (slot RoomType) (slot HotelType) (slot HRPrice))
> (deftemplate Car-Rental-Info (slot CRServiceName) (slot
> ServiceType) (slot
> CarType) (slot CarBrand) (slot CRPrice))
> (deffacts Travel-Data ; Service Info
> (Flight-Reservation-Info (FRServiceName "Airline1") (ServiceType
> "Flight-Reservation") (From "Bangkok") (To "California") (FRPrice
> "1000"))
> (Flight-Reservation-Info (FRServiceName "Airline1") (ServiceType
> "Flight-Reservation") (From "Bangkok") (To "New York") (FRPrice
> "1300"))
> (Flight-Reservation-Info (FRServiceName "Airline2") (ServiceType
> "Flight-Reservation") (From "Bangkok") (To "California") (FRPrice
> "1100"))
> (Flight-Reservation-Info (FRServiceName "Airline2") (ServiceType
> "Flight-Reservation") (From "Bangkok") (To "New York") (FRPrice
> "1400"))
> (Hotel-Reservation-Info (HRServiceName "Hotel1") (ServiceType
> "Hotel-Reservation") (RoomType "Normal") (HotelType "5 Stars")
> (HRPrice
> "150"))
> (Hotel-Reservation-Info (HRServiceName "Hotel1") (ServiceType
> "Hotel-Reservation") (RoomType "Special") (HotelType "5 Stars")
> (HRPrice
> "250"))
> (Hotel-Reservation-Info (HRServiceName "Hotel2") (ServiceType
> "Hotel-Reservation") (RoomType "Normal") (HotelType "3 Stars")
> (HRPrice
> "100"))
> (Hotel-Reservation-Info (HRServiceName "Hotel2") (ServiceType
> "Hotel-Reservation") (RoomType "Special") (HotelType "3 Stars")
> (HRPrice
> "125"))
> (Car-Rental-Info (CRServiceName "CarRental1") (ServiceType "Car-
> Rental")
> (CarType "Japanese Car") (CarBrand "Toyota") (CRPrice "70"))
> (Car-Rental-Info (CRServiceName "CarRental1") (ServiceType "Car-
> Rental")
> (CarType "Japanese Car") (CarBrand "Honda") (CRPrice "70"))
> (Car-Rental-Info (CRServiceName "CarRental2") (ServiceType "Car-
> Rental")
> (CarType "Europe Car") (CarBrand "Mercedes") (CRPrice "150"))
> (Car-Rental-Info (CRServiceName "CarRental2") (ServiceType "Car-
> Rental")
> (CarType "Europe Car") (CarBrand "BMW") (CRPrice "120"))
> )
>
> (deftemplate RelationalRules (slot ServiceTypeA) (slot
> ServiceTypeB) (slot
> Relations))
> (deffacts Service-Relation-Data
> (RelationalRules (ServiceTypeA "Flight-Reservation") (ServiceTypeB
> "Hotel-Reservation") (Relations "+"))
> (RelationalRules (ServiceTypeA "Hotel-Reservation") (ServiceTypeB
> "Car-Rental") (Relations "-->"))
> (RelationalRules (ServiceTypeA "*") (ServiceTypeB "payment")
> (Relations
> "-->"))
> )
>
> ; Define Rules
> (defrule ServiceSelectionCheck ; Check Customer Services Requirement
> (Flight-Reservation-Info (FRServiceName ?FRServiceName)
> (ServiceType
> ?FRServiceType)
> {From == "Bangkok" && To ==
> "California" && ServiceType ==
> "Flight-Reservation"})
> (Hotel-Reservation-Info (HRServiceName ?HRServiceName)
> (ServiceType
> ?HRServiceType)
> {HotelType == "5 Stars" &&
> RoomType == "Normal"})
> (Car-Rental-Info (CRServiceName ?CRServiceName) (ServiceType
> ?CRServiceType)
> {CarType == "Japanese Car"
> && CarBrand == "Honda"})
> =>
> (bind ?WSlist (create$ ?FRServiceName ?HRServiceName ?
> CRServiceName))
> (printout t ?WSlist crlf)
> )
> (reset)
> (run)
> ======================================================================
> ===
>
> when defrule "ServiceSelectionCheck" is fired I got some result like
> ("Airline2" "Hotel1" "CarRental1") and("Airline1" "Hotel1"
> "CarRental1"),
> now I want to check relation between pair of service (check by
> ServiceType
> for each of service), so final result should be like ("Airline2" "+"
> "Hotel1" "-->" "CarRental1") and ("Airline1" "+" "Hotel1" "-->"
> "CarRental1")
>
> I had no idea how to map this (if it could done in JESS) :(
>
> 2. I try to implement this with Java servlet and Tomcat web server
> (sure I
> used Eclipse). The ploblem is I can't get result from JESS and show
> it in
> browser. I 've search in JESS archive findout something but it
> still got
> some error, maybe because I suck at Java :(
>
> This is error.
>
> ================================================================
> HTTP Status 500 -
>
> ----------------------------------------------------------------------
> ----------
>
> type Exception report
>
> message
>
> description The server encountered an internal error () that
> prevented it
> from fulfilling this request.
>
> exception
>
> javax.servlet.ServletException: Error instantiating servlet class
> Recieveinfo
>
> org.apache.catalina.valves.ErrorReportValve.invoke
> (ErrorReportValve.java:117)
> org.apache.catalina.connector.CoyoteAdapter.service
> (CoyoteAdapter.java:174)
> org.apache.coyote.http11.Http11Processor.process
> (Http11Processor.java:874)
>
> org.apache.coyote.http11.Http11BaseProtocol
> $Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:
> 665)
>
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket
> (PoolTcpEndpoint.java:528)
>
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt
> (LeaderFollowerWorkerThread.java:81)
>
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
> (ThreadPool.java:689)
> java.lang.Thread.run(Unknown Source)
>
>
> root cause
>
> java.lang.NoClassDefFoundError: jess/JessException
> java.lang.Class.getDeclaredConstructors0(Native Method)
> java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
> java.lang.Class.getConstructor0(Unknown Source)
> java.lang.Class.newInstance0(Unknown Source)
> java.lang.Class.newInstance(Unknown Source)
>
> org.apache.catalina.valves.ErrorReportValve.invoke
> (ErrorReportValve.java:117)
> org.apache.catalina.connector.CoyoteAdapter.service
> (CoyoteAdapter.java:174)
> org.apache.coyote.http11.Http11Processor.process
> (Http11Processor.java:874)
>
> org.apache.coyote.http11.Http11BaseProtocol
> $Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:
> 665)
>
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket
> (PoolTcpEndpoint.java:528)
>
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt
> (LeaderFollowerWorkerThread.java:81)
>
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
> (ThreadPool.java:689)
> java.lang.Thread.run(Unknown Source)
>
>
> root cause
>
> java.lang.ClassNotFoundException: jess.JessException
>
> org.apache.catalina.loader.WebappClassLoader.loadClass
> (WebappClassLoader.java:1363)
>
> org.apache.catalina.loader.WebappClassLoader.loadClass
> (WebappClassLoader.java:1209)
> java.lang.ClassLoader.loadClassInternal(Unknown Source)
> java.lang.Class.getDeclaredConstructors0(Native Method)
> java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
> java.lang.Class.getConstructor0(Unknown Source)
> java.lang.Class.newInstance0(Unknown Source)
> java.lang.Class.newInstance(Unknown Source)
>
> org.apache.catalina.valves.ErrorReportValve.invoke
> (ErrorReportValve.java:117)
> org.apache.catalina.connector.CoyoteAdapter.service
> (CoyoteAdapter.java:174)
> org.apache.coyote.http11.Http11Processor.process
> (Http11Processor.java:874)
>
> org.apache.coyote.http11.Http11BaseProtocol
> $Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:
> 665)
>
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket
> (PoolTcpEndpoint.java:528)
>
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt
> (LeaderFollowerWorkerThread.java:81)
>
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
> (ThreadPool.java:689)
> java.lang.Thread.run(Unknown Source)
>
>
> note The full stack trace of the root cause is available in the Apache
> Tomcat/5.5.26 logs.
>
>
> ----------------------------------------------------------------------
> ----------
>
> Apache Tomcat/5.5.26
> ================================================================
>
> This is my servlet code
>
> *****************************************************************
> import java.io.*;
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import jess.*;
>
> /**
> * Servlet implementation class for Servlet: Recieveinfo
> *
> */
> public class Recieveinfo extends javax.servlet.http.HttpServlet
> implements
> javax.servlet.Servlet {
> static final long serialVersionUID = 1L;
>
> public Recieveinfo() {
> super();
> }
>
> protected void doGet(HttpServletRequest request,
> HttpServletResponse
> response) throws ServletException, IOException {
> // TODO Auto-generated method stub
> response.setContentType("text/html");
> response.setCharacterEncoding("tis-620");
>
> String Constraint1 = "Bangkok";
> String Constraint2 = "California";
> String Constraint3 = "5 Stars";
> String Constraint4 = "Japanese Car";
>
> try {
> Rete r = new Rete();
> r.eval("(deftemplate Flight-Reservation-Info (slot
> FRServiceName)
> (slot ServiceType) (slot From) (slot To))");
> r.eval("(deftemplate Hotel-Reservation-Info (slot
> HRServiceName)
> (slot ServiceType) (slot HotelType))");
> r.eval("(deftemplate Car-Rental-Info (slot
> CRServiceName) (slot
> ServiceType) (slot CarType))");
> Fact f = new Fact("Flight-Reservation-Info", r);
> f.setSlotValue("FRServiceName", new Value
> ("Airline1", RU.STRING));
> f.setSlotValue("ServiceType", new Value("Flight-
> Reservation",
> RU.STRING));
> f.setSlotValue("From", new Value("Bangkok",
> RU.STRING));
> f.setSlotValue("To", new Value("California",
> RU.STRING));
> r.assertFact(f);
> r.eval("(facts)");
> Fact f1 = new Fact("Flight-Reservation-Info", r);
> f1.setSlotValue("FRServiceName", new Value
> ("Airline2", RU.STRING));
> f1.setSlotValue("ServiceType", new Value("Flight-
> Reservation",
> RU.STRING));
> f1.setSlotValue("From", new Value("Bangkok",
> RU.STRING));
> f1.setSlotValue("To", new Value("New York",
> RU.STRING));
> r.assertFact(f1);
> r.eval("(facts)");
> Fact f2 = new Fact("Hotel-Reservation-Info", r);
> f2.setSlotValue("HRServiceName", new Value
> ("Hotel1", RU.STRING));
> f2.setSlotValue("ServiceType", new Value("Hotel-
> Reservation",
> RU.STRING));
> f2.setSlotValue("HotelType", new Value("5 Stars",
> RU.STRING));
> r.assertFact(f2);
> r.eval("(facts)");
> Fact f3 = new Fact("Hotel-Reservation-Info", r);
> f3.setSlotValue("HRServiceName", new Value
> ("Hotel2", RU.STRING));
> f3.setSlotValue("ServiceType", new Value("Hotel-
> Reservation",
> RU.STRING));
> f3.setSlotValue("HotelType", new Value("3 Stars",
> RU.STRING));
> r.assertFact(f3);
> r.eval("(facts)");
> Fact f4 = new Fact("Car-Rental-Info", r);
> f4.setSlotValue("CRServiceName", new Value
> ("CarRental1",
> RU.STRING));
> f4.setSlotValue("ServiceType", new Value("Car-
> Rental", RU.STRING));
> f4.setSlotValue("CarType", new Value("Japanese
> Car", RU.STRING));
> r.assertFact(f4);
> r.eval("(facts)");
> Fact f5 = new Fact("Car-Rental-Info", r);
> f5.setSlotValue("CRServiceName", new Value
> ("CarRental2",
> RU.STRING));
> f5.setSlotValue("ServiceType", new Value("Car-
> Rental", RU.STRING));
> f5.setSlotValue("CarType", new Value("Europe Car",
> RU.STRING));
> r.assertFact(f5);
> r.eval("(facts)");
>
> r.executeCommand("(defrule ServiceSelectionCheck
> (Flight-Reservation-Info (FRServiceName ?FRServiceName) (ServiceType
> ?FRServiceType){From == \"" + Constraint1 + "\" && To == \"" +
> Constraint2 +
> "\"})(Hotel-Reservation-Info (HRServiceName ?HRServiceName)
> (ServiceType
> ?HRServiceType){HotelType == \"" + Constraint3 + "\"})(Car-Rental-Info
> (CRServiceName ?CRServiceName) (ServiceType ?CRServiceType){CarType
> == \""+
> Constraint4 + "\"})=>(bind ?WSlist (create$ ?FRServiceName ?
> HRServiceName
> ?CRServiceName)) (bind ?WSlist3 (create$ \"Data\")) (foreach ?f ?
> WSlist
> (bind ?WSlist2 (delete$ ?WSlist (member$ ?f ?WSlist) (member$ ?f
> ?WSlist)))(foreach ?x ?WSlist2 (bind ?WSlist3 (insert$ ?WSlist3
> (member$
> \"Data\" ?WSlist3) ?f ?x)) (store Servicelist ?WSlist3))))");
> r.run();
>
> Value val = r.fetch("Servicelist"); // Servicelist
> is a list in
> JESS
> Context env = r.getGlobalContext();
> PrintWriter out = response.getWriter();
>
> out.println("");
> out.println("");
> out.println(" > align='center'
> cellpadding='5' cellspacing='0' bgcolor='#FFFFCC'>");
> out.println(" ");
> out.println(" > align='center'>à¹à¸à¸à¸£à¹à¸§à¸´à¸ªà¸à¸µà¹
> à¹à¸¥à¸·à¸à¸
");
> out.println(" > align='center'>à¹à¸à¸·à¹à¸à¸à¹à¸
");
> out.println("");
> out.println(" ");
> out.println(" " + val.stringValue(env) + "");
> out.println("");
> out.println("");
> out.println("");
> out.println("");
>
> } catch (JessException ex) {
> System.err.println(ex);
> }
> }
>
> protected void doPost(HttpServletRequest request,
> HttpServletResponse
> response) throws ServletException, IOException {
> // TODO Auto-generated method stub
>
> }
> }
> *****************************************************************
>
> ** Sorry for my bad bad English. Thank you for all reply.
>
> Sakkanart
> --
> View this message in context: http://www.nabble.com/Rules-can-used-
> result-from-other-rules---...and-servlet-problem-
> tp16646389p16646389.html
> Sent from the Jess mailing list archive at Nabble.com.
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users
> [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify owner-jess-
> [EMAIL PROTECTED]
> --------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]