From 314914234412d88994d1a4d02be28d8962704ce3 Mon Sep 17 00:00:00 2001 From: Schankula Christopher <schankuc@mcmaster.ca> Date: Tue, 27 Mar 2018 18:18:15 -0400 Subject: [PATCH] new TrawlExpert object api for getting a certain taxon node from a scientific name --- src/data/BioTree.java | 20 ++++++++++++++++++-- src/model/TrawlExpert.java | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/data/BioTree.java b/src/data/BioTree.java index 362adfc..97ec7ed 100644 --- a/src/data/BioTree.java +++ b/src/data/BioTree.java @@ -170,7 +170,7 @@ public class BioTree implements Serializable { */ public static Integer processRecord(String scientificName) throws IOException, ParseException { //reverse lookup based on name, try adding the found taxonId. - Integer taxonId = getTaxonRecord(scientificName); + Integer taxonId = nameToTaxonId(scientificName); System.out.println(scientificName + ": " + taxonId); if (taxonId == null) return null; if (taxonId == -1) return null; @@ -237,6 +237,22 @@ public class BioTree implements Serializable { return idNodes.get(taxonId); } + /** + * Get the species at a given index (taxonId). This assumes that the + * node already exists or else it will return null. As such, it is best + * to use this function once all the data has been parsed and the BioTree + * has been built. + * + * @param i + * The speciesid (index) of the species. + * @return The Species object. + * @throws ParseException + * @throws IOException + */ + public static TaxonNode getTaxonRecord(String scientificName) throws IOException, ParseException { + return idNodes.get(nameToTaxonId(scientificName)); + } + /** * Get the TaxonNode containing information about the given scientific name. * This assumes that thenode already exists locally or else it will return null. @@ -249,7 +265,7 @@ public class BioTree implements Serializable { * @throws ParseException * @throws IOException */ - public static Integer getTaxonRecord(String scientificName) throws IOException, ParseException { + public static Integer nameToTaxonId(String scientificName) throws IOException, ParseException { Integer taxonId; //look up based on string literal, return if found TaxonNode tx = strNodes.get(scientificName); diff --git a/src/model/TrawlExpert.java b/src/model/TrawlExpert.java index 70b8667..a0a1ed4 100644 --- a/src/model/TrawlExpert.java +++ b/src/model/TrawlExpert.java @@ -1,11 +1,14 @@ package model; +import java.io.IOException; + import org.json.simple.parser.ParseException; import data.BioTree; import data.DataStore; import data.FileProcessor; import data.Record; +import data.TaxonNode; import search.BasicSearch; import search.BasicSearchResult; import sort.KDT; @@ -37,4 +40,18 @@ public class TrawlExpert { public BasicSearchResult rangeSearch(Integer taxonId, Integer yearLo, Integer yearHi) { return BasicSearch.range(taxonId, yearLo, yearHi); } + + public TaxonNode getTaxonRecord(Integer taxonId) { + return BioTree.getTaxonRecord(taxonId); + } + + public TaxonNode getTaxonRecord(String scientificName) { + try { + return BioTree.getTaxonRecord(scientificName); + } catch (IOException | ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } } -- GitLab