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
44b67022d2
commit
38c7ceb942
@ -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) {
|
||||
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;
|
||||
if (na != null ) {
|
||||
speciesID = na.asInt();
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot load template classifier");
|
||||
|
||||
JsonNode na = jTree.findValue("SPECIES");
|
||||
int speciesID;
|
||||
if (na != null ) {
|
||||
speciesID = na.asInt();
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot load standard classifier");
|
||||
return null;
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
CTClassification[] ctClassification = new CTClassification[standardClassifier.length];
|
||||
for (int i=0; i<standardClassifier.length; i++) {
|
||||
ctClassification[i] = ((SimpleClassifierJSONLogging) standardClassifier[i].getJSONLogging()).createClassification(jTree);
|
||||
}
|
||||
|
||||
StandardClassification stClassification =
|
||||
new StandardClassification(ctClassification, speciesID);
|
||||
|
||||
return stClassification;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user