[rules-users] Getting facts from external source using 'from' and parametrized method call
Przemysław Różycki
P.Rozycki at amg.net.pl
Mon Jan 26 09:34:16 EST 2009
Great! That was it. Changing the order from:
session.insert(fact1);
session.insert(new FactSource());
session.setGlobal("factSource", new FactSource());
to:
session.setGlobal("factSource", new FactSource());
session.insert(fact1);
session.insert(new FactSource());
helped!
Thank you very much for help. The conclusion is obvious then - to set
such a global before any insertion.
Best regards,
Przemek
Edson Tirelli pisze:
>
> Remember that the engine evaluates all your LHS CEs when you ASSERT
> the facts, not when you FIRE the rules. So, you obviously need to set
> the global before asserting your facts or you will get the nasty NPE
> that you saw.
>
> Pre rule tells you exactly that, because eval(true) is evaluated at
> ASSERT time and activates the rule, but your System.out is only execute
> at FIRE time, after your application set the global.
>
> []s
> Edson
>
>
>
> 2009/1/26 Przemysław Różycki <P.Rozycki at amg.net.pl
> <mailto:P.Rozycki at amg.net.pl>>
>
> Of course, you can get rid of 'pre rule'. I forgot to delete it.
>
>
> Best regards,
> Przemek
>
> Przemysław Różycki pisze:
>
> Hi,
>
> I mean, I checked the global and it was set.
>
> I'm attaching the code, that causes the problem (Java and DRL).
> You need just to set a proper path to DRL file while setting
> file property in Java file. I think, the global is set in proper
> way.
> In DRL, depending which rule is commented/uncommented, the code
> works or not.
>
> Best regards,
> Przemek
>
> Jaroslaw Kijanowski pisze:
>
> And did the stack trace change? Can you post more details
> (drl, java src)?
>
> Przemysław Różycki wrote:
>
> Yes, I did. This was the first thing I've checked.
>
> Best regards,
> Przemek
>
> Jaroslaw Kijanowski pisze:
>
> Did you set the global on your session?
>
> http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html#d0e948
>
>
> Cheers
>
> Przemysław Różycki wrote:
>
> Sorry for responsing myself, but I'm still
> working on it and found that when factSource is
> a fact, not global, the rule works very well. I
> mean, this rule works fine:
>
> rule "My Rule"
> when
> $factSrc : FactSource( )
> $fact : Fact( ) from
> $factSrc.getSomeFacts("a","b","c")
> then
> // do something
> end
>
> so what's the difference between invocation on
> global object and invocation on fact object? Why
> the first one doesn't work and the second one works?
>
> Best regards,
> Przemek
>
>
> Przemysław Różycki pisze:
>
> Hi,
>
> could I ask for some advice, please, how to
> use a parametrized method call to get some
> data using 'from' element in LHS.
>
> To be more precise, I would like to do
> something like this:
>
> rule "My Rule"
> when
> $fact : Fact( ) from
> factSource.getSomeFacts("a","b","c")
> then
> // do something
> end
>
> where factSource is for example some global
> and getSomeFacts(String,String,String) is a
> parametrized method that returns some array
> of Fact objects.
>
> Unfortunately, when I try to launch the
> following rule I have an error:
>
> Exception in thread "main"
> org.mvel.PropertyAccessException: unable to
> resolve property:
> factSource.getSomeFacts("a","b","c")
> at
> org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:295)
>
> at
> org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:110)
>
> at
> org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:26)
>
> at
> org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:70)
>
> at
> org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:24)
>
> at
> org.mvel.MVELRuntime.execute(MVELRuntime.java:90)
> at
> org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
> at
> org.mvel.MVEL.executeExpression(MVEL.java:252)
> at
> org.drools.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:55)
>
> at
> org.drools.reteoo.FromNode.assertTuple(FromNode.java:68)
> at
> org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
>
> at
> org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
>
> at
> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
>
> at
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
>
> at
> org.drools.reteoo.Rete.assertObject(Rete.java:175)
> at
> org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
>
> at
> org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:181)
>
> at
> org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1312)
>
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:915)
>
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
>
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
>
> at
> com.sample.DroolsTest6.main(DroolsTest6.java:29)
> Caused by: java.lang.NullPointerException
> at
> org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:530)
>
> at
> org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:261)
>
> ... 21 more
>
> Documentation says:
>
> "The from Conditional Element allows users
> to specify a source for patterns to reason
> over. This allows the engine to reason over
> data not in the Working Memory. This could
> be a sub-field on a bound variable or the
> results of a method call."
>
> so I assume that it is possible to do what I
> want. If not, could I ask for an advice of
> some workaround, please?
>
> Best regards,
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> JBoss, a division of Red Hat @ www.jboss.com <http://www.jboss.com>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list