Jtalis: modifying time intervalls of events

80 views
Skip to first unread message

Hendrik Adler

unread,
Jan 24, 2013, 7:37:28 AM1/24/13
to eta...@googlegroups.com
Hi,

I am new to this forum. I do some research in temporal streaming languages. Currently I try to analyze historical data with Jtalis. That is why I want to modify the timeinvervalls of some events. But modifying timestamps with event.setTimeStarts(e1) and event.setTimeEnds(e2) has no influence to the system.
With etalis I can modify intervalls with "event(a,[datime(2013,1,24,12,11,47,4),datime(2013,1,24,12,11,47,4)])".
Here is a simple example that is not doing what I would expect. It would be great if someone could tell me what I am doing wrong or if there is a better way to work with historical event-data.

Many thanks
Hendrik
 
                public static void main(String[] args) {

                    PrologEngineWrapper<?> engine = new JPLEngineWrapper(false);
                                       
                    JtalisContextImpl ctx = new JtalisContextImpl(engine);
                    ctx.setEtalisFlags("out_of_order", "on");

                    ctx.addEventTrigger("_");
                                         
                    ctx.addDynamicRule("c <- b(X) seq a(Y)");

                    ctx.registerOutputProvider(new DefaultOutputProvider());
                    ctx.registerInputProvider(new DefaultInputProvider(), 1000);


                    //This way I try to modify the timestamps.
                    EtalisEvent eventa = new EtalisEvent("a",1);                   
                    EventTimestamp     e1 = new EventTimestamp(System.currentTimeMillis()/1000,0);
                    EventTimestamp     e2 = new EventTimestamp(System.currentTimeMillis()/1000,0);
                    eventa.setTimeStarts(e1);
                    eventa.setTimeEnds(e2);


                    //I use "-10" because event b has happened in the past.
                    EtalisEvent eventb = new EtalisEvent("b",1);
                    EventTimestamp     e3 = new EventTimestamp(System.currentTimeMillis()/1000-10,0);
                    EventTimestamp     e4 = new EventTimestamp(System.currentTimeMillis()/1000-10,0);
                    eventb.setTimeStarts(e3);
                    eventb.setTimeEnds(e4);
                                       
                                       
                    //Now I send the events, but the timestamp modification has not influence
                    ctx.pushEvent(eventa);
                    ctx.pushEvent(eventb);

                    ctx.waitForInputProviders();
                    ctx.shutdown();
                }

Jia Ding

unread,
Jan 24, 2013, 9:25:33 AM1/24/13
to eta...@googlegroups.com
Hi Hendrik,

I look at the source code of Jtalis,
when events send to Etalis from Jtalis, the timestamp is not included.
That's why your code doesn't work.

regards,
Jia

2013/1/24 Hendrik Adler <hen....@gmail.com>

--
 
 

Pouyan Ziafati

unread,
Jan 24, 2013, 10:13:50 AM1/24/13
to eta...@googlegroups.com
Hi,

I also had encountered the same problem.
Below is a modification of the CoumpandTerm class in Jtalis which should do the job for you.

Cheers,
Pouyan


package com.jtalis.core.terms;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.jtalis.core.event.EtalisEvent;
import com.jtalis.core.event.EventTimestamp;
import com.jtalis.core.plengine.logic.CompoundTerm;
import com.jtalis.core.plengine.logic.Term;

/**
 * AssertTEventTermerm
 *
 * @author <a href="mailto:vesko.m....@gmail.com">Vesko Georgiev<a>
 */
public class EventTerm extends CompoundTerm {
    // changed by Pouyan
    String timeStartsToString,timeEndsToString;
   
    public EventTerm(EtalisEvent event) {
        super("event", event);//super("event",event);
        DateFormat df = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss");
        this.timeStartsToString = "datime("+ df.format(event.getTimeStarts()) +","+((EventTimestamp) event.getTimeStarts()).getIndex()+")";
        this.timeEndsToString = "datime("+df.format(event.getTimeEnds())+","+((EventTimestamp) event.getTimeEnds()).getIndex()+")";
    }
   
   
    //did not exist before, added by Pouyan
    @Override
    public String getPrologString() {
        if (getArity() == 0) {
            return this.getName();
        }
        StringBuilder builder = new StringBuilder(this.getName()).append("(");
        for (Term t : this.getTerms()) {
            builder.append(t.getPrologString()).append(", ");
        }
       
        if(this.timeStartsToString == null){
            builder.replace(builder.length() - 2, builder.length(), ")");
            return builder.toString();
        }
        else if(this.timeEndsToString == null){
            builder.append(this.timeStartsToString);
            builder.append(")");
            return builder.toString();
        }
        else{
            builder.append(this.timeStartsToString);
            builder.append(", ");
            builder.append(this.timeEndsToString);
            builder.append(")");
            //System.out.println("*************  "+builder.toString());
            return builder.toString();           
        }
               
    }
    //did not exist before
    @Override
    public String toString() {
        return getPrologString();
    }
   
