diff --git a/src/clickTrainDetector/classification/standardClassifier/StandardClassification.java b/src/clickTrainDetector/classification/standardClassifier/StandardClassification.java index 554f2b0c..07bb2513 100644 --- a/src/clickTrainDetector/classification/standardClassifier/StandardClassification.java +++ b/src/clickTrainDetector/classification/standardClassifier/StandardClassification.java @@ -3,6 +3,7 @@ package clickTrainDetector.classification.standardClassifier; import clickTrainDetector.classification.CTClassification; import clickTrainDetector.classification.CTClassifierType; import clickTrainDetector.classification.ClassifierJSONLogging; +import clickTrainDetector.classification.bearingClassifier.BearingClassifierJSON; /** * A classification object for a standard classification @@ -23,6 +24,10 @@ public class StandardClassification implements CTClassification { private CTClassification[] ctClassifications; + public CTClassification[] getCtClassifications() { + return ctClassifications; + } + /** * Standard classifier JSON logging. */ @@ -41,9 +46,15 @@ public class StandardClassification implements CTClassification { * @param jsonstring */ public StandardClassification(String jsonstring) { + standardClassifierJSONLogging = new StandardClassificationJSON(); + CTClassification classification = standardClassifierJSONLogging.createClassification(jsonstring); + this.ctClassifications = ((StandardClassification) classification).getCtClassifications(); + this.speciesID =classification.getSpeciesID(); + } + @Override public CTClassifierType getClassifierType() { diff --git a/src/clickTrainDetector/classification/standardClassifier/StandardClassificationJSON.java b/src/clickTrainDetector/classification/standardClassifier/StandardClassificationJSON.java index 3016ba2d..9951aaf8 100644 --- a/src/clickTrainDetector/classification/standardClassifier/StandardClassificationJSON.java +++ b/src/clickTrainDetector/classification/standardClassifier/StandardClassificationJSON.java @@ -1,10 +1,22 @@ package clickTrainDetector.classification.standardClassifier; +import java.io.ByteArrayInputStream; +import java.io.IOException; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import clickTrainDetector.classification.CTClassification; import clickTrainDetector.classification.SimpleClassifierJSONLogging; +import clickTrainDetector.classification.bearingClassifier.BearingClassification; +import clickTrainDetector.classification.bearingClassifier.BearingClassifier; +import clickTrainDetector.classification.idiClassifier.IDIClassification; +import clickTrainDetector.classification.idiClassifier.IDIClassifier; +import clickTrainDetector.classification.simplechi2classifier.Chi2CTClassification; +import clickTrainDetector.classification.simplechi2classifier.Chi2ThresholdClassifier; +import clickTrainDetector.classification.templateClassifier.CTTemplateClassifier; +import clickTrainDetector.classification.templateClassifier.TemplateClassification; /** @@ -25,6 +37,11 @@ public class StandardClassificationJSON extends SimpleClassifierJSONLogging { this.standardClassifier=ctClassifications; } + public StandardClassificationJSON() { + + } + + @Override public void writeJSONData(JsonGenerator jg, CTClassification ctClassification) { @@ -35,27 +52,59 @@ public class StandardClassificationJSON extends SimpleClassifierJSONLogging { @Override - public CTClassification createClassification(JsonNode jTree) { - - JsonNode na = jTree.findValue("SPECIES"); - int speciesID; - if (na != null ) { - speciesID = na.asInt(); - } - else { - System.err.println("Cannot load template classifier"); - return null; - } + public CTClassification createClassification(String jsonString) { + try { + ObjectMapper om = new ObjectMapper(); + JsonNode jTree = om.readTree(new ByteArrayInputStream(jsonString.getBytes())); + // JsonNode nv = jTree.findValue("NAME"); - CTClassification[] ctClassification = new CTClassification[standardClassifier.length]; - for (int i=0; i(); + - classifiers.add(new Chi2ThresholdClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID)); - - classifiers.add(new IDIClassifier(clickTrainControl,SUB_CLASSIFIER_SPECIESID)); - - classifiers.add(new CTTemplateClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID)); - - classifiers.add(new BearingClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID)); - + //do this so that is CLASSIFIER_TYPES changes order things still work. + for (int i=0; i