git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@165359 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c7f90167ee
commit
2754f320a5
|
@ -55,32 +55,18 @@ public class NLPHub extends HttpServlet {
|
||||||
private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
token = Constants.getToken(request, devMode);
|
token = Constants.getToken(request, devMode);
|
||||||
try {
|
try {
|
||||||
|
String dataMiner = request.getParameter("dataminer");
|
||||||
String[] algs = request.getParameter("algs").split(",");
|
String[] algs = request.getParameter("algs").split(",");
|
||||||
for(int i=0; i<algs.length; i++) {
|
for(int i=0; i<algs.length; i++) {
|
||||||
algs[i] = algs[i].trim();
|
algs[i] = algs[i].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RunnerCommander commander = new RunnerCommander(algs, request.getParameter("plink"), request.getParameter("annotations"), token,
|
RunnerCommander commander = new RunnerCommander(dataMiner, algs, request.getParameter("plink"), request.getParameter("annotations"), token,
|
||||||
response);
|
response);
|
||||||
commander.setSleepTime(100);
|
commander.setSleepTime(100);
|
||||||
commander.setMaxWaitingTime(90*1000);
|
commander.setMaxWaitingTime(90*1000);
|
||||||
commander.startProcess();
|
commander.startProcess();
|
||||||
/*
|
|
||||||
if (algs.length >= 1) {
|
|
||||||
NlpNerRunner runner = new NlpNerRunner(service, algs, token, response);
|
|
||||||
runner.run(request.getParameter("plink"), request.getParameter("annotations"),
|
|
||||||
request.getParameter("lang"));
|
|
||||||
} else {
|
|
||||||
response.setContentType("application/json;charset=UTF-8");
|
|
||||||
try {
|
|
||||||
PrintWriter writer = response.getWriter();
|
|
||||||
writer.println(new JsonManager().getErrorJsonResponse("No algorithm identifiers given."));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
x.printStackTrace();
|
x.printStackTrace();
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class NLPUploader extends HttpServlet {
|
||||||
String sentence = NlpUtils.getLanguageRecognizerDigest(new String(content));
|
String sentence = NlpUtils.getLanguageRecognizerDigest(new String(content));
|
||||||
logger.info(sentence);
|
logger.info(sentence);
|
||||||
try {
|
try {
|
||||||
NLpLanguageRecognizer.run(sentence, token, link, response);
|
NLpLanguageRecognizer.run(request.getParameter("dataminer"), sentence, token, link, response);
|
||||||
} catch (NlpHubException ex) {
|
} catch (NlpHubException ex) {
|
||||||
writer.println(new JsonManager().getSuccessJsonResponse(Constants.UNAVAILABLE, link));
|
writer.println(new JsonManager().getSuccessJsonResponse(Constants.UNAVAILABLE, link));
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public class NLPUploader extends HttpServlet {
|
||||||
String sentence = NlpUtils.getLanguageRecognizerDigest(stringContent);
|
String sentence = NlpUtils.getLanguageRecognizerDigest(stringContent);
|
||||||
logger.info(sentence);
|
logger.info(sentence);
|
||||||
try {
|
try {
|
||||||
NLpLanguageRecognizer.run(sentence, token, link, response);
|
NLpLanguageRecognizer.run(request.getParameter("dataminer"), sentence, token, link, response);
|
||||||
} catch (NlpHubException ex) {
|
} catch (NlpHubException ex) {
|
||||||
writer.println(new JsonManager().getSuccessJsonResponse(Constants.UNAVAILABLE, link));
|
writer.println(new JsonManager().getSuccessJsonResponse(Constants.UNAVAILABLE, link));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ public class Constants {
|
||||||
public static String DEFAULT_DESCRIPTION = "NlpHub upload";
|
public static String DEFAULT_DESCRIPTION = "NlpHub upload";
|
||||||
public static String TOKEN_PARAMETER = "gcube-token";
|
public static String TOKEN_PARAMETER = "gcube-token";
|
||||||
public static String TEST_TOKEN = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
|
public static String TEST_TOKEN = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
|
||||||
|
public static String PUBLIC_TOKEN = "f57441ac-b361-4c2d-992a-40db034f1b8c-843339462";
|
||||||
public static String MIME_TEXT = "text/plain";
|
public static String MIME_TEXT = "text/plain";
|
||||||
public static String CONTENT_TYPE = "Content-Type";
|
public static String CONTENT_TYPE = "Content-Type";
|
||||||
public static String UNAVAILABLE = "unavailable";
|
public static String UNAVAILABLE = "unavailable";
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class NLpLanguageRecognizer extends DataminerClient {
|
||||||
private Logger logger = Logger.getLogger(NLpLanguageRecognizer.class.getSimpleName());
|
private Logger logger = Logger.getLogger(NLpLanguageRecognizer.class.getSimpleName());
|
||||||
private String sentence, publicLink;
|
private String sentence, publicLink;
|
||||||
public final static String RECOGNIZER_ID = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LANGUAGE_RECOGNIZER";
|
public final static String RECOGNIZER_ID = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LANGUAGE_RECOGNIZER";
|
||||||
|
private String dataMiner = null;
|
||||||
|
|
||||||
public NLpLanguageRecognizer(String service, String token, String sentence) {
|
public NLpLanguageRecognizer(String service, String token, String sentence) {
|
||||||
super(service, "", token);
|
super(service, "", token);
|
||||||
|
@ -44,18 +45,22 @@ public class NLpLanguageRecognizer extends DataminerClient {
|
||||||
response = null;
|
response = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NLpLanguageRecognizer(String service, String token, String sentence, String publicLink,
|
public NLpLanguageRecognizer(String dataMiner, String service, String token, String sentence, String publicLink,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
super(service, "", token);
|
super(service, "", token);
|
||||||
this.sentence = sentence;
|
this.sentence = sentence;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.publicLink = publicLink;
|
this.publicLink = publicLink;
|
||||||
|
this.dataMiner = dataMiner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void run(String sentence, String token, String publicLink, HttpServletResponse response) throws NlpHubException {
|
public static void run(String dataMiner, String sentence, String token, String publicLink, HttpServletResponse response) throws NlpHubException {
|
||||||
try {
|
try {
|
||||||
//String urlService = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
if(dataMiner == null)
|
||||||
String urlService = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
dataMiner = Constants.DATAMINER_URL;
|
||||||
|
else
|
||||||
|
dataMiner = "http://" + dataMiner;
|
||||||
|
String urlService = dataMiner + "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
||||||
urlService += "&gcube-token=" + token;
|
urlService += "&gcube-token=" + token;
|
||||||
urlService += "&lang=en-US";
|
urlService += "&lang=en-US";
|
||||||
urlService += "&Identifier=" + RECOGNIZER_ID;
|
urlService += "&Identifier=" + RECOGNIZER_ID;
|
||||||
|
|
|
@ -20,13 +20,13 @@ import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
public final static String WPS_EXECUTE_URL = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
public static String WPS_EXECUTE_URL = "/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0";
|
||||||
public final static String WPS_DESCRIBE_PROCESS_URL = Constants.DATAMINER_URL + "/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0";
|
public static String WPS_DESCRIBE_PROCESS_URL = "/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0";
|
||||||
private String identifier, token, httpMethod, annotations, publicLink, language;
|
private String identifier, token, httpMethod, annotations, publicLink, language, dataMiner;
|
||||||
private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName());
|
private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName());
|
||||||
private RunnerCommander commander;
|
private RunnerCommander commander;
|
||||||
|
|
||||||
public NlpAsyncNerRunner(String identifier, String token, String publicLink, String annotations, String language, RunnerCommander commander) {
|
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations, String language, RunnerCommander commander) {
|
||||||
super();
|
super();
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -35,8 +35,13 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
this.publicLink = publicLink;
|
this.publicLink = publicLink;
|
||||||
this.language = language; // not used for the moment...
|
this.language = language; // not used for the moment...
|
||||||
this.commander = commander;
|
this.commander = commander;
|
||||||
|
if(dataMiner == null)
|
||||||
|
this.dataMiner = Constants.DATAMINER_URL;
|
||||||
|
else
|
||||||
|
this.dataMiner = "http://" + dataMiner;
|
||||||
|
|
||||||
ArrayList<NlpParameter> params = buildParameterString();
|
ArrayList<NlpParameter> params = buildParameterString();
|
||||||
String serviceUrl = WPS_EXECUTE_URL + "&gcube-token=" + token + "&lang=en-US&Identifier=" + identifier;
|
String serviceUrl = this.dataMiner + WPS_EXECUTE_URL + "&gcube-token=" + token + "&lang=en-US&Identifier=" + identifier;
|
||||||
serviceUrl += "&" + setUrl(params);
|
serviceUrl += "&" + setUrl(params);
|
||||||
super.setBaseUrl(serviceUrl);
|
super.setBaseUrl(serviceUrl);
|
||||||
super.setMethod(httpMethod);
|
super.setMethod(httpMethod);
|
||||||
|
@ -75,7 +80,7 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
BufferedReader r = null;
|
BufferedReader r = null;
|
||||||
try {
|
try {
|
||||||
String finalUrl = WPS_DESCRIBE_PROCESS_URL + "&gcube-token=" + token;
|
String finalUrl = dataMiner + WPS_DESCRIBE_PROCESS_URL + "&gcube-token=" + token;
|
||||||
finalUrl += "&lang=en-US&Identifier=" + identifier;
|
finalUrl += "&lang=en-US&Identifier=" + identifier;
|
||||||
URL url = new URL(finalUrl);
|
URL url = new URL(finalUrl);
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
@ -173,17 +178,4 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
logger.error(x.getLocalizedMessage());
|
logger.error(x.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// String id1 = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.ENGLISH_NAMED_ENTITY_RECOGNIZER";
|
|
||||||
// String id2 = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.ENGLISH_NER_CORENLP";
|
|
||||||
// String tokken = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
|
|
||||||
// String ann = "Organization,Location,Person";
|
|
||||||
// String file = "http://data.d4science.org/TWhNTS9DdVdXaTZLSWsrWUNQdHk3OUdZSU93SXRFbjhHbWJQNStIS0N6Yz0";
|
|
||||||
// file = "http://data.d4science.org/L0txb3o3Tk9GaW1LSWsrWUNQdHk3MG1ZWFdtWkJENU5HbWJQNStIS0N6Yz0";
|
|
||||||
// NlpAsyncNerRunner n1 = new NlpAsyncNerRunner(id1, tokken, file, ann, null);
|
|
||||||
// NlpAsyncNerRunner n2 = new NlpAsyncNerRunner(id2, tokken, file, ann, null);
|
|
||||||
// n2.start();
|
|
||||||
// n1.start();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,23 +15,25 @@ public class RunnerCommander extends Thread {
|
||||||
private String[] identifiers = null;
|
private String[] identifiers = null;
|
||||||
private String link = "";
|
private String link = "";
|
||||||
private String token = "";
|
private String token = "";
|
||||||
|
private String dataMiner;
|
||||||
private ArrayList<String> outResultList = null;
|
private ArrayList<String> outResultList = null;
|
||||||
private long sleepTime = 500l;
|
private long sleepTime = 500l;
|
||||||
private long maxWaitingTime = 5l * 60l * 1000l;
|
private long maxWaitingTime = 5l * 60l * 1000l;
|
||||||
private Logger logger = Logger.getLogger(RunnerCommander.class.getSimpleName());
|
private Logger logger = Logger.getLogger(RunnerCommander.class.getSimpleName());
|
||||||
private boolean complete = false;
|
private boolean complete = false;
|
||||||
|
|
||||||
public RunnerCommander(String[] identifiers, String link, String annotationList, String token) {
|
public RunnerCommander(String dataMiner, String[] identifiers, String link, String annotationList, String token) {
|
||||||
this.identifiers = identifiers;
|
this.identifiers = identifiers;
|
||||||
this.annotationList = annotationList;
|
this.annotationList = annotationList;
|
||||||
this.link = link;
|
this.link = link;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.response = null;
|
this.response = null;
|
||||||
this.sleepTime = 500l;
|
this.sleepTime = 500l;
|
||||||
|
this.dataMiner = dataMiner;
|
||||||
outResultList = new ArrayList<String>();
|
outResultList = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunnerCommander(String[] identifiers, String link, String annotationList, String token,
|
public RunnerCommander(String dataMiner, String[] identifiers, String link, String annotationList, String token,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
this.identifiers = identifiers;
|
this.identifiers = identifiers;
|
||||||
this.annotationList = annotationList;
|
this.annotationList = annotationList;
|
||||||
|
@ -39,6 +41,7 @@ public class RunnerCommander extends Thread {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.sleepTime = 500l;
|
this.sleepTime = 500l;
|
||||||
|
this.dataMiner = dataMiner;
|
||||||
outResultList = new ArrayList<String>();
|
outResultList = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +84,7 @@ public class RunnerCommander extends Thread {
|
||||||
|
|
||||||
private void runAlgorithms() {
|
private void runAlgorithms() {
|
||||||
for (String id : identifiers) {
|
for (String id : identifiers) {
|
||||||
NlpAsyncNerRunner n = new NlpAsyncNerRunner(id, token, link, annotationList, null, this);
|
NlpAsyncNerRunner n = new NlpAsyncNerRunner(dataMiner, id, token, link, annotationList, null, this);
|
||||||
n.start();
|
n.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue