diff --git a/src/main/java/org/gcube/nlphub/NLPHub.java b/src/main/java/org/gcube/nlphub/NLPHub.java index 2a19c1e..eeb026e 100644 --- a/src/main/java/org/gcube/nlphub/NLPHub.java +++ b/src/main/java/org/gcube/nlphub/NLPHub.java @@ -2,32 +2,18 @@ package org.gcube.nlphub; import java.io.IOException; import java.io.PrintWriter; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; import javax.servlet.ServletException; -import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; -import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; -import org.gcube.data.analysis.dataminermanagercl.shared.data.OutputData; -import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId; -import org.gcube.data.analysis.dataminermanagercl.shared.data.output.MapResource; -import org.gcube.data.analysis.dataminermanagercl.shared.data.output.Resource; -import org.gcube.data.analysis.dataminermanagercl.shared.parameters.FileParameter; -import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ObjectParameter; -import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter; import org.gcube.nlphub.legacy.Constants; -import org.gcube.nlphub.legacy.DataminerClient; import org.gcube.nlphub.legacy.JsonManager; -//import org.gcube.dataminerclient.DataminerClient; import org.gcube.nlphub.nlp.NlpNerRunner; +import org.gcube.nlphub.nlp.RunnerCommander; /** * Servlet implementation class NLPHub @@ -76,6 +62,11 @@ public class NLPHub extends HttpServlet { } + RunnerCommander commander = new RunnerCommander(algs, request.getParameter("plink"), request.getParameter("annotations"), token, + response); + commander.setSleepTime(100); + commander.startProcess(); + /* if (algs.length >= 1) { NlpNerRunner runner = new NlpNerRunner(service, algs, token, response); runner.run(request.getParameter("plink"), request.getParameter("annotations"), @@ -88,7 +79,8 @@ public class NLPHub extends HttpServlet { } catch (Exception ex) { logger.error(ex.getLocalizedMessage()); } - } + }*/ + } catch (Exception x) { x.printStackTrace(); } diff --git a/src/main/java/org/gcube/nlphub/NLPMapper.java b/src/main/java/org/gcube/nlphub/NLPMapper.java index e817dcc..4f560e5 100644 --- a/src/main/java/org/gcube/nlphub/NLPMapper.java +++ b/src/main/java/org/gcube/nlphub/NLPMapper.java @@ -67,9 +67,9 @@ public class NLPMapper extends HttpServlet { response.setCharacterEncoding("utf-8"); token = Constants.getToken(request, devMode); String documentLink = request.getParameter("plink"); // link to text file (workspace) - System.out.println("documentLink\n: " + documentLink); + //System.out.println("documentLink\n: " + documentLink); String toBeMap = request.getParameter("tobemap"); - System.out.println("tobemap:\n" + toBeMap); + //System.out.println("tobemap:\n" + toBeMap); String[] tokens; if(toBeMap.indexOf("|") > 0) tokens = toBeMap.split("\\|"); @@ -79,15 +79,15 @@ public class NLPMapper extends HttpServlet { } String annotations = request.getParameter("annotations"); - System.out.println("annotations\n: " + annotations); + //System.out.println("annotations\n: " + annotations); String language = request.getParameter("lang"); PrintWriter writer = response.getWriter(); - System.out.println("language\n: " + language); + //System.out.println("language\n: " + language); - System.out.println("tokens length: " + tokens.length); - for(int u=0; u parameters; + private Logger logger = Logger.getLogger(AsyncHttpRequest.class.getSimpleName()); + protected long elapsedTime; + + public AsyncHttpRequest() { + this.baseUrl = null; + this.parameters = null; + this.method = "GET"; + finalUrl = null; + elapsedTime = 0; + } + + public AsyncHttpRequest(String baseUrl, String method, ArrayList parameters) { + this.baseUrl = baseUrl; + this.parameters = parameters; + if(method == null) + this.method = "GET"; + else + this.method = (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("POST")) ? method : "GET"; + setFinalUrl(); + elapsedTime = 0; + } + + public void run() { + elapsedTime = System.currentTimeMillis(); + if(finalUrl == null) + finalUrl = baseUrl; + HttpURLConnection connection = null; + BufferedReader r = null; + try { + URL url = new URL(finalUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setUseCaches(false); + connection.setRequestMethod(method); + r = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line = ""; + result = ""; + + while (line != null) { + line = r.readLine(); + if (line != null) + result += line.trim(); + } + + asyncHttpRequestCallback(); + + } catch (Exception x) { + logger.error(x.getLocalizedMessage()); + } finally { + try { + if (r != null) + r.close(); + if (connection != null) + connection.disconnect(); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + } + } + } + + public String getResult() { + return result; + } + + public void asyncHttpRequestCallback() { + elapsedTime = System.currentTimeMillis() - elapsedTime; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public void setMethod(String method) { + this.method = method; + } + + public void setParameters(ArrayList parameters) { + this.parameters = parameters; + } + + private void setFinalUrl() { + finalUrl = baseUrl; + if (parameters != null) { + if (finalUrl.indexOf("?") < 0) + finalUrl += "?"; + for (NlpParameter p : parameters) { + try { + finalUrl += p.getName() + "=" + URLEncoder.encode((String) p.getValue(), "UTF-8"); + finalUrl += "&"; + } catch (Exception x) { + logger.error(x.getLocalizedMessage()); + } + } + finalUrl = finalUrl.substring(0, finalUrl.length() - 1); + } + } +} diff --git a/src/main/java/org/gcube/nlphub/legacy/Constants.java b/src/main/java/org/gcube/nlphub/legacy/Constants.java index a239627..8cab1fd 100644 --- a/src/main/java/org/gcube/nlphub/legacy/Constants.java +++ b/src/main/java/org/gcube/nlphub/legacy/Constants.java @@ -7,7 +7,8 @@ public class Constants { public static String TEST_TOKEN = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462"; public static String MIME_TEXT = "text/plain"; public static String CONTENT_TYPE = "Content-Type"; - + public static String UNAVAILABLE = "unavailable"; + public static String ERROR_ID = "ERROR"; public static String getToken(HttpServletRequest request, boolean devMode) { String token = request.getParameter(TOKEN_PARAMETER); diff --git a/src/main/java/org/gcube/nlphub/legacy/DataminerClient.java b/src/main/java/org/gcube/nlphub/legacy/DataminerClient.java index d9b6bdc..fdb56b6 100644 --- a/src/main/java/org/gcube/nlphub/legacy/DataminerClient.java +++ b/src/main/java/org/gcube/nlphub/legacy/DataminerClient.java @@ -127,7 +127,7 @@ public class DataminerClient { @Override public void running(double percentage) { - logger.debug("Operation Running: " + percentage); + //logger.debug("Operation Running: " + percentage); //System.out.println("Operation Running: " + percentage); } diff --git a/src/main/java/org/gcube/nlphub/nlp/NLpLanguageRecognizer.java b/src/main/java/org/gcube/nlphub/nlp/NLpLanguageRecognizer.java index 94581ec..cff255d 100644 --- a/src/main/java/org/gcube/nlphub/nlp/NLpLanguageRecognizer.java +++ b/src/main/java/org/gcube/nlphub/nlp/NLpLanguageRecognizer.java @@ -80,14 +80,14 @@ public class NLpLanguageRecognizer extends DataminerClient { String link = data.getTextContent(); String type = description.getTextContent(); if(type.equals("outfile")) { - System.out.println(link); + //System.out.println(link); String content = readFileContent(link, token); if (response != null) { response.getWriter() .println(new JsonManager().getSuccessJsonResponse(content, publicLink)); } else { - System.out.println(new JsonManager().getSuccessJsonResponse(content, publicLink)); + Logger.getLogger(NLpLanguageRecognizer.class.getSimpleName()).debug(new JsonManager().getSuccessJsonResponse(content, publicLink)); } } } diff --git a/src/main/java/org/gcube/nlphub/nlp/NlpAsyncNerRunner.java b/src/main/java/org/gcube/nlphub/nlp/NlpAsyncNerRunner.java new file mode 100644 index 0000000..cec8688 --- /dev/null +++ b/src/main/java/org/gcube/nlphub/nlp/NlpAsyncNerRunner.java @@ -0,0 +1,188 @@ +package org.gcube.nlphub.nlp; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.log4j.Logger; +import org.gcube.nlphub.legacy.AsyncHttpRequest; +import org.gcube.nlphub.legacy.Constants; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +public class NlpAsyncNerRunner extends AsyncHttpRequest { + public final static String WPS_EXECUTE_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=Execute&service=WPS&Version=1.0.0"; + public final static String WPS_DESCRIBE_PROCESS_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService?request=DescribeProcess&service=WPS&Version=1.0.0"; + private String identifier, token, httpMethod, annotations, publicLink, language; + private Logger logger = Logger.getLogger(NlpAsyncNerRunner.class.getSimpleName()); + + public NlpAsyncNerRunner(String identifier, String token, String publicLink, String annotations, String language) { + super(); + this.identifier = identifier; + this.token = token; + this.httpMethod = "GET"; + this.annotations = annotations; + this.publicLink = publicLink; + this.language = language; // not used for the moment... + ArrayList params = buildParameterString(); + String serviceUrl = WPS_EXECUTE_URL + "&gcube-token=" + token + "&lang=en-US&Identifier=" + identifier; + serviceUrl += "&" + setUrl(params); + super.setBaseUrl(serviceUrl); + super.setMethod(httpMethod); + //System.out.println(serviceUrl); + } + + public NlpAsyncNerRunner(String baseUrl, String method) { + super(baseUrl, method, null); + } + + public String getIdentifier() { + return identifier; + } + + public String getToken() { + return token; + } + + public String getHttpMethod() { + return httpMethod; + } + + private String setUrl(ArrayList parameters) { + String url = "DataInputs="; + for (NlpParameter p : parameters) { + try { + url += p.getName() + "=" + URLEncoder.encode((String) p.getValue(), "UTF-8") + ";"; + } catch (Exception ex) { + logger.error(ex.getLocalizedMessage()); + } + } + return url; + } + + private ArrayList buildParameterString() { + ArrayList parameters = new ArrayList<>(); + HttpURLConnection connection = null; + BufferedReader r = null; + try { + String finalUrl = WPS_DESCRIBE_PROCESS_URL + "&gcube-token=" + token; + finalUrl += "&lang=en-US&Identifier=" + identifier; + URL url = new URL(finalUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setUseCaches(false); + connection.setRequestMethod("GET"); + r = new BufferedReader(new InputStreamReader(connection.getInputStream())); + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r)); + doc.getDocumentElement().normalize(); + NodeList nListInput = doc.getElementsByTagName("Input"); + for (int i = 0; i < nListInput.getLength(); i++) { + Node nodeInput = nListInput.item(i); + NlpParameter nlpParam = new NlpParameter(); + NodeList inputChildren = nodeInput.getChildNodes(); + + // try to find the name and the type of the input parameter + for (int j = 0; j < inputChildren.getLength(); j++) { + Node node = inputChildren.item(j); + // for the moment we limit the type at 'file' and + // 'annotations' + if (node.getNodeName().equals("ows:Identifier")) { + nlpParam.setName(node.getTextContent()); + } else if (node.getNodeName().equals("ows:Title")) { + nlpParam.setDescription(node.getTextContent()); + } else if (node.getNodeName().equals("ows:Abstract")) { + String text = node.getTextContent().toLowerCase(); + if ((text.indexOf("file") >= 0) || (text.indexOf("text") >= 0)) { + nlpParam.setObjectType(NlpParameter.INPUT_FILE); + nlpParam.setValue(publicLink); + } else if ((text.indexOf("annotation") >= 0) || (text.indexOf("list") >= 0)) { + nlpParam.setObjectType(NlpParameter.INPUT_ANNOTATIONS); + nlpParam.setValue(annotations.replaceAll(",", "|")); + } + } + } + parameters.add(nlpParam); + } + + } catch (Exception x) { + logger.error(x.getLocalizedMessage()); + } finally { + try { + if (r != null) + r.close(); + if (connection != null) + connection.disconnect(); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + } + } + return parameters; + } + + public long getElapsedTime() { + return elapsedTime; + } + + @Override + public void asyncHttpRequestCallback() { + elapsedTime = System.currentTimeMillis() - elapsedTime; + logger.info("ID: " + identifier.substring(identifier.lastIndexOf(".") + 1) + " elapsed time: " + elapsedTime); + String result = super.getResult(); + String theLink = ""; + //System.out.println(result); + BufferedReader r = new BufferedReader( + new InputStreamReader(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)))); + try { + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r)); + doc.getDocumentElement().normalize(); + NodeList nListResult = doc.getElementsByTagName("ogr:Result"); + + for (int i=0, found=0; (i 0) { + theLink = res; + } + } + RunnerCommander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + theLink); + } catch (Exception x) { + RunnerCommander.updateResultList(identifier.substring(identifier.lastIndexOf(".") + 1) + ":::" + Constants.ERROR_ID); + 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(); +// } +} diff --git a/src/main/java/org/gcube/nlphub/nlp/NlpNerRunner.java b/src/main/java/org/gcube/nlphub/nlp/NlpNerRunner.java index 86fdc82..9e87377 100644 --- a/src/main/java/org/gcube/nlphub/nlp/NlpNerRunner.java +++ b/src/main/java/org/gcube/nlphub/nlp/NlpNerRunner.java @@ -84,8 +84,9 @@ public class NlpNerRunner extends DataminerClient { String mimeType = f.getMimeType(); if (mimeType.equalsIgnoreCase("application/d4science")) { String link = f.getUrl(); - System.out.println("url: " + link); + //System.out.println("url: " + link); logger.debug("url: " + link); + logger.error("url: " + link); String op = computationId.getOperatorId(); op = op.substring(op.lastIndexOf(".") + 1); testEndOfProcess(op + ":::" + link); @@ -103,11 +104,11 @@ public class NlpNerRunner extends DataminerClient { for (String id : identifiers) { try { super.identifier = id; - System.out.println("Running: " + id); + logger.error("Running: " + id); super.init(); List parameters = mapParameters(filePublicLink, annotations); super.execute(parameters); - System.out.println("Runned: " + id); + logger.error("Runned: " + id); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new NlpHubException(e.getLocalizedMessage(), e); @@ -136,11 +137,11 @@ public class NlpNerRunner extends DataminerClient { try { writer = response.getWriter(); String msg = new JsonManager().getSuccessJsonResponse(content); - System.out.println("msg: " + msg); + //System.out.println("msg: " + msg); writer.println(msg); if(writer.checkError()) { logger.error("writeResponse method has some problem in writing result."); - System.out.println("writeResponse method has some problem in writing result."); + //System.out.println("writeResponse method has some problem in writing result."); } } catch (Exception ex) { @@ -187,14 +188,14 @@ public class NlpNerRunner extends DataminerClient { fileName.setName(p.getName()); fileName.setValue(publicLink); parameters.add(fileName); - System.out.println(fileName.toString()); + //System.out.println(fileName.toString()); break; case LIST: ListParameter list = new ListParameter(); list.setName(p.getName()); list.setValue(annotations.replace(",", "|")); parameters.add(list); - System.out.println(list.toString()); + //System.out.println(list.toString()); break; case ENUM: // to be managed... diff --git a/src/main/java/org/gcube/nlphub/nlp/NlpParameter.java b/src/main/java/org/gcube/nlphub/nlp/NlpParameter.java index d3d3612..22b470d 100644 --- a/src/main/java/org/gcube/nlphub/nlp/NlpParameter.java +++ b/src/main/java/org/gcube/nlphub/nlp/NlpParameter.java @@ -2,12 +2,17 @@ package org.gcube.nlphub.nlp; public class NlpParameter { public static String ANNOTATION_LIST = "annotations"; + public static int INPUT_FILE = 0; + public static int INPUT_ANNOTATIONS = 1; + public static int INPUT_LANGUAGE = 2; private String name, description; private Object value; private int objectType; + public NlpParameter() { + } + public NlpParameter(String name, String description, Object value, int objectType) { - super(); this.name = name; this.description = description; this.value = value; @@ -29,6 +34,20 @@ public class NlpParameter { public int getObjectType() { return objectType; } - - + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setValue(Object value) { + this.value = value; + } + + public void setObjectType(int objectType) { + this.objectType = objectType; + } } diff --git a/src/main/java/org/gcube/nlphub/nlp/NlpUtils.java b/src/main/java/org/gcube/nlphub/nlp/NlpUtils.java index 5e8ee6e..57c8f00 100644 --- a/src/main/java/org/gcube/nlphub/nlp/NlpUtils.java +++ b/src/main/java/org/gcube/nlphub/nlp/NlpUtils.java @@ -5,33 +5,17 @@ import java.util.ArrayList; public class NlpUtils { public static String getLanguageRecognizerDigest(String content) { - int minToken = 20; + int minToken = 100; content = content.trim(); - String[] tokens = content.split("\\."); - if(tokens.length == 1) - tokens = content.split(";"); - if(tokens.length == 1) - return escapeContent(content); - - ArrayList list = new ArrayList<>(); - - for(int i=0; i= minToken) { - list.add(tokens[i]); - } + + String[] tokens = content.split("\\s"); + String digest = ""; + int len = (minToken <= tokens.length) ? minToken : tokens.length; + for(int i=0; i outResultList = null; + private long sleepTime = 500l; + private long maxWaitingTime = 5l * 60l * 1000l; + private Logger logger = Logger.getLogger(RunnerCommander.class.getSimpleName()); + private boolean complete = false; + + public RunnerCommander(String[] identifiers, String link, String annotationList, String token) { + this.identifiers = identifiers; + this.annotationList = annotationList; + this.link = link; + this.token = token; + this.response = null; + this.sleepTime = 500l; + outResultList = new ArrayList(); + } + + public RunnerCommander(String[] identifiers, String link, String annotationList, String token, + HttpServletResponse response) { + this.identifiers = identifiers; + this.annotationList = annotationList; + this.link = link; + this.token = token; + this.response = response; + this.sleepTime = 500l; + outResultList = new ArrayList(); + } + + public long getSleepTime() { + return sleepTime; + } + + public void setSleepTime(long sleepTime) { + this.sleepTime = sleepTime; + } + + public synchronized static void updateResultList(String res) { + outResultList.add(res); + } + + public long getMaxWaitingtime() { + return maxWaitingTime; + } + + public void setMaxWaitingTime(long maxWaitingTime) { + this.maxWaitingTime = maxWaitingTime; + } + + public void startProcess() { + start(); + while(!complete) { + try { + sleep(sleepTime); + } catch (InterruptedException x) { + logger.info("Interrupted."); + } + } + } + + private void runAlgorithms() { + for (String id : identifiers) { + NlpAsyncNerRunner n = new NlpAsyncNerRunner(id, token, link, annotationList, null); + n.start(); + } + } + + public void run() { + runAlgorithms(); + long counter = 0; + try { + while (counter <= maxWaitingTime) { + if (outResultList.size() == identifiers.length) { + String[] links = new String[outResultList.size()]; + links = outResultList.toArray(links); + writeResponse(links); + logger.info("Elapsed time: " + counter + " msec."); + return; + } + counter += sleepTime; + sleep(sleepTime); + } + logger.error("Timeout error."); + timeoutHandler(); + } catch (InterruptedException x) { + logger.info("Elapsed time: " + counter + " msec."); + logger.info("Thread interrupted."); + timeoutHandler(); + } + } + + private void timeoutHandler() { + boolean found = false; + for(int i=0; i Colors - +
TEST COLORE
TEST COLORE + SFONDO
+
+
\ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index fec647a..1f09a4b 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -61,7 +61,7 @@
-

