Starting to map species codes

This commit is contained in:
Douglas Gillespie 2023-07-03 17:53:35 +01:00
parent 75470b450b
commit cd70026cf8
9 changed files with 214 additions and 1 deletions

View File

@ -3102,6 +3102,16 @@ public class PamDataBlock<Tunit extends PamDataUnit> extends PamObservable {
public void setTethysDataProvider(TethysDataProvider tethysDataProvider) {
this.tethysDataProvider = tethysDataProvider;
}
/**
* Get information about species types that may occur within this data
* block.
* @return Types of species information available within this datablock.
*/
public tethys.species.SpeciesTypes getSpeciesTypes() {
return null;
}
final public boolean getCanLog() {
return (logging != null);

View File

@ -129,7 +129,6 @@ public class DBXMLQueries {
String queryResult = null;
String schemaPlan = null;
TethysExportParams params = tethysControl.getTethysExportParams();
try {
JerseyClient jerseyClient = dbxmlConnect.getJerseyClient();

View File

@ -67,4 +67,5 @@ public interface TethysDataProvider {
public Parameters getAlgorithmParameters();
}

View File

@ -0,0 +1,12 @@
package tethys.species;
import java.io.Serializable;
/**
* Species map for a specified data block
* @author dg50
*
*/
public class DatablockSpeciesMap implements Serializable {
}

View File

@ -0,0 +1,19 @@
package tethys.species;
import java.io.Serializable;
public class SpeciesMapItem implements Serializable, Cloneable {
public static final long serialVersionUID = 1L;
private int itisCode;
private String pamguardName;
private String latinName;
private String commonName;
private String callType;
}

View File

@ -0,0 +1,5 @@
package tethys.species;
public class SpeciesMapManager {
}

View File

@ -0,0 +1,110 @@
package tethys.species;
import dbxml.JerseyClient;
import dbxml.Queries;
import tethys.dbxml.DBQueryResult;
import tethys.dbxml.TethysQueryException;
public class SpeciesTest extends SpeciesTypes {
String uri = "http://localhost:9779";
public static void main(String[] args) {
SpeciesTest st = new SpeciesTest();
st.runJson();
// int spermWhale = 180488;
// st.getCodeInfo(spermWhale);
// st.runXQuery();
}
private void getCodeInfo(int itisCode) {
System.out.println("Running getCodeInfo()");
String jQBase = "{\"return\":[\"ranks/rank\"],\"select\":[{\"op\":\"=\",\"operands\":[\"ranks/rank/tsn\",\"SPECIESTSN\"],\"optype\":\"binary\"}],\"enclose\":1}";
String jQ = jQBase.replace("SPECIESTSN", String.format("%d", itisCode));
DBQueryResult result = null;
String queryResult = null;
String schemaPlan = null;
JerseyClient jerseyClient = new JerseyClient(uri);
long t1 = System.nanoTime();
try {
queryResult = jerseyClient.queryJSON(jQ, 0);
// schemaPlan = jerseyClient.queryJSON(jQ, 1);
} catch (Exception e1) {
e1.printStackTrace();
}
long t2 = System.nanoTime();
System.out.printf("Query time was %3.1fms\n" , (double) (t2-t1)/1e6);
System.out.println(queryResult);
TethysITISResult itisResult = new TethysITISResult(queryResult);
}
/*
*
<ranks xmlns="http://tethys.sdsu.edu/schema/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tethys.sdsu.edu/schema/1.0 tethys.xsd">
<rank>
<tsn>-10</tsn>
<completename>Other phenomena</completename>
<vernacular>
<name language="English">Other</name>
<name language="French">Autre</name>
<name language="Spanish">Otro</name>
</vernacular>
</rank>
<rank>
<tsn>555654</tsn>
<completename>Delphinus capensis</completename>
<vernacular>
<name language="English">Long-beaked Common Dolphin</name>
</vernacular>
</rank>
*/
private void runXQuery() {
System.out.println("Running runXQuery()");
String queryBase = "count(collection(\"Detections\")/Detections[Id=\"ReplaceDocumentId\"]/OnEffort/Detection)";
String xQ = "collection(\"ITIS_ranks\")/ty:ranks/ty:rank[dbxml:contains(ty:completename, \"Physeter\")]";
JerseyClient jerseyClient = new JerseyClient(uri);
Queries queries = new Queries(jerseyClient);
String result = null;
try {
result = queries.QueryTethys(xQ);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(result);
}
private void runJson() {
// String jQ = "{\"return\":[\"Deployment\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/Project\",\"DCLDE2022\"],\"optype\":\"binary\"}],\"enclose\":1}";
// String jQ = "{\"return\":[\"ranks/rank\"],\"select\":[{\"op\":\"=\",\"operands\":[\"ranks/rank/tsn\",\"624908\"],\"optype\":\"binary\"}],\"enclose\":1}";
// String jQ = "{\"return\":[\"ranks/rank\"],\"select\":[{\"op\":\"=\",\"operands\":[\"ranks/rank/completename\",\"Mesoplodon\"],\"optype\":\"binary\"}],\"enclose\":1}";
String jQ = "{\"return\":[\"ranks/rank\"],\"select\":[{\"op\":\"dbxml:contains\",\"operands\":[\"ranks/rank/completename\",\"Mesoplodon\"],\"optype\":\"function\"}],\"enclose\":1}";
System.out.println(jQ);
DBQueryResult result = null;
String queryResult = null;
String schemaPlan = null;
JerseyClient jerseyClient = new JerseyClient(uri);
long t1 = System.nanoTime();
try {
queryResult = jerseyClient.queryJSON(jQ, 0);
// schemaPlan = jerseyClient.queryJSON(jQ, 1);
} catch (Exception e1) {
System.out.println("epic fail");
e1.printStackTrace();
}
long t2 = System.nanoTime();
System.out.printf("Query time was %3.1fms\n" , (double) (t2-t1)/1e6);
System.out.println(queryResult);
}
}

View File

@ -0,0 +1,20 @@
package tethys.species;
import java.util.ArrayList;
/**
* Class to return lists of species codes or names for a datablock.
* This information will then get incorporated into a more complicated translation table to
* provide PAMGuard data on it's way to Tethys with more rigid species code definitions.
* @author dg50
*
*/
public class SpeciesTypes {
/**
* List of species names / codes associated with this data block.
*/
private ArrayList<String> speciesNames;
}

View File

@ -0,0 +1,37 @@
package tethys.species;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* Class to hold and unpack a XML string returned from the ITIS_ranks document
* in a Tethys database.
* @author dg50
*
*/
public class TethysITISResult {
/**
* Construct a ITIS object from XML data
* @param xmlData
*/
public TethysITISResult(String xmlData) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//API to obtain DOM Document instance
DocumentBuilder builder = null;
// //Create DocumentBuilder with default configuration
// builder = factory.newDocumentBuilder();
//
// //Parse the content to Document object
// Document doc = builder.parse(new InputSource(new StringReader(xmlData)));
}
}