Closed MJRinne closed 9 years ago
There is a problem in the query. When we add input, such as [] ep:hasEventObjectSamplingTime \"2014-01-07T09:18:21\"^^xsd:dateTime it matches the first two triple patterns: ?event a ep:EventObject ; # Match incoming events ep:hasEventObjectSamplingTime ?time . The where clause is satisfied, whether or not the OPTIONAL matches. Then the INSERT clause adds a triple to memory graph, which unintentionally matches the OPTIONAL part, producing a new instance of the rule. This leads to an infinite loop.
A solution is to use some unique value to the triples that are added to the memory graph and matched in the OPTIONAL part and add a FILTER to the OPTIONAL part that checks that the OPTIONAL does not match the newly added triples again.
I just implemented new options for execution that can be used to tackle this issue.
--rdf-operations=LIST Apply a colon separated list of operations to the unit of RDF input. Operations are "add", "remove", "execute", "execute-first", "execute-snapshot", "execute-repeat-first", and "execute-repeat-snapshot". The last four operations use the specified execution policy. "First" means to execute only the first rule instance in the queue, "snapshot" to execute the the instances currently in the queue, but not the new instances that are added to the queue during these instances. "Repeat" before "first" or "snapshot" means to execute the system using that policy until the queue is empty. Operation "execute" is the a synonym to "execute-repeat-first". You can use "event" as a shorthand form "add:execute:remove:execute". The default operations list is "add:execute".
Using this new option, you should get the correct result as follows:
instans --rdf-operations=add:execute-snapshot:remove:execute -r issue18.rq --input-blocks=issue18.ttl
I am not sure, whether I like this solution though. It contains a lot of out-of-band signaling.
Not sure if anything is wrong, but I'm unable to simultaneously copy events between two graphs and change data in another. Each part can be made to work separately, but the combination gets stuck in a fairly unintuitive way.
Steps to reproduce:
1) Query (issue18.rq):
PREFIX : http://instans.org/ PREFIX ep:http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#
DELETE { GRAPH http://example.org/memory/ { # Clear old value :poststateful :prevHour ?prevhour } } INSERT { GRAPH http://example.org/output/ { # Copy the event ?event a ep:EventObject ; ep:hasEventObjectSamplingTime ?time } GRAPH http://example.org/memory/ { # Write new value to memory :poststateful :prevHour ?hour }
} WHERE { ?event a ep:EventObject ; # Match incoming events ep:hasEventObjectSamplingTime ?time . GRAPH http://example.org/memory/ { # Retrieve value from memory, if available OPTIONAL { :poststateful :prevHour ?prevhour } } BIND ( HOURS(?time) as ?hour ) } ;
SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }
2) Data (issue18.ttl); events with timestamps like:
[] a ep:EventObject ; ep:hasEventObjectSamplingTime "2014-01-07T09:18:21"^^xsd:dateTime . ...
3) Command line: $ instans -r issue18.rq -t issue18.ttl Also tested with block input, no difference detected.
What happens:
The query produces the following output:
g,s,p,o http://example.org/output/,_:!-0,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-0,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T09:18:21
After that execution gets stuck. After CTRL-C, the following debugger output is produced: debugger invoked on a SB-SYS:INTERACTIVE-INTERRUPT in thread
<THREAD "main thread" RUNNING {100588BF13}>:
Interactive interrupt at #x116750.
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name): 0: [CONTINUE] Return from SB-UNIX:SIGINT.
("bogus stack frame") 0]
What was expected to happen:
The events were expected to be copied to the new frame, the memory-graph updated with the hour of each event during the copy process.
If the first two lines of the query are removed (the DELETE statement cleaning the memory-graph) the following (expected) output is produced:
g,s,p,o http://example.org/output/,_:!-0,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-0,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T09:18:21 http://example.org/memory/,http://instans.org/poststateful,http://instans.org/prevHour,9 http://example.org/output/,_:!-1,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-1,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T09:42:00 http://example.org/output/,_:!-2,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-2,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T10:18:21 http://example.org/memory/,http://instans.org/poststateful,http://instans.org/prevHour,10 http://example.org/output/,_:!-3,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-3,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T11:32:34 http://example.org/memory/,http://instans.org/poststateful,http://instans.org/prevHour,11 http://example.org/output/,_:!-4,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-4,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-07T21:12:32 http://example.org/memory/,http://instans.org/poststateful,http://instans.org/prevHour,21 http://example.org/output/,_:!-5,http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#EventObject http://example.org/output/,_:!-5,http://www.ontologydesignpatterns.org/cp/owl/eventprocessing.owl#hasEventObjectSamplingTime,2014-01-08T04:02:11 http://example.org/memory/,http://instans.org/poststateful,http://instans.org/prevHour,4
Related:
The copying also proceeds as expected, if the memory INSERT operation is removed or incapacitated (e.g. by introducing a spelling error to the "?hour" variable).
The memory operations can be made to work independently, but a terminating condition needs to be set and only the final value is printed by the SELECT-query.
This issue is related to the construction of stateful filters: It should be possible to selectively forward events, while keeping a record of previous events, which can influence the outgoing ones.