Drag a file on the Upload box, or select a file from your PC, or paste a text.

+

Drag a .TXT file on the Upload box, or select a file from your PC, or paste a text.

diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index 61d361e..d3a4079 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -10,6 +10,7 @@ var jsonContent = null; var named = null; var resultText = ""; var hexLetters = '0123456789ABCDEF'; +var txtFlag = true; // ------------------------------------------------------------------------------------------------------ // Starting point: get the csv file with algorithm parameters and set the page @@ -50,13 +51,15 @@ $(document).ready(function() { fileName : "mytxtfile", maxFileCount : 100, multiple : false, - maxFileSize : 1024 * 1000 * 6.14, + maxFileSize : 1024 * 1000 * 1, showFileCounter : false, showCancel : true, + //allowedTypes: "txt,.txt", dragDropStr : "", extErrorStr : "Error. Text file only", sizeErrorStr : "Error. Max size: 6 Mb", onLoad : function(obj) { + txtFlag = true; $("#file-info").remove(); $("#reset-upload").remove(); $("#fu-container") @@ -81,9 +84,21 @@ $(document).ready(function() { setEventListeners(); }, onSelect : function(files) { - showProgress(); - textAreaEnable(false); - $("#input-textarea").val(""); + var fileName = files[0].name; + var extension = "" + fileName.substring(fileName.lastIndexOf(".")); + if(extension.toUpperCase() == ".TXT") { + showProgress(); + textAreaEnable(false); + $("#input-textarea").val(""); + } else { + txtFlag = false; + alert("The application supports text file only (.TXT)"); + } + }, + onSubmit: function(files) { + var submitFlag = txtFlag; + txtFlag = true; + return submitFlag; }, onSuccess : function(files, data, xhr) { hideProgress(); @@ -124,6 +139,8 @@ $(document).ready(function() { * Utility function processing the language indication returned by the language recognition service */ checkLanguage = function(lang) { + if(lang == 'unavailable') + return; var options = $("#language-select option"); for(var i=0; i= 0) { - algList += encodeURI(algorithms[j].id) + ","; + var algAnnotations = algorithms[j].annotations.toLowerCase(); + for(k in list) { + var a = list[k].toLowerCase(); + if(algAnnotations.indexOf(a) > -1) { + algList += encodeURI(algorithms[j].id) + ","; + break; + } + } + } } if (algList.length == 0) { @@ -575,8 +604,9 @@ rewriteText = function(annotation, color) { var G = enhanceColor(complement.substring(2,4)); var B = enhanceColor(complement.substring(4)); complement = "#" + R + G + B; - + console.log("-getIndices: start"); var indices = getIndices(annotation); + console.log("-getIndices: end"); $("#result-header-right").empty(); $("#result-header-right").append("" + annotation + " occurs " + indices.length + " times."); var indexedText = ""; @@ -584,6 +614,8 @@ rewriteText = function(annotation, color) { if ((typeof (indices) == 'undefined') || (indices.length == 0)) { indexedText = resultText; indexedText = indexedText.replace(/\n/g, "
"); + indexedText = indexedText.replace(//g, ">"); $("#result-text-div").append("

