mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
Fix standard classifier JSON logging
This commit is contained in:
parent
80b580d30d
commit
2ed51b9c70
@ -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,10 +46,16 @@ 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() {
|
||||
return CTClassifierType.STANDARDCLASSIFIER;
|
||||
|
@ -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,7 +52,12 @@ public class StandardClassificationJSON extends SimpleClassifierJSONLogging {
|
||||
|
||||
|
||||
@Override
|
||||
public CTClassification createClassification(JsonNode jTree) {
|
||||
public CTClassification createClassification(String jsonString) {
|
||||
try {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
JsonNode jTree = om.readTree(new ByteArrayInputStream(jsonString.getBytes()));
|
||||
// JsonNode nv = jTree.findValue("NAME");
|
||||
|
||||
|
||||
JsonNode na = jTree.findValue("SPECIES");
|
||||
int speciesID;
|
||||
@ -43,19 +65,46 @@ public class StandardClassificationJSON extends SimpleClassifierJSONLogging {
|
||||
speciesID = na.asInt();
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot load template classifier");
|
||||
System.err.println("Cannot load standard classifier");
|
||||
return null;
|
||||
}
|
||||
|
||||
CTClassification[] ctClassification = new CTClassification[standardClassifier.length];
|
||||
for (int i=0; i<standardClassifier.length; i++) {
|
||||
ctClassification[i] = ((SimpleClassifierJSONLogging) standardClassifier[i].getJSONLogging()).createClassification(jTree);
|
||||
//System.out.println("Hello load classification: " + standardClassifier.length);
|
||||
CTClassification[] ctClassification = new CTClassification[StandardClassifier.CLASSIFIER_TYPES.length];
|
||||
|
||||
|
||||
for (int i=0; i<ctClassification.length; i++) {
|
||||
CTClassification classification = null;
|
||||
switch (StandardClassifier.CLASSIFIER_TYPES[i]) {
|
||||
case CHI2THRESHOLD:
|
||||
classification = new Chi2CTClassification(jsonString);
|
||||
break;
|
||||
case IDICLASSIFIER:
|
||||
classification = new IDIClassification(jsonString);
|
||||
break;
|
||||
case TEMPLATECLASSIFIER:
|
||||
classification = new TemplateClassification(jsonString);
|
||||
break;
|
||||
case BEARINGCLASSIFIER:
|
||||
classification = new BearingClassification(jsonString);
|
||||
break;
|
||||
default:
|
||||
System.err.println("StandardClassification: classifier JSON not found");
|
||||
break;
|
||||
}
|
||||
ctClassification[i] = classification;
|
||||
}
|
||||
|
||||
StandardClassification stClassification =
|
||||
new StandardClassification(ctClassification, speciesID);
|
||||
|
||||
return stClassification;
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Classification interpreting " + jsonString);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import clickTrainDetector.ClickTrainControl;
|
||||
import clickTrainDetector.classification.CTClassification;
|
||||
import clickTrainDetector.classification.CTClassifier;
|
||||
import clickTrainDetector.classification.CTClassifierParams;
|
||||
import clickTrainDetector.classification.CTClassifierType;
|
||||
import clickTrainDetector.classification.bearingClassifier.BearingClassifier;
|
||||
import clickTrainDetector.classification.bearingClassifier.BearingClassifierParams;
|
||||
import clickTrainDetector.classification.idiClassifier.IDIClassification;
|
||||
@ -51,6 +52,13 @@ public class StandardClassifier implements CTClassifier {
|
||||
*/
|
||||
private ClickTrainControl clickTrainControl;
|
||||
|
||||
|
||||
/**
|
||||
* The classifier types used in the standard classifier.
|
||||
* ****New types MUST BE ADDED HERE****
|
||||
*/
|
||||
public static CTClassifierType[] CLASSIFIER_TYPES = {CTClassifierType.CHI2THRESHOLD, CTClassifierType.IDICLASSIFIER, CTClassifierType.TEMPLATECLASSIFIER, CTClassifierType.BEARINGCLASSIFIER};
|
||||
|
||||
public StandardClassifier(ClickTrainControl clickTrainControl, int speciesID) {
|
||||
this.clickTrainControl = clickTrainControl;
|
||||
standardClassifierGraphics = new StandardClassifierGraphics(clickTrainControl, this);
|
||||
@ -66,13 +74,27 @@ public class StandardClassifier implements CTClassifier {
|
||||
private void createClassifiers() {
|
||||
classifiers = new ArrayList<CTClassifier>();
|
||||
|
||||
|
||||
//do this so that is CLASSIFIER_TYPES changes order things still work.
|
||||
for (int i=0; i<CLASSIFIER_TYPES.length; i++) {
|
||||
|
||||
switch (CLASSIFIER_TYPES[i]) {
|
||||
default:
|
||||
break;
|
||||
case CHI2THRESHOLD:
|
||||
classifiers.add(new Chi2ThresholdClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID));
|
||||
|
||||
break;
|
||||
case IDICLASSIFIER:
|
||||
classifiers.add(new IDIClassifier(clickTrainControl,SUB_CLASSIFIER_SPECIESID));
|
||||
|
||||
break;
|
||||
case TEMPLATECLASSIFIER:
|
||||
classifiers.add(new CTTemplateClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID));
|
||||
|
||||
break;
|
||||
case BEARINGCLASSIFIER:
|
||||
classifiers.add(new BearingClassifier(clickTrainControl, SUB_CLASSIFIER_SPECIESID));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setClassifierParams();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user