From cfe42aca714d18d11b0c886afe16c4161838a564 Mon Sep 17 00:00:00 2001 From: dtracers Date: Sun, 3 Jul 2016 23:43:41 -0500 Subject: [PATCH] Added a finish training method to clean up training resources --- .../recognition/framework/RecognitionInterface.java | 9 ++++++++- .../recognition/test/RecognitionTesting.java | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/coursesketch/recognition/framework/RecognitionInterface.java b/src/main/java/coursesketch/recognition/framework/RecognitionInterface.java index 3a39b34..f2a7b57 100644 --- a/src/main/java/coursesketch/recognition/framework/RecognitionInterface.java +++ b/src/main/java/coursesketch/recognition/framework/RecognitionInterface.java @@ -74,6 +74,13 @@ public interface RecognitionInterface { */ public void trainTemplate(Sketch.RecognitionTemplate template) throws TemplateException; + /** + * Called when Training is finished to show perform any cleanup that is needed. + * + * @throws RecognitionException Thrown if there is a recognition Problem. + */ + public void finishTraining() throws RecognitionException; + /** * Recognizes the sketch as a list of changes producing a list of changes as a result. * @@ -117,5 +124,5 @@ public List recognize(String sketchId, Sketch.Recognit /** * Called for an initialization or training to setup for recognition. */ - public void initialize(); + public void initialize() throws RecognitionException; } diff --git a/src/main/java/coursesketch/recognition/test/RecognitionTesting.java b/src/main/java/coursesketch/recognition/test/RecognitionTesting.java index 2814d95..8a4b64e 100644 --- a/src/main/java/coursesketch/recognition/test/RecognitionTesting.java +++ b/src/main/java/coursesketch/recognition/test/RecognitionTesting.java @@ -2,6 +2,7 @@ import coursesketch.recognition.framework.RecognitionInterface; import coursesketch.recognition.framework.TemplateDatabaseInterface; +import coursesketch.recognition.framework.exceptions.RecognitionException; import coursesketch.recognition.framework.exceptions.TemplateException; import protobuf.srl.sketch.Sketch; @@ -72,7 +73,7 @@ public List testAgainstTemplates(List> recognizeAgainstTemplates( + public Map> recognizeAgainstTemplates( List testTemplates) { Map> scoreMap = new HashMap<>(); @@ -106,7 +107,6 @@ public Object call() throws Exception { } generateScore(score, recognize, testTemplate.getInterpretation()); } catch (Exception e) { - LOG.error("Excpetion occured while recognizering", e); score.setFailed(e); } recognitionScoreList.add(score); @@ -158,7 +158,6 @@ public Object call() throws Exception { try { recognitionSystem.trainTemplate(template); } catch (Exception e) { - LOG.error("Exception occured while training", e); score.addException(new RecognitionTestException("Error with training template " + template.getTemplateId(), e, recognitionSystem)); } @@ -186,6 +185,11 @@ public Object call() throws Exception { LOG.debug("EXECUTION EXCEPTION", e); } } + try { + recognitionSystem.finishTraining(); + } catch (RecognitionException e) { + LOG.debug("EXCEPTION WHEN TRAINING", e); + } LOG.debug("All trainings tasks have finished"); } return scoreMap;