" + indexedText + "

"); return; } @@ -595,6 +627,7 @@ rewriteText = function(annotation, color) { var start = index[0]; var end = index[1]; indexedText += resultText.substring(t, start); + /* offset += countSubstringOccurrencies(resultText.substring(t, start), "\n"); offset += countSubstringOccurrencies(resultText.substring(t, start), @@ -602,7 +635,7 @@ rewriteText = function(annotation, color) { offset += countSubstringOccurrencies(resultText.substring(t, start), "\t"); start += offset; - end += offset; + end += offset;*/ var colored = "" + resultText.substring(start, end) + ""; @@ -625,7 +658,8 @@ checkAnnotation = function(annotation) { for (var j = 0; j < entities.length; j++) { a = entities[j][annotation]; if (typeof a != 'undefined') { - return true; + if(a.length > 0) + return true; } } } @@ -665,11 +699,14 @@ getIndices = function(annotation) { * Merge the indices */ mergeIndices = function(indices) { - var newIndices = [] - if (indices.length <= 1) + console.log("--mergeIndices start"); + var newIndices = []; + //console.log("--mergeIndices: indices.length=" + indices.length); + if (indices.length == 1) newIndices = indices[0]; else newIndices = mergeAll(indices); + console.log("--mergeIndices end"); return newIndices; } @@ -707,10 +744,18 @@ resizeTable = function() { rowId = "row-" + i; $("#annotations-table").append(""); } + var annotationElement = " "; + if(annotations[i].toLowerCase() == "keyword") { + annotationElement = " "; + } + $("#" + rowId).append("" + annotationElement + ""); } } diff --git a/src/main/webapp/js/merge.js b/src/main/webapp/js/merge.js index 5df986a..15df0fd 100644 --- a/src/main/webapp/js/merge.js +++ b/src/main/webapp/js/merge.js @@ -87,6 +87,7 @@ compareSegmentList = function(list1, list2) { */ mergeAll = function(indices) { + console.log("---mergeAll indices.length=" + indices.length); var m = []; for(var i=0; i