mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
Starting to map species codes
This commit is contained in:
parent
75470b450b
commit
cd70026cf8
@ -3103,6 +3103,16 @@ public class PamDataBlock<Tunit extends PamDataUnit> extends PamObservable {
|
|||||||
this.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() {
|
final public boolean getCanLog() {
|
||||||
return (logging != null);
|
return (logging != null);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,6 @@ public class DBXMLQueries {
|
|||||||
|
|
||||||
String queryResult = null;
|
String queryResult = null;
|
||||||
String schemaPlan = null;
|
String schemaPlan = null;
|
||||||
TethysExportParams params = tethysControl.getTethysExportParams();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JerseyClient jerseyClient = dbxmlConnect.getJerseyClient();
|
JerseyClient jerseyClient = dbxmlConnect.getJerseyClient();
|
||||||
|
@ -67,4 +67,5 @@ public interface TethysDataProvider {
|
|||||||
|
|
||||||
public Parameters getAlgorithmParameters();
|
public Parameters getAlgorithmParameters();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
src/tethys/species/DatablockSpeciesMap.java
Normal file
12
src/tethys/species/DatablockSpeciesMap.java
Normal 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 {
|
||||||
|
|
||||||
|
}
|
19
src/tethys/species/SpeciesMapItem.java
Normal file
19
src/tethys/species/SpeciesMapItem.java
Normal 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;
|
||||||
|
|
||||||
|
}
|
5
src/tethys/species/SpeciesMapManager.java
Normal file
5
src/tethys/species/SpeciesMapManager.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package tethys.species;
|
||||||
|
|
||||||
|
public class SpeciesMapManager {
|
||||||
|
|
||||||
|
}
|
110
src/tethys/species/SpeciesTest.java
Normal file
110
src/tethys/species/SpeciesTest.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/tethys/species/SpeciesTypes.java
Normal file
20
src/tethys/species/SpeciesTypes.java
Normal 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;
|
||||||
|
|
||||||
|
}
|
37
src/tethys/species/TethysITISResult.java
Normal file
37
src/tethys/species/TethysITISResult.java
Normal 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)));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user