    //Pouyan

Pouyan Ziafati

unread,
Jan 24, 2013, 10:40:13 AM1/24/13
to eta...@googlegroups.com
Sorry a couple of mistakes in my previous message.

1- The EventTerm.java file is the one that has to be modified, not the CompoundTerm.java file.
2- Change the getPrologString() function I sent you to the following.


@Override
    public String getPrologString() {
        if (getArity() == 0) {
            return this.getName();
        }
        StringBuilder builder = new StringBuilder(this.getName()).append("(");
        for (Term t : this.getTerms()) {
            builder.append(t.getPrologString()).append(", ");
        }
       
        if(this.timeStartsToString == null){
            builder.replace(builder.length() - 2, builder.length(), ")");
            return builder.toString();
        }
        else if(this.timeEndsToString == null){
            builder.append("[");
            builder.append(this.timeStartsToString);
            builder.append(",");
            builder.append(this.timeStartsToString);
            builder.append("]");

            builder.append(")");
            return builder.toString();
        }
        else{
            builder.append("[");

            builder.append(this.timeStartsToString);
            builder.append(", ");
            builder.append(this.timeEndsToString);
            builder.append("]");

            builder.append(")");
            //System.out.println("*************  "+builder.toString());
            return builder.toString();           
        }
               
    }



On Thursday, January 24, 2013 4:13:50 PM UTC+1, Pouyan Ziafati wrote:
Hi,

I also had encountered the same problem.
Below is a modification of the CoumpandTerm class in Jtalis which should do the job for you.

Cheers,
Pouyan


package com.jtalis.core.terms;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.jtalis.core.event.EtalisEvent;
import com.jtalis.core.event.EventTimestamp;
import com.jtalis.core.plengine.logic.CompoundTerm;
import com.jtalis.core.plengine.logic.Term;

/**
 * AssertTEventTermerm
 *
 * @author <a href="mailto:vesko.m.georgiev@gmail.com">Vesko Georgiev<a>

Hendrik Adler

unread,
Jan 24, 2013, 11:39:18 AM1/24/13
to eta...@googlegroups.com
Hi,

many thanks. You made my day! I added the code of your second mail to the EventTerm.java. Now the example is working.

Cheers
Hendrik

Darko Anicic

unread,
Jan 24, 2013, 3:08:28 PM1/24/13
to eta...@googlegroups.com
Hi Hendrik and Pouyan,

ETALIS has a possibility to express the system time (the time stamp assigned to an event automatically as the event is reported to ETALIS) and the application time (e.g., the time stamp assigned to an event at the moment when the event was generated by an application or event source). For the latter case we have provided a means to trigger an event with an application time stamp, e.g., what you mentioned: event(a,[datime(2013,1,24,12,11,47,4),datime(2013,1,24,12,11,47,4)]).

This functionality is implemented in ETALIS but not yet in jtalis. Anyway it is good to know that you need it, and since now Pouyan did it we will add it to jtalis. 

However, please note that the functionality for the application time stamp was added to ETALIS with intention to be used with the purpose I described above, i.e., not really to be used for historical events. 

Anyway I am glad if it also works for the purpose of your research work too.

Cheers, Darko
Message has been deleted

Vesko Georgiev

unread,
Jan 25, 2013, 6:41:54 AM1/25/13
to eta...@googlegroups.com
Hi all, 

I have added a test case for the timestamps manipulation. 

I've tried to apply the suggested change from Pouyan Ziafati, and unfortunately it breaks some of the existing tests, e.g. TestDynamicEvents

Could somebody please see why is that?

Cheers,
Vesko

--
 
 


Pouyan Ziafati

unread,
Jan 25, 2013, 11:26:22 AM1/25/13
to eta...@googlegroups.com
Hi,

I guess below is what causes the TestDynamicEvents to fail.
In my run:
First event is:           event(a(1), [datime(2013,01,25,17,01,05,0), datime(2013,01,25,17,01,05,0)])
Second event is:      event(b(1), [datime(2013,01,25,17,01,05,0), datime(2013,01,25,17,01,05,0)])

As both event have the same time stamp, the rule "c(X) <- a(X) seq b(X)" can not be applied.
When events are pushed to Etalis without time stamps, you time stamp them using  label_time_stamp predicate(Datime) predicate which increases the counter (index, the last argument of the datime/7 predicate) in time stamps of events incrementally.

By the way (this has nothing to do with the test failures), I suggest to change the getTime() function in EventTimestamp.java to
@Override
    public long getTime() {
        return super.getTime();
    }
 The reason: please look at the below line of the code I sent before.

this.timeStartsToString = "datime("+ df.format(event.getTimeStarts()) +","+((EventTimestamp) event.getTimeStarts()).getIndex()+")";

Here I add index value separately, so I don't see any reason that getTime() function should also add the index value.

Cheers,
Pouyan
 * @author <a href="mailto:vesko.m....@gmail.com">Vesko Georgiev<a>

--
 
 


Hendrik Adler

unread,
Jan 27, 2013, 9:39:44 AM1/27/13
to eta...@googlegroups.com
Hi,

many thanks for adding this feature to the SVN.
In practice I will try to use Jtalis for classifying sensor data. I need to modify timestamps, because Data will not be received in realtime but with a delay of minutes or even days. Besides if I add or change classification rules I need to reanalyze historical data.
Darko, you have written Jtalis is more developed for realtime data. Do you expect some concrete problems when using Jtalis with historical data? What I think about for example is if I can set the analyzing-window to a past point of time?

Cheers
Hendrik

Darko Anicic

unread,
Feb 3, 2013, 3:28:07 PM2/3/13
to eta...@googlegroups.com
Hi,

Pouyan is right - the same time stamps cased the test to fail, and I agree with him about changing  the getTime() function.

Cheers, Darko  

Darko Anicic

unread,
Feb 3, 2013, 3:33:54 PM2/3/13
to eta...@googlegroups.com
Hi Hendrik,

I don't expect problems when using Jtalis with historical data, except that you need to take care about correctness of time stamps (e.g., if two events have the same time stamp up to the second resolution, the index value need to be assigned).

Cheers, Darko
Reply all
Reply to author
Forward
0 new messages