-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa84af5
commit c21320e
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/org/dataone/annotator/matcher/esor/CosineService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.dataone.annotator.matcher.esor; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.dataone.annotator.matcher.ConceptItem; | ||
import org.dataone.annotator.matcher.ConceptMatcher; | ||
|
||
public class CosineService implements ConceptMatcher { | ||
|
||
private static Log log = LogFactory.getLog(CosineService.class); | ||
|
||
//the cosine server | ||
private static final String REST_URL = "https://esor.tw.rpi.edu/cosine/"; | ||
|
||
|
||
public CosineService() { | ||
} | ||
|
||
|
||
@Override | ||
public List<ConceptItem> getConcepts(String fullText, String unit, String context) throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<ConceptItem> getConcepts(Map<String, String> queryItems) throws Exception { | ||
return null; | ||
} | ||
|
||
public static String lookupCosine(String id) throws Exception { | ||
|
||
HttpClient client = HttpClients.createDefault(); | ||
String uriStr = REST_URL + id; | ||
log.debug("uriStr=" + uriStr); | ||
|
||
// use post to handle potentially long parameter values | ||
HttpGet method = new HttpGet(uriStr); | ||
method.setHeader("Accept", "*/*"); | ||
|
||
HttpResponse response = client.execute(method); | ||
int code = response.getStatusLine().getStatusCode(); | ||
if (2 != code / 100) { | ||
throw new Exception("response code " + code + " for resource at " + uriStr); | ||
} | ||
InputStream body = response.getEntity().getContent(); | ||
String jsonStr = IOUtils.toString(body, "UTF-8"); | ||
log.debug("jsonStr=" + jsonStr); | ||
|
||
return jsonStr; | ||
|
||
|
||
} | ||
|
||
|
||
} |