Worked wonderfully. Thank you Ernest. On Mon, Jul 18, 2011 at 10:05 AM, Ernest Friedman-Hill <ejfr...@sandia.gov>wrote:
> I believe the issue is the classic one that RU.SYMBOL and RU.STRING are > different data types. Your DimmerSwitch properties are quoted strings > (RU.STRING) but your query parameters are created using > > > new ValueVector().add("Ceiling Light") >> > > which creates a Value of type RU.SYMBOL. You want to explictly create > STRINGS: > > > new ValueVector().add(new Value("Ceiling Light", RU.STRING)) >> > > > and that should fix the problem. > > > > On Jul 17, 2011, at 8:30 PM, Felix Chan wrote: > > Hi all, >> >> I am wondering if someone could help me understand why runQueryStar would >> not work for me in a certain scenario. Thank you in advance! >> >> First, I have the following script. It works as expected: >> >> (deftemplate DimmerSwitch (slot label) (slot brightness)) >> (defquery search-dimmer-switch >> (declare (variables ?lbl)) >> (DimmerSwitch (label ?lbl) (brightness ?b)) >> ) >> (defrule set-brightness-to-10-and-15 >> (not (DimmerSwitch)) >> => >> (assert (DimmerSwitch (label "Ceiling Light") (brightness 10))) >> (assert (DimmerSwitch (label "Bathroom Light") (brightness 5))) >> ) >> >> (reset) >> (run) >> (facts) >> (bind ?result (run-query* search-dimmer-switch "Ceiling Light")) >> (while (?result next) >> (printout t (?result getString lbl) " | " (?result getInt b) crlf) >> ) >> >> The output is as follows. No problem there. >> f-0 (MAIN::initial-fact) >> >> f-1 (MAIN::DimmerSwitch (label "Ceiling Light") (brightness 10)) >> >> f-2 (MAIN::DimmerSwitch (label "Bathroom Light") (brightness 5)) >> >> For a total of 3 facts in module MAIN. >> >> Ceiling Light | 10 >> >> ------------------------------**----------------------------- >> >> Then I delete the portion of the script from (reset) on down, with just >> the following: >> >> (deftemplate DimmerSwitch (slot label) (slot brightness)) >> (defquery search-dimmer-switch >> (declare (variables ?lbl)) >> (DimmerSwitch (label ?lbl) (brightness ?b)) >> ) >> (defrule set-brightness-to-10-and-15 >> (not (DimmerSwitch)) >> => >> (assert (DimmerSwitch (label "Ceiling Light") (brightness 10))) >> (assert (DimmerSwitch (label "Bathroom Light") (brightness 5))) >> ) >> >> Then I use java to run the query as follows. "test.clp" contains the above >> script obviously. >> >> package control; >> import jess.*; >> public class TestApp { >> public static void main(String[] args) throws JessException { >> Rete engine = new Rete(); >> engine.batch("C:\\Users\\**Administrator\\workspace\\** >> ShadowFactTest\\src\\control\\**test.clp"); >> engine.reset(); >> >> engine.eval("(facts)"); >> engine.run(); >> >> engine.eval("(facts)"); >> >> QueryResult result = engine.runQueryStar("search-**dimmer-switch", new >> ValueVector().add("Ceiling Light")); >> while (result.next()) { >> System.out.println(result.**getString("lbl") + " | " + >> result.getInt("b")); >> } >> } >> } >> >> The output is as follows. The Rete Engine ran fine. The rule fired. But >> there's nothing coming back from runQueryStar. >> f-0 (MAIN::initial-fact) >> >> For a total of 1 facts in module MAIN. >> >> f-0 (MAIN::initial-fact) >> >> f-1 (MAIN::DimmerSwitch (label "Ceiling Light") (brightness 10)) >> >> f-2 (MAIN::DimmerSwitch (label "Bathroom Light") (brightness 5)) >> >> For a total of 3 facts in module MAIN. >> >> ------------------------------**--------------------------- >> >> Now I change the query parameter to "brightness", an integer field. >> >> (deftemplate DimmerSwitch (slot label) (slot brightness)) >> (defquery search-dimmer-switch >> (declare (variables ?b)) >> (DimmerSwitch (label ?lbl) (brightness ?b)) >> ) >> (defrule set-brightness-to-10-and-15 >> (not (DimmerSwitch)) >> => >> (assert (DimmerSwitch (label "Ceiling Light") (brightness 10))) >> (assert (DimmerSwitch (label "Bathroom Light") (brightness 5))) >> ) >> >> --------------------- >> >> and use the following java program instead: >> >> package control; >> >> import jess.*; >> >> public class TestApp { >> >> public static void main(String[] args) throws JessException { >> Rete engine = new Rete(); >> engine.batch("C:\\Users\\**Administrator\\workspace\\** >> ShadowFactTest\\src\\control\\**test.clp"); >> engine.reset(); >> >> engine.eval("(facts)"); >> engine.run(); >> >> engine.eval("(facts)"); >> >> QueryResult result = engine.runQueryStar("search-**dimmer-switch", new >> ValueVector().add(10)); >> >> while (result.next()) { >> System.out.println(result.**getString("lbl") + " | " + >> result.getInt("b")); >> } >> } >> } >> >> --------------- >> >> Now the output looks normal: >> >> f-0 (MAIN::initial-fact) >> For a total of 1 facts in module MAIN. >> f-0 (MAIN::initial-fact) >> f-1 (MAIN::DimmerSwitch (label "Ceiling Light") (brightness 10)) >> f-2 (MAIN::DimmerSwitch (label "Bathroom Light") (brightness 5)) >> For a total of 3 facts in module MAIN. >> Ceiling Light | 10 >> >> -------------------------- >> >> Could someone explain why this query won't work? >> >> QueryResult result = engine.runQueryStar("search-**dimmer-switch", new >> ValueVector().add("Ceiling Light")); >> >> Many thanks. >> >> Felix >> >> >> > ------------------------------**--------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences, Sandia National Laboratories > PO Box 969, MS 9012, Livermore, CA 94550 > http://www.jessrules.com > > > > > > > > ------------------------------**------------------------------**-------- > To unsubscribe, send the words 'unsubscribe jess-users y...@address.com' > in the BODY of a message to majord...@sandia.gov, NOT to the list > (use your own address!) List problems? Notify owner-jess-us...@sandia.gov. > ------------------------------**------------------------------**-------- > >