Skip to content
Snippets Groups Projects
Commit b1ba04af authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

lots of bugfixing, storage of incorrect names, etc

parent 4c86f126
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,9 @@ public class BioTree {
//FIXME: replace with a single kd-tree
private static BST<Integer, TaxonNode> idNodes = new BST<Integer, TaxonNode>();
private static BST<String, TaxonNode> strNodes = new BST<String, TaxonNode>();
private static BST<String, Integer> incorrectNames = new BST<String, Integer>();
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, ParseException {
BioTree.processRecord("Catostomus commersoni");
}
......@@ -64,16 +65,27 @@ public class BioTree {
* @param scientificName The scientific name of the possible new entry
* @return taxonId of new / existing entry
* @throws IOException
* @throws ParseException
*/
public static Integer processRecord(String scientificName) throws IOException {
public static Integer processRecord(String scientificName) throws IOException, ParseException {
//reverse lookup based on name, try adding the found taxonId.
TaxonNode res = strNodes.get(scientificName);
if (res == null) {
System.out.println("Not already found.");
Integer incorrectNameId = incorrectNames.get(scientificName);
if (incorrectNameId != null) if (incorrectNameId == -1) return null;
res = idNodes.get(incorrectNameId);
}
Integer taxonId = null;
if (res == null) {
try {
taxonId = WormsAPI.nameToID(scientificName);
} catch (Exception e) {
taxonId = WormsAPI.fuzzyNameToID(scientificName);
if (taxonId != null)
incorrectNames.put(scientificName, taxonId);
else
incorrectNames.put(scientificName, -1);
}
if (taxonId == -999)
taxonId = WormsAPI.fuzzyNameToID(scientificName);
......
......@@ -8,6 +8,8 @@ import java.util.Scanner; // Testing ONLY
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.simple.parser.ParseException;
/**
* This class reads and parses files in the format of occurences.csv
* It provides methods to get chunks of data.
......@@ -41,8 +43,10 @@ public class FileProcessor {
* Initialize Processing.
* Reads file at path.
* Calls parse() for each line
* @throws ParseException
* @throws NumberFormatException
*/
private static void initProcessing() {
private static void initProcessing() throws NumberFormatException, ParseException {
FileReader fr;
BufferedReader br;
......@@ -65,6 +69,7 @@ public class FileProcessor {
//initialize the storage of records
DataStore.init(al.toArray(new Record[al.size()]));
al = null;
s.close();//Testing ONLY
br.close();
......@@ -81,8 +86,10 @@ public class FileProcessor {
*
* @param currentLine, a line/row of data
* @throws IOException
* @throws ParseException
* @throws NumberFormatException
*/
private static void parse(String currentLine) throws IOException {
private static void parse(String currentLine) throws IOException, NumberFormatException, ParseException {
/* Regex Pattern Grouping Guide
* Retrieve String Groups with: matchEventId.group(x):
* group 0: full matched string
......@@ -125,8 +132,10 @@ public class FileProcessor {
* Calls BioTree's processRecord and another method to create a Record
*
* @param matchEventId
* @throws ParseException
* @throws NumberFormatException
*/
public static void createObjects(Matcher matchEventId) {
public static void createObjects(Matcher matchEventId) throws NumberFormatException, ParseException {
// Call BioTree
Record rec = null;
// if(matchEventId.group(9) != null) {
......@@ -170,7 +179,7 @@ public class FileProcessor {
return new Record(eventId, occurId, taxonId, individualCount, latitude, longitude, year, month, day);
}
public static void main(String[] args) {
public static void main(String[] args) throws NumberFormatException, ParseException {
initProcessing();
}
}
......@@ -64,13 +64,14 @@ public class WormsAPI {
* @throws IOException
* @throws ParseException
*/
public static int fuzzyNameToID(String fuzzyName) throws IOException, ParseException {
//System.out.println("Fuzzy name: " + fuzzyName);
public static Integer fuzzyNameToID(String fuzzyName) throws IOException, ParseException {
System.out.println("Fuzzy name: " + fuzzyName);
fuzzyName = repSpaces(fuzzyName);
String resp = makeRequest(String.format(
"http://marinespecies.org/rest/AphiaRecordsByMatchNames?scientificnames%%5B%%5D=%s&marine_only=true",
"http://marinespecies.org/rest/AphiaRecordsByMatchNames?scientificnames%%5B%%5D=%s&marine_only=false",
fuzzyName));
if (resp.length() == 0) return null;
JSONParser parser = new JSONParser();
JSONArray json = (JSONArray) parser.parse(resp);
......
......@@ -28,7 +28,7 @@ public class BST<Key extends Comparable<Key>, Value> {
else return x.N;
}
public Value get(Key key) { return get(root, key); }
public Value get(Key key) { if (key == null) return null; return get(root, key); }
private Value get(Node x, Key key) {
if (x == null) return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment