Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2XB3FinalProject
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Schankula
2XB3FinalProject
Commits
1c4690cd
Commit
1c4690cd
authored
7 years ago
by
Ray Liu
Browse files
Options
Downloads
Patches
Plain Diff
Added nameToRecordID function that uses a faster API call than fuzzyname
parent
f246c7f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/biotree/WormsAPI.java
+31
-2
31 additions, 2 deletions
src/biotree/WormsAPI.java
with
31 additions
and
2 deletions
src/biotree/WormsAPI.java
+
31
−
2
View file @
1c4690cd
...
...
@@ -13,6 +13,8 @@ import org.json.simple.parser.JSONParser;
import
org.json.simple.parser.ParseException
;
import
org.json.simple.JSONArray
;
import
org.json.simple.JSONObject
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
public
class
WormsAPI
{
...
...
@@ -20,7 +22,7 @@ public class WormsAPI {
public
static
void
main
(
String
[]
args
)
throws
IOException
,
ParseException
{
// small test
//System.out.println(nameToID("Neogobius melanostomus"));
//System.out.println(
fuzzyNameTo
ID("Neogobius melanostomus"));
//System.out.println(
nameToRecord
ID("Neogobius melanostomus"));
/*
* TaxonNode[] taxnodes = idToClassification(126916);
*
...
...
@@ -65,7 +67,7 @@ public class WormsAPI {
* @throws ParseException
*/
public
static
Integer
fuzzyNameToID
(
String
fuzzyName
)
throws
IOException
,
ParseException
{
System
.
out
.
println
(
"Fuzzy name: "
+
fuzzyName
);
//
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=false"
,
...
...
@@ -80,6 +82,33 @@ public class WormsAPI {
return
(
int
)
(
long
)
first
.
get
(
"AphiaID"
);
}
/**
* Search the WORMS database by a scientific name from multiple records
*
* @param Name
* @return Aphia (taxon) ID of given scientific name.
* @throws IOException
* @throws ParseException
*/
public
static
Integer
nameToRecordID
(
String
Name
)
throws
IOException
,
ParseException
{
//System.out.println( Name);
Name
=
repSpaces
(
Name
);
String
resp
=
makeRequest
(
String
.
format
(
"http://marinespecies.org/rest/AphiaRecordsByName/%s?like=true&marine_only=false&offset=1"
,
Name
));
if
(
resp
.
length
()
==
0
)
return
null
;
JSONParser
parser
=
new
JSONParser
();
JSONArray
json
=
(
JSONArray
)
parser
.
parse
(
resp
);
int
id
=
(
int
)
(
long
)
((
JSONObject
)
json
.
get
(
0
)).
get
(
"AphiaID"
);
return
id
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment