Skip to content

Commit

Permalink
add cosine service
Browse files Browse the repository at this point in the history
  • Loading branch information
leinfelder committed Sep 14, 2016
1 parent fa84af5 commit c21320e
Showing 1 changed file with 64 additions and 0 deletions.
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;


}


}

0 comments on commit c21320e

Please sign in to comment.