I see, you don't want all the events that are fired returned to Java,
but only part of them.
You can certainly do that on the Prolog side if you want to. First of
all, you filter the event names that you are interested about with the
external_trigger/1 predicate in the input:
external_trigger(a/0).
external_trigger(b/0).
external_trigger(c/0).
Then you can filter things in the OuputList. Lets say that the query
that you send to Prolog from Java looks like:
"fire_events_java(InputList,OutputList)"
You can put filters on the OutputList:
"fire_events_java(InputList,OutputList),
filter1(OutputList,OutputList2), filter2(OutputList,OutputList3)"
These filter1(OutputList,OutputList2) are very simple to implement:
filter1([],[]):- !.
filter1([event(E,[T1,T2])|OutputList],[Return|OutputList2]):-
% put your filters here
E =.. [EventName|Args],
EventName = ce1,
Args = [X,Y,Z],
X < 100,
!,
% You can return whatever you wish, for instance, only a list of
the first argument
Return = X,
filter1(OutputList,OutputList2).
filter1([_|OutputList],OutputList2):- % those that you don't want in
the result:
!,
filter1(OutputList,OutputList2).
Put these methods in the same file with the event rules. Etalis will
find out that they are Prolog rules and put them in Prolog.
You can also put write statements to see if these rules are working:
"fire_events_java(InputList,OutputList), write('OutputList: '),
write(OutputList), nl, filter1(OutputList,OutputList2),
write('OutputList2: '), write(OutputList2), nl,
filter2(OutputList,OutputList3), write('OutputList3: '),
write(OutputList3), nl, "
or trace these rules:
"fire_events_java(InputList,OutputList), trace,
filter1(OutputList,OutputList2), filter2(OutputList,OutputList3)"
with Enter you trace them, with s you skip the rule, with l you leave
the trace and resume uninterrupted execution
Paul.
On Tue, Sep 21, 2010 at 5:18 AM, hayri <hayri...@googlemail.com> wrote:
> I don't really know what the difference is between print_trigger and
> external_trigger. I used external_trigger and it had the same effekt.
> It printed out the events which were its arguments.
There is no difference between those two predicates. The original name
was external_trigger to flag these triggers that they are intended as
the events that are sent to some agent outside the engine.
However, at some point we thought about this predicate from the
debugging perspective and we renames it print_trigger. They both work
the same. Use whichever you like.
> I also couldn't use the filters properly. A filter is there to sort
> out some events right? What I understood in your description first I
> had to define the events I want and then filter the ones that I don't
> want to get printed out. This part
I put an example in:
etalis\examples\java_interface_02
Basically, the return predicate returns a whole list of events that
were created, but you want to filter in the prolog part and return to
Java only a set that are interesting to you.
So, your call to Prolog from Java would be something like:
"fire_events_java(InputList,OutputList), filter1(OutputList,OutputList2)"
OutputList contains a lot of events that you don't care about.
OutputList2 contains only the events that are interesting to you.
etalis\examples\java_interface_02
We don't want al the events, but only the events of type "c".
The filter is put in place to return only those.
etalis\examples\java_interface_02 is identical to
etalis\examples\java_interface_01, only that
etalis\examples\java_interface_02 returns only the events c, not all
the other events (a,b).
Update ETALIS from the SVN repository to see this example that I mentioned.
Paul.