Corese News Corese

Event Listeners in Corese

Olivier Corby, INRIA, Novembre 2008.
See also: Corese

Corese have the notions of Event and Event Listener that enable users to trap some predefined events.

Type Check Events

Interesting for type checking RDF Schema and RDF metadata wrt RDF Schema

EngineFactory ef = new EngineFactory();

IEngine engine = ef.newInstance();

engine.validate("onto.rdfs")
engine.validate("data.rdf")

for (Event e : engine.report()){
   System.out.println(e);
}

API

Event Listeners implement the EventListener interface and specifically the send method shown below, that can be specialized in a user defined Listener subclass.

void send(Event e);

Load Events

Events related to RDF/S document loading.

engine.addEventListener(LoadListener.create());

The Event contains the triple being loaded. The send method of the listener may invalidate the Event using the function call shown below. In this case the triple is withdrawn from loading.

event.setValid(false) 

It is possible to modify/correct the triple on the fly in the listener using the API shown below. This enables users to correct RDF triples that would not be correct otherwise, to leverage or validate RDF wrt RDF Schema, to cast literals to target datatype, etc.

Triple t = (Triple) event.getObject();

t.setSource(aSource);
t.setResource(aResource);
t.setProperty(aProperty);
t.setValue(aValue);
t.setDatatype(aDatatype);
t.setLang(aLang);

Query Events

Events related to SPARQL query processing.

engine.addEventListener(QueryListener.create());

It is possible to skip some events processing in a listener.

EventListener el = QueryListener.create();
el.handle(Event.PROJ_EVAL, false);

Rule Events

Events related to inference rules.

engine.addEventListener(RuleListener.create());

Generic Event Listener

The EventListenerImpl class implements the EventListener interface and does nothing. Users can specialize this class to design their own listners by refining specific methods, specifically the send method.

class MyListener extends EventListenerImpl {

void send(Event e){
   System.out.println(e);
}

}