Search code examples
complex-event-processingesper

Esper js expression declaration


I am following the example in Esper documentation to create an expression following js dialect

Here's my EPL declaration

expression float js:IOU(xBottom1,yBottom1, xTop1, yTop1, xBottom2, yBottom2, xTop2, yTop2) [
    IOU(xBottom1,yBottom1, xTop1, yTop1, xBottom2, yBottom2, xTop2, yTop2);
    function IOU(xBottom1,yBottom1, xTop1, yTop1, xBottom2, yBottom2, xTop2, yTop2) {
    //get the bottom left and top right points of the intersection triangle
    var xIntersection1 = Math.max(xBottom1,xBottom2);
    var yIntersection1 = Math.max(yBottom1,yBottom2);
    var xIntersection2 = Math.min(xTop1,xTop2);
    var yIntersection2 = Math.min(yTop1,yTop2);

    var interArea = (Math.max(0, xIntersection2 - xIntersection1 +1) * Math.max(0, yIntersection2 - yIntersection1 +1));
    var box1Area = (Math.max(0, xTop1 - xBottom1 +1) * Math.max(0, yTop1 - yBottom1 +1));
    var box2Area = (Math.max(0, xTop2 - xBottom2 +1) * Math.max(0, yTop2 - yBottom2 +1));

    var iou = interArea / parseFloat(box1Area+box2Area-interArea);

    return iou;
   }
]

However, I get a compilation error as Incorrect syntax near 'IOU' at line 2 column 4 [expression float js:IOU(xBottom1,yBottom1, xTop1, yTop1, xBottom2, yBottom2, xTop2, yTop2)...

I am not sure what is missing and if there are examples in Esper Github for using expressions? Do I need to configure the compiler somehow? This is not mentioned in the respective chapter, Chapter 19 of the documentation.

Just to clarify, I tried even with a single-line JS script and I verified the above JS function. So, I believe that it is related to how to define the script in EPL not the syntax itself within the respective dialect.


Solution

  • The standalone expression syntax is "create expression". Since I don't see anything else I presume you want to do a standalone expression and so its missing "create". And when its not a standalone expression the syntax is "expression ... select ...".

    Here is a link to one of the regression tests.