Revision: 13946 http://gate.svn.sourceforge.net/gate/?rev=13946&view=rev Author: valyt Date: 2011-06-07 11:23:11 +0000 (Tue, 07 Jun 2011)
Log Message: ----------- - support for interruptions, - firing of progress event. Modified Paths: -------------- gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/SPTBase.java gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java Modified: gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/SPTBase.java =================================================================== --- gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/SPTBase.java 2011-06-07 10:56:59 UTC (rev 13945) +++ gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/SPTBase.java 2011-06-07 11:23:11 UTC (rev 13946) @@ -1118,11 +1118,14 @@ * @throws ExecutionException */ public void execute() throws ExecutionException { + // fire the progress start event + fireProgressChanged(0); + // the annotation for which we last reported the progress + int lastProgressReportAnnIdx = 0; // prepare the annotations array loadAnnotations(); predicateHits = 0; predicateMisses = 0; - activeInstances = new LinkedList<FSMInstance>(); acceptingInstances = new ArrayList<FSMInstance>(); int currentAnnotation = 0; @@ -1131,12 +1134,12 @@ activeInstances.add(new FSMInstance(currentAnnotation, 0, new HashMap<String, IntArrayList>())); activeInstances: while(activeInstances.size() > 0) { + if(owner.isInterrupted()) throw new ExecutionInterruptedException( + "The execution of the \"" + getName() + + "\" JAPE Plus transducer has been interrupted!"); // The matching needs to run in breadth-first-search mode, in order to // support Once and First matching modes. The algorithm is that we - // advance - // the top instance, and queue all resulting instances (which may - // include - // the original one, if still active). + // advance the top instance, and queue all resulting instances. // get the first instance FSMInstance fsmInstance = activeInstances.removeFirst(); if(states[fsmInstance.state].rule >= 0) { @@ -1335,22 +1338,15 @@ }else{ //no acceptors -> just move to next annotation currentAnnotation = annotationNextOffset[currentAnnotation]; -// currentAnnotation = followingAnnotation(currentAnnotation); -// while(currentAnnotation != Integer.MAX_VALUE && -// oldCurrAnn == followingAnnotation(currentAnnotation)) { -// // this can happen when a rule has a Kleene * and nothing else -// // which allows it to successfully match nothing -// if(currentAnnotation < annotation.length -2){ -// currentAnnotation ++; -// } else { -// // we've run out of annotations -// currentAnnotation = Integer.MAX_VALUE; -// } -// } } - + // fire the progress event + if(currentAnnotation - lastProgressReportAnnIdx > annotation.length / 10) { + fireProgressChanged(currentAnnotation * 100 / annotation.length); + lastProgressReportAnnIdx = currentAnnotation; + } }// while(currentAnnotation < annotation.length) // execution completed -> clean up the internal data structures. + fireProcessFinished(); annotation = null; annotationFollowing = null; annotationNextOffset = null; @@ -1365,6 +1361,7 @@ // ((double)predicateHits / (predicateHits + predicateMisses)))); } + protected void applyRule(FSMInstance instance) throws JapeException { // convert bindings to correct type Map<String, AnnotationSet> newBindings = Modified: gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java =================================================================== --- gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java 2011-06-07 10:56:59 UTC (rev 13945) +++ gate/trunk/plugins/JAPE_Plus/src/gate/jape/plus/Transducer.java 2011-06-07 11:23:11 UTC (rev 13946) @@ -24,6 +24,7 @@ import gate.creole.metadata.RunTime; import gate.event.AnnotationSetEvent; import gate.event.AnnotationSetListener; +import gate.event.ProgressListener; import gate.event.StatusListener; import gate.gui.MainFrame; import gate.jape.MultiPhaseTransducer; @@ -49,7 +50,7 @@ @CreoleResource(name = "JAPE-Plus Transducer", comment = "An optimised, JAPE-compatible transducer.") public class Transducer extends AbstractLanguageAnalyser - implements ControllerAwarePR { + implements ControllerAwarePR, ProgressListener { /** * A comparator for annotations based on start offset and inverse length. */ @@ -150,8 +151,12 @@ */ protected SPTBase[] singlePhaseTransducers; + /** + * The index in {@link #singlePhaseTransducers} for the SPT currently being + * executed, if any, -1 otherwise. + */ + protected int currentSptIndex = -1; - public String getEncoding() { return encoding; } @@ -209,6 +214,7 @@ for(int i = 0; i < intermediate.getPhases().size(); i++){ singlePhaseTransducers[i] = builder.buildSPT((SinglePhaseTransducerPDA) intermediate.getPhases().get(i)); + singlePhaseTransducers[i].addProgressListener(this); } } finally{ @@ -218,21 +224,28 @@ @Override public void cleanup() { - // TODO Auto-generated method stub super.cleanup(); + for(SPTBase aSpt : singlePhaseTransducers){ + aSpt.removeProgressListener(this); + aSpt.cleanup(); + } } - + @Override public void execute() throws ExecutionException { if (singlePhaseTransducers == null) { throw new IllegalStateException("init() was not called."); } + interrupted = false; AnnotationSet inputAs = (inputASName == null || inputASName.length() == 0) ? document.getAnnotations() : document.getAnnotations(inputASName); + fireProgressChanged(0); try { inputAs.addAnnotationSetListener(inputASListener); sortedAnnotations.clear(); - for(SPTBase aSpt : singlePhaseTransducers){ + for(currentSptIndex = 0; currentSptIndex < singlePhaseTransducers.length; + currentSptIndex++){ + SPTBase aSpt = singlePhaseTransducers[currentSptIndex]; changedTypes.clear(); aSpt.setCorpus(corpus); aSpt.setDocument(document); @@ -254,9 +267,25 @@ } } finally { inputAs.removeAnnotationSetListener(inputASListener); + currentSptIndex = -1; + fireProcessFinished(); } } + + @Override + public void progressChanged(int i) { + // event coming from one of our SPTs + if(currentSptIndex >= 0) { + fireProgressChanged((currentSptIndex * 100 + i) / singlePhaseTransducers.length); + } + } + + @Override + public void processFinished() { + // ignore + } + /** * Get the set of annotations, of a given type, sorted by start offset and * inverse length, obtained from the input annotation set of the current This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ GATE-cvs mailing list GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs