This commit is contained in:
Erik Perrone 2018-02-20 07:39:31 +00:00
parent a2bbc0aefd
commit e68c3a31d6
55 changed files with 22352 additions and 0 deletions

37
.classpath Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

37
.project Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>nlphub</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

13
.settings/.jsdtscope Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -0,0 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="nlphub">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="nlphub"/>
<property name="java-output-path" value="/nlphub/target/classes"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/>
</faceted-project>

View File

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@ -0,0 +1 @@
Window

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

146
pom.xml Normal file
View File

@ -0,0 +1,146 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube</groupId>
<artifactId>nlphub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<tomcat.version>7.0.70</tomcat.version>
<websocket.version>1.1</websocket.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
<!-- GCube -->
<dependency>
<groupId>org.gcube.data.analysis</groupId>
<artifactId>data-miner-manager-cl</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<!-- <version>1.3.0-4.5.0-148453</version>-->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>[2.1.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-configuration-scanner</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
<version>[1.2.1-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<scope>compile</scope>
</dependency>
<!-- Sevlet jars for compilation, provided by Tomcat -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>${tomcat.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>compile</scope>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>nlphub</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,100 @@
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.DataminerClient;
import org.gcube.nlphub.legacy.JsonManager;
//import org.gcube.dataminerclient.DataminerClient;
import org.gcube.nlphub.nlp.NlpNerRunner;
/**
* Servlet implementation class NLPHub
*/
@WebServlet(asyncSupported = true, name = "NLPServlet", urlPatterns = { "/nlphub-servlet" })
public class NLPHub extends HttpServlet {
private Logger logger = Logger.getLogger(NLPHub.class.getSimpleName());
private static final long serialVersionUID = 1L;
private String service = "http://dataminer-prototypes.d4science.org/wps/";
private String token = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
/**
* @see HttpServlet#HttpServlet()
*/
public NLPHub() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
System.out.println("annotations: " + request.getParameter("annotations"));
System.out.println("lang: " + request.getParameter("lang"));
System.out.println("plink: " + request.getParameter("plink"));
System.out.println("algs: " + request.getParameter("algs"));
String[] algs = request.getParameter("algs").split(",");
for(int i=0; i<algs.length; i++) {
algs[i] = algs[i].trim();
}
if (algs.length >= 1) {
// single algorithm execution
System.out.println("algs[0]: " + algs[0]);
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) {
x.printStackTrace();
}
}
}

View File

@ -0,0 +1,77 @@
package org.gcube.nlphub;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.ServletException;
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.nlphub.nlp.NlpNerRunner;
import org.gcube.nlphub.mapper.JsonMapper;
import org.gcube.nlphub.mapper.DefaultMapper;
/**
* Servlet implementation class NlpMapper
*/
@WebServlet("/nlphub-mapper-servlet")
public class NLPMapper extends HttpServlet {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(NLPMapper.class.getSimpleName());
/**
* @see HttpServlet#HttpServlet()
*/
public NLPMapper() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// response.getWriter().append("Served at:
// ").append(request.getContextPath());
String documentLink = request.getParameter("dlink"); // link al testo (sul workspace)
String toBeMap = request.getParameter("tobemap");
String[] tokens = toBeMap.split("|");
String annotations = request.getParameter("annotations");
String language = request.getParameter("language");
for (String token : tokens) {
String[] t = token.split(":::");
try {
String json = ((JsonMapper)(getMapper(t[0]).newInstance())).getJson(t[0], t[1]);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
}
}
//response.getWriter().write(json);
}
private Class getMapper(String algId) throws Exception {
return Class.forName("org.gcube.nlphub.mapper.DefaultMapper");
}
}

View File

@ -0,0 +1,293 @@
package org.gcube.nlphub;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
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 javax.servlet.http.Part;
import org.apache.log4j.Logger;
import org.gcube.nlphub.legacy.Constants;
import org.gcube.nlphub.legacy.JsonManager;
import org.gcube.nlphub.legacy.NlpHubException;
/**
* Servlet implementation class NLPUploader
*/
// @WebServlet("/NLPUploader")
@WebServlet(asyncSupported = true, name = "NLPUploader", urlPatterns = { "/nlphub-uploader-servlet" })
@MultipartConfig
public class NLPUploader extends HttpServlet {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(NLPUploader.class.getSimpleName());
private boolean devMode = true;
private String token = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
/**
* @see HttpServlet#HttpServlet()
*/
public NLPUploader() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doWork(request, response);
}
private void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json;charset=UTF-8");
if (request.getParameter("freetext") == null)
handleFileUpload(request, response);
else
handleFreeText(request, response);
}
private void handleFreeText(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String freeText = request.getParameter("freetext");
System.out.println(freeText);
byte[] content = freeText.getBytes("UTF-8");
String fileName = generateFileName();
PrintWriter writer = response.getWriter();
try {
if (!uploadFile(content, fileName, Constants.DEFAULT_DESCRIPTION, token)) {
writer.println(new JsonManager().getErrorJsonResponse(
"Error uploading file. A file called '" + fileName + "' is already in the workspace?"));
return;
}
String link = getPublicLink(fileName, token);
writer.println(new JsonManager().getSuccessJsonResponse("" + link));
} catch (Exception x) {
x.printStackTrace();
logger.error(x.getClass().getName() + ": " + x.getLocalizedMessage());
writer.println(new JsonManager().getErrorJsonResponse(x.getLocalizedMessage()));
}
}
private void handleFileUpload(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int contentLength = request.getContentLength();
Part filePart = request.getPart("mytxtfile");
String fileName = getFileName(filePart);
PrintWriter writer = response.getWriter();
// allocate a buffer of request size
byte[] buffer = new byte[contentLength];
byte[] bufferedContent;
try {
InputStream fileContent = filePart.getInputStream();
int offset = 0, len = 100, byteRead = 0;
byte[] readBuffer = new byte[len];
while (byteRead > -1) {
byteRead = fileContent.read(readBuffer, 0, len);
// System.out.println(byteRead);
if (byteRead > 0) {
System.arraycopy(readBuffer, 0, buffer, offset, byteRead);
offset += byteRead;
}
}
if (offset < contentLength) {
bufferedContent = new byte[offset];
System.arraycopy(buffer, 0, bufferedContent, 0, offset);
} else
bufferedContent = buffer;
deleteFile(fileName, token);
if (!uploadFile(bufferedContent, fileName, Constants.DEFAULT_DESCRIPTION, token)) {
writer.println(new JsonManager().getErrorJsonResponse(
"Error uploading file. A file called '" + fileName + "' is already in the workspace?"));
return;
}
String link = getPublicLink(fileName, token);
writer.println(new JsonManager().getSuccessJsonResponse("" + link));
} catch (Exception x) {
x.printStackTrace();
logger.error(x.getClass().getName() + ": " + x.getLocalizedMessage());
writer.println(new JsonManager().getErrorJsonResponse(x.getLocalizedMessage()));
}
}
private String getFileName(Part part) {
String partHeader = part.getHeader("content-disposition");
logger.debug("Part Header: " + partHeader);
for (String content : part.getHeader("content-disposition").split(";")) {
if (content.trim().startsWith("filename")) {
return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
}
}
return null;
}
private String getPublicLink(String fileName, String token) throws NlpHubException {
try {
String link = "";
String user = authorizationService().get(token).getClientInfo().getId();
String wsRoot = "/Home/" + user + "/Workspace/";
String webapp = "https://workspace-repository.d4science.org/home-library-webapp";
String uri = webapp + "/rest/GetPublicLink?absPath=" + URLEncoder.encode(wsRoot + fileName, "UTF-8")
+ "&shortUrl=false";
URL url = new URL(uri);
// System.out.println(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty(Constants.TOKEN_PARAMETER, token);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer response = new StringBuffer();
String inputLine;
while ((inputLine = r.readLine()) != null) {
response.append(inputLine);
}
String xmlOut = response.toString();
// System.out.println("xmlOut: " + xmlOut);
String begin = "<string>";
String end = "</string>";
int b = xmlOut.indexOf(begin);
int e = xmlOut.indexOf(end);
if (xmlOut.contains("Exception") || (e < 0) || (b < 0)) {
String message = "Invalid link: " + URLEncoder.encode(xmlOut, "UTF-8");
logger.error(message);
throw new NlpHubException(message, null);
}
link = xmlOut.substring(b + begin.length(), e);
return link;
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw new NlpHubException(e.getLocalizedMessage(), e);
}
}
private void deleteFile(String fileName, String token) throws NlpHubException {
try {
String user = authorizationService().get(token).getClientInfo().getId();
String wsRoot = "/Home/" + user + "/Workspace/";
String webapp = "https://workspace-repository.d4science.org/home-library-webapp";
String uri = webapp + "/rest/Delete?absPath=" + URLEncoder.encode(wsRoot + fileName, "UTF-8");
URL url = new URL(uri);
// System.out.println(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty(Constants.TOKEN_PARAMETER, token);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer response = new StringBuffer();
String inputLine;
while ((inputLine = r.readLine()) != null) {
response.append(inputLine);
}
String xmlOut = response.toString();
// System.out.println(xmlOut);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw new NlpHubException(e.getLocalizedMessage(), e);
}
}
private boolean uploadFile(byte[] in, String name, String description, String token) throws NlpHubException {
OutputStream output = null;
try {
String user = authorizationService().get(token).getClientInfo().getId();
String wsRoot = "/Home/" + user + "/Workspace/";
String webapp = "https://workspace-repository.d4science.org/home-library-webapp";
String uri = webapp + "/rest/Upload?name=" + URLEncoder.encode(name, "UTF-8") + "&description="
+ URLEncoder.encode(description, "UTF-8") + "&parentPath=" + URLEncoder.encode(wsRoot, "UTF-8");
URL url = new URL(uri);
// System.out.println(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty(Constants.TOKEN_PARAMETER, token);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty(Constants.CONTENT_TYPE, Constants.MIME_TEXT);
connection.setRequestMethod("POST");
output = connection.getOutputStream();
output.write(in);
BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer response = new StringBuffer();
String inputLine;
while ((inputLine = r.readLine()) != null) {
response.append(inputLine);
}
String xmlOut = response.toString();
// System.out.println(xmlOut);
if (xmlOut.contains("Exception"))
return false;
return true;
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw new NlpHubException(e.getLocalizedMessage(), e);
} finally {
// output stream must be closed anyway...
if (output != null)
try {
output.close();
} catch (IOException e) {
logger.error(e.getLocalizedMessage());
}
}
}
private String generateFileName() {
long now = System.currentTimeMillis();
return "auto-nlp-" + now;
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.nlphub.legacy;
import javax.servlet.http.HttpServletRequest;
public class Constants {
public static String DEFAULT_DESCRIPTION = "NlpHub upload";
public static String TOKEN_PARAMETER = "gcube-token";
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 getToken(HttpServletRequest request, boolean devMode) {
String token = request.getParameter(TOKEN_PARAMETER);
if(devMode) {
if(token == null) token = TEST_TOKEN;
}
return token;
}
}

View File

@ -0,0 +1,214 @@
package org.gcube.nlphub.legacy;
//package dataminerclient;
import java.util.List;
import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService;
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient;
import org.gcube.data.analysis.dataminermanagercl.server.monitor.DMMonitor;
import org.gcube.data.analysis.dataminermanagercl.server.monitor.DMMonitorListener;
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.Parameter;
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DataminerClient {
private String service, token;
protected String identifier;
private static Logger logger = LoggerFactory.getLogger(DataminerClient.class);
private DataMinerService dataMinerService = null;
private SClient sClient = null;
private Operator operator = null;
public DataminerClient(String service, String identifier, String token) {
this.service = service;
this.identifier = identifier;
this.token = token;
dataMinerService = new DataMinerService();
}
public void init() throws DataminerClientException {
try {
sClient = dataMinerService.getClient(getToken(), getService());
operator = sClient.getOperatorById(getIdentifier());
} catch (Exception e) {
logger.error(e.getClass().getName() + ": " + e.getLocalizedMessage());
throw new DataminerClientException(e.getLocalizedMessage(), e);
}
}
public String getOperatorName() {
if (operator != null) {
return operator.getName();
}
return "";
}
public String getOperatorDescription() {
if (operator != null) {
return operator.getDescription();
}
return "";
}
public String getOperatorBriefDescription() {
if (operator != null) {
return operator.getBriefDescription();
}
return "";
}
public List<Parameter> getOperatorInputParameters() throws DataminerClientException {
if (operator != null) {
try {
return sClient.getInputParameters(operator);
}
catch (Exception x) {
throw new DataminerClientException(x.getLocalizedMessage(), x);
}
}
return null;
}
public ComputationId execute(List<Parameter> parameters) throws DataminerClientException {
try {
operator.setOperatorParameters(parameters);
ComputationId computationId = sClient.startComputation(operator);
monitoringComputation(computationId, sClient);
return computationId;
} catch (Exception e) {
logger.error(e.getClass().getName() + ": " + e.getLocalizedMessage());
throw new DataminerClientException(e.getLocalizedMessage(), e);
}
}
public String getService() {
return service;
}
public String getIdentifier() {
return identifier;
}
public String getToken() {
return token;
}
public void setIdentifier(String indentifier) {
this.identifier = identifier;
}
public void retrieveOutput(ComputationId computationId, SClient sClient) {
try {
OutputData output = sClient.getOutputDataByComputationId(computationId);
// logger.debug("Output: " + output);
Resource resource = output.getResource();
if (resource.isMap()) {
MapResource mapResource = (MapResource) resource;
for (String key : mapResource.getMap().keySet()) {
logger.debug("Entry: " + key + " = " + mapResource.getMap().get(key));
System.out.println("Entry: " + key + " = " + mapResource.getMap().get(key));
}
}
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
}
}
private void monitoringComputation(ComputationId computationId, SClient sClient) {
DMMonitorListener listener = new DMMonitorListener() {
@Override
public void running(double percentage) {
logger.debug("Operation Running: " + percentage);
}
@Override
public void failed(String message, Exception exception) {
logger.error("Operation Failed");
logger.error(message);
logger.error(exception.getStackTrace().toString());
System.out.println(exception.getLocalizedMessage());
}
@Override
public void complete(double percentage) {
logger.debug("Operation Completed");
logger.debug("Perc: " + percentage);
retrieveOutput(computationId, sClient);
}
@Override
public void cancelled() {
logger.debug("Operation Cancelled");
}
@Override
public void accepted() {
logger.debug("Operation Accepted");
}
};
DMMonitor dmMonitor = new DMMonitor(computationId, sClient);
dmMonitor.add(listener);
dmMonitor.start();
}
/*
public static void main(String[] args) {
String service = "http://dataminer-prototypes.d4science.org/wps/";
String identifier = "";
identifier = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.ENGLISH_NAMED_ENTITY_RECOGNIZER";
identifier = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.NEWSTANBOLWRAPPER";
//identifier = "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.GENERIC_OPINION_MINING_ENGLISH";
String token = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462";
DataminerClient dmc = new DataminerClient(service, identifier, token);
try {
dmc.init();
System.out.println(dmc.getOperatorBriefDescription());
System.out.println(dmc.getOperatorDescription());
System.out.println(dmc.getOperatorName());
List<Parameter> parameters = dmc.getOperatorInputParameters();
if (parameters != null) {
System.out.println("Parameter number: " + parameters.size());
for (Parameter p : parameters) {
System.out.println("name : " + p.getName());
System.out.println("value: " + p.getValue());
System.out.println("type : " + p.getTypology());
System.out.println("desc : " + p.getDescription());
System.out.println("toString: " + p.toString());
System.out.println();
}
}
// List<Parameter> parameters = new ArrayList<>();
//
// FileParameter fileName = new FileParameter();
// fileName.setName("inputTextFile");
// fileName.setValue("http://data.d4science.org/cWRQbHNjRVR4YjdkQXdDUnlSS0JkZVlmLzk2WnJIb1ZHbWJQNStIS0N6Yz0");
// parameters.add(fileName);
//
// ObjectParameter options = new ObjectParameter();
// options.setName("annotationsList");
// //options.setValue("Address|Date|Location|Organization|Person|Money|Percent|SpaceToken");
// options.setValue("SpaceToken");
// parameters.add(options);
//
// ComputationId cid = dmc.execute(parameters);
// System.out.println("urlId: " + cid.getUrlId());
} catch (Exception e) {
System.out.println("-" + e.getClass().getName() + "-\n" + e.getLocalizedMessage());
e.printStackTrace();
}
}
*/
}

View File

@ -0,0 +1,7 @@
package org.gcube.nlphub.legacy;
class DataminerClientException extends Exception {
public DataminerClientException(String message, Throwable throwable) {
super(message, throwable);
}
};

View File

@ -0,0 +1,130 @@
package org.gcube.nlphub.legacy;
import java.io.Reader;
import java.util.ArrayList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class JsonManager {
public static String TEXT = "text";
public static String ANNOTATIONS = "annotations";
public static String LANGUAGE = "language";
public static String ALGORITHM = "algorithm";
public static String ENTITIES = "entities";
public static String INDICES = "indices";
public static String RESULT = "result";
public static String RESPONSE = "response";
public static String OK = "Ok";
public static String ERROR = "Error";
public static String MESSAGE = "message";
private JsonObject jsonObjectRoot = null;
private JsonParser jsonParser = null;
public JsonManager() {
jsonObjectRoot = new JsonObject();
}
public JsonManager(String s) {
jsonObjectRoot = (JsonObject) new JsonParser().parse(s);
}
public JsonManager(Reader r) {
jsonObjectRoot = (JsonObject) new JsonParser().parse(r);
}
public String getJsonAsString() {
return jsonObjectRoot.toString();
}
public String getSuccessJsonResponse(String[] messages) {
jsonObjectRoot.addProperty(RESPONSE, OK);
JsonArray msgs = new JsonArray();
for(String m : messages) {
msgs.add(m);
}
jsonObjectRoot.add(MESSAGE, msgs);
return jsonObjectRoot.toString();
}
public String getSuccessJsonResponse(String message) {
return getResponse(true, message);
}
public String getErrorJsonResponse(String message) {
return getResponse(false, message);
}
private String getResponse(boolean success, String message) {
jsonObjectRoot.addProperty(RESPONSE, (success ? OK : ERROR));
jsonObjectRoot.addProperty(MESSAGE, message);
return jsonObjectRoot.toString();
}
/*
public void buildNerOutputJson(NerOutput nerOut) {
// build the root json object initial property fields
jsonObjectRoot.addProperty(TEXT, nerOut.getText());
jsonObjectRoot.addProperty(ANNOTATIONS, nerOut.getAnnotations());
jsonObjectRoot.addProperty(LANGUAGE, nerOut.getLanguage());
// set the result array (main array)
JsonArray jsonResults = new JsonArray();
ArrayList<NerAlgorithmResult> results = nerOut.getResults();
for (NerAlgorithmResult result : results) {
JsonObject jsonResult = buildResult(result);
jsonResults.add(jsonResult);
}
jsonObjectRoot.add(RESULT, jsonResults);
}
private JsonObject buildResult(NerAlgorithmResult result) {
JsonObject jsonResult = new JsonObject();
jsonResult.addProperty(ALGORITHM, result.getAlgorithmName());
JsonObject jsonEntities = new JsonObject();
ArrayList<NerEntity> entities = result.getEntities();
if (entities != null)
for (NerEntity entity : entities) {
JsonArray jsonEntityValues = buildEntityValues(entity);
jsonEntities.add(entity.getEntityName(), jsonEntityValues);
}
jsonResult.add(ENTITIES, jsonEntities);
return jsonResult;
}
private JsonArray buildEntityValues(NerEntity entity) {
// JsonObject jsonEntity = new JsonObject();
JsonArray values = new JsonArray();
ArrayList<NerEntityData> entityData = entity.getEntities();
if (entityData != null)
for (NerEntityData data : entityData) {
JsonObject jsonEntityData = buildEntityData(data);
values.add(jsonEntityData);
}
// jsonEntity.add(entity.getEntityName(), values);
return values;
}
private JsonObject buildEntityData(NerEntityData data) {
JsonObject entityData = new JsonObject();
JsonArray indices = new JsonArray();
indices.add(data.getStart());
indices.add(data.getEnd());
entityData.add(INDICES, indices);
ArrayList<NameValue> fields = data.getAdditionalFields();
if (fields != null)
for (NameValue field : fields) {
entityData.addProperty(field.getName(), field.getValue());
}
return entityData;
}
*/
}

View File

@ -0,0 +1,76 @@
package org.gcube.nlphub.legacy;
import java.util.ArrayList;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class NerAlgorithm {
private String name;
private ArrayList<NerAnnotationData> annotationsData;
public NerAlgorithm(String name) {
this.name = name;
annotationsData = new ArrayList<>();
}
public void addAnnotationData(NerAnnotationData data) {
annotationsData.add(data);
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("algorithm", name);
JsonArray data = new JsonArray();
for (NerAnnotationData d : annotationsData) {
data.add(d.toJson());
}
json.add("entities", data);
return json;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<NerAnnotationData> getAnnotationsData() {
return annotationsData;
}
public void setAnnotationsData(ArrayList<NerAnnotationData> annotationsData) {
this.annotationsData = annotationsData;
}
/*
public static void main(String[] args) {
NerAlgorithm alg = new NerAlgorithm("Algorithm-name");
NerEntity ne1 = new NerEntity(11, 22);
ne1.addProperty("type", "scalar");
ne1.addProperty("unit", "hours");
NerEntity ne2 = new NerEntity(33, 44);
ne2.addProperty("type", "scalar");
ne2.addProperty("unit", "minutes");
NerAnnotationData nad = new NerAnnotationData("Measure");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
alg.addAnnotationData(nad);
ne1 = new NerEntity(0, 10);
ne2 = new NerEntity(111, 114);
nad = new NerAnnotationData("Person");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
alg.addAnnotationData(nad);
System.out.println(alg.toJson().toString());
}*/
}

View File

@ -0,0 +1,77 @@
package org.gcube.nlphub.legacy;
import java.util.ArrayList;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class NerAnnotationData {
private String name;
private ArrayList<NerEntity> nerEntities;
/**
* Class constructor; require the name of the annotation
* @param name
*/
public NerAnnotationData(String name) {
this.name = name;
nerEntities = new ArrayList<>();
}
/**
* add a new NerEntity to the collection
* @param entity
*/
public void addNerEntity(NerEntity entity) {
nerEntities.add(entity);
}
/**
* build the proper Json object.
* @return JsonObject
*/
public JsonObject toJson() {
JsonObject json = new JsonObject();
JsonArray entities = new JsonArray();
for(NerEntity e : nerEntities) {
entities.add(e.toJson());
}
json.add(name,entities);
return json;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<NerEntity> getNerEntities() {
return nerEntities;
}
public void setNerEntities(ArrayList<NerEntity> nerEntities) {
this.nerEntities = nerEntities;
}
/*
public static void main(String[] args) {
NerEntity ne1 = new NerEntity(11, 22);
ne1.addProperty("type", "scalar");
ne1.addProperty("unit", "hours");
NerEntity ne2 = new NerEntity(33, 44);
ne2.addProperty("type", "scalar");
ne2.addProperty("unit", "minutes");
NerAnnotationData nad = new NerAnnotationData("Measure");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
System.out.println(nad.toJson().toString());
}*/
}

View File

@ -0,0 +1,87 @@
package org.gcube.nlphub.legacy;
import java.util.HashMap;
import java.util.Set;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class NerEntity {
private int startIndex, endIndex;
private HashMap<String, String> properties = null;
/**
* Class constructor
* @param startIndex the start index of the matching annotation
* @param endIndex the end index of the matching annotation
*/
public NerEntity(int startIndex, int endIndex) {
this.startIndex = startIndex;
this.endIndex = endIndex;
properties = new HashMap<>();
}
/**
* Add an additional property (property is a couple {name, value})
* @param name
* @param value
*/
public void addProperty(String name, String value) {
properties.put(name, value);
}
/**
* Build a proper JsonObject
* @return JsonObject
*/
public JsonObject toJson() {
JsonObject json = new JsonObject();
// build the "indices" array
JsonArray indices = new JsonArray();
indices.add(startIndex);
indices.add(endIndex);
json.add("indices", indices);
// add additional properties (if any)
Set<String> names = properties.keySet();
for(String n : names) {
json.addProperty(n, properties.get(n));
}
return json;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public HashMap<String, String> getProperties() {
return properties;
}
public void setProperties(HashMap<String, String> properties) {
this.properties = properties;
}
/*
public static void main(String[] args) {
NerEntity ne = new NerEntity(11, 22);
ne.addProperty("type", "scalar");
ne.addProperty("unit", "hour");
System.out.println(ne.toJson().toString());
}*/
}

View File

@ -0,0 +1,114 @@
package org.gcube.nlphub.legacy;
import java.util.ArrayList;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class NerOutput {
private String text, annotations, language;
private ArrayList<NerAlgorithm> result;
public NerOutput(String text, String annotations, String language) {
this.text = text;
this.annotations = annotations;
this.language = language;
result = new ArrayList<>();
}
public void addNerAlgorithm(NerAlgorithm alg) {
result.add(alg);
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("text", text);
json.addProperty("annotations", annotations);
json.addProperty("language", language);
JsonArray jResult = new JsonArray();
for(NerAlgorithm a : result) {
jResult.add(a.toJson());
}
json.add("result",jResult);
return json;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getAnnotations() {
return annotations;
}
public void setAnnotations(String annotations) {
this.annotations = annotations;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public ArrayList<NerAlgorithm> getResult() {
return result;
}
public void setResult(ArrayList<NerAlgorithm> result) {
this.result = result;
}
public static void main(String[] args) {
NerAlgorithm alg = new NerAlgorithm("Algorithm-name");
NerEntity ne1 = new NerEntity(11, 22);
ne1.addProperty("type", "scalar");
ne1.addProperty("unit", "hours");
NerEntity ne2 = new NerEntity(33, 44);
ne2.addProperty("type", "scalar");
ne2.addProperty("unit", "minutes");
NerAnnotationData nad = new NerAnnotationData("Measure");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
alg.addAnnotationData(nad);
ne1 = new NerEntity(0, 10);
ne2 = new NerEntity(111, 114);
nad = new NerAnnotationData("Person");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
alg.addAnnotationData(nad);
NerAlgorithm alg2 = new NerAlgorithm("Algorithm-name-2");
ne1 = new NerEntity(1, 22);
ne2 = new NerEntity(30, 33);
nad = new NerAnnotationData("Measure");
nad.addNerEntity(ne1);
nad.addNerEntity(ne2);
alg2.addAnnotationData(nad);
NerOutput no = new NerOutput("this is the text", "Measure,Person", "english");
no.addNerAlgorithm(alg);
no.addNerAlgorithm(alg2);
System.out.println(no.toJson().toString());
}
}

View File

@ -0,0 +1,7 @@
package org.gcube.nlphub.legacy;
public class NlpHubException extends Exception {
public NlpHubException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@ -0,0 +1,73 @@
package org.gcube.nlphub.mapper;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Set;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.apache.log4j.Logger;
import org.gcube.nlphub.legacy.NerAlgorithm;
import org.gcube.nlphub.legacy.NerAnnotationData;
import org.gcube.nlphub.legacy.NerEntity;
import org.gcube.nlphub.nlp.NlpNerRunner;
public class DefaultMapper implements JsonMapper {
private Logger logger = Logger.getLogger(DefaultMapper.class.getSimpleName());
public String getJson(String alg, String link) {
NerAlgorithm algInfo = new NerAlgorithm(alg);
try {
HttpURLConnection connection = (HttpURLConnection) new URL(link).openConnection();
connection.setRequestMethod("GET");
System.out.println("Content-Type: " + connection.getContentType());
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JsonObject jsonRoot = (JsonObject) new JsonParser().parse(reader);
JsonElement entities = jsonRoot.get("entities");
if ((entities != null) && (entities.isJsonObject())) {
JsonObject e = (JsonObject) entities;
Set<String> properties = e.keySet();
for (String p : properties) {
JsonElement property = e.get(p);
if (!property.isJsonArray())
continue;
NerAnnotationData data = new NerAnnotationData(p);
JsonArray jsonAnnotation = (JsonArray) property;
int size = jsonAnnotation.size();
for (int i = 0; i < size; i++) {
JsonElement ann = jsonAnnotation.get(i);
if (ann.isJsonObject()) {
JsonObject annotation = (JsonObject) ann;
Set<String> fields = annotation.keySet();
JsonArray indices = (JsonArray) annotation.get("indices");
NerEntity ne = new NerEntity(indices.get(0).getAsInt(), indices.get(1).getAsInt());
for (String f : fields) {
if (f.equals("indices"))
continue;
JsonElement je = annotation.get(f);
if (!je.isJsonArray() && !je.isJsonObject() && !je.isJsonNull()) {
ne.addProperty(f, je.getAsString());
}
}
data.addNerEntity(ne);
}
algInfo.addAnnotationData(data);
}
}
}
return algInfo.toJson().toString();
} catch (Exception x) {
logger.error(x.getLocalizedMessage());
return null;
}
}
public static void main(String[] args) {
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.nlphub.mapper;
public interface JsonMapper {
public String getJson(String algorithm, String link);
// public String JsonObject(HashMap<String, String> algs, String language);
// public String JsonObject(HashMap<String, String> algs, String language, String text);
}

View File

@ -0,0 +1,209 @@
package org.gcube.nlphub.nlp;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.FileResource;
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.data.output.Resource.ResourceType;
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.ListParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
import org.gcube.nlphub.NLPUploader;
import org.gcube.nlphub.legacy.Constants;
import org.gcube.nlphub.legacy.DataminerClient;
import org.gcube.nlphub.legacy.JsonManager;
import org.gcube.nlphub.legacy.NlpHubException;
import org.apache.log4j.Logger;
public class NlpNerRunner extends DataminerClient {
private Logger logger = Logger.getLogger(NlpNerRunner.class.getSimpleName());
private HttpServletResponse response = null;
private ArrayList<String> outputLinks;
private String[] identifiers;
private String currentId;
/**
* This constructor is useful for local test cases...
*
* @param service
* @param identifier
* @param token
*/
public NlpNerRunner(String service, String identifier, String token) {
super(service, identifier, token);
outputLinks = new ArrayList<>();
}
/**
* This constructor is the "canonical one"
*
* @param service
* @param identifier
* @param token
* @param response
*/
public NlpNerRunner(String service, String[] identifiers, String token) {
super(service, "", token);
outputLinks = new ArrayList<>();
}
/**
* This constructor is useful when multiple alogrithm identifiers are given
*
* @param service
* @param identifiers
* @param token
*/
public NlpNerRunner(String service, String[] identifiers, String token, HttpServletResponse response) {
super(service, "", token);
this.response = response;
this.identifiers = identifiers;
outputLinks = new ArrayList<>();
}
@Override
public void retrieveOutput(ComputationId computationId, SClient sClient) {
try {
OutputData output = sClient.getOutputDataByComputationId(computationId);
Resource resource = output.getResource();
if (resource.isMap()) {
MapResource mapResource = (MapResource) resource;
for (String key : mapResource.getMap().keySet()) {
Resource r = mapResource.getMap().get(key);
if (r.isFile()) {
FileResource f = (FileResource) r;
String link = f.getUrl();
System.out.println("url: " + link);
String op = computationId.getOperatorId();
op = op.substring(op.lastIndexOf(".") + 1);
testEndOfProcess(op + ":::" + link);
}
}
}
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
writeResponse(e.getLocalizedMessage(), false);
}
}
public void run(String filePublicLink, String annotations, String language) throws NlpHubException {
for (String id : identifiers) {
try {
super.identifier = id;
super.init();
List<Parameter> parameters = mapParameters(filePublicLink, annotations);
super.execute(parameters);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw new NlpHubException(e.getLocalizedMessage(), e);
}
}
}
public ArrayList<String> getOutputLinks() {
return outputLinks;
}
private synchronized void testEndOfProcess(String link) {
outputLinks.add(link);
if (outputLinks.size() == identifiers.length) {
String[] links = new String[outputLinks.size()];
links = outputLinks.toArray(links);
writeResponse(links);
}
}
private void writeResponse(String[] content) {
if (response != null) {
response.setContentType("application/json;charset=UTF-8");
try {
PrintWriter writer = response.getWriter();
writer.println(new JsonManager().getSuccessJsonResponse(content));
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
}
}
}
private void writeResponse(String content, boolean isOk) {
if (response != null) {
response.setContentType("application/json;charset=UTF-8");
try {
PrintWriter writer = response.getWriter();
if (isOk) {
writer.println(new JsonManager().getSuccessJsonResponse("" + content));
} else {
writer.println(new JsonManager().getErrorJsonResponse("" + content));
}
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
}
}
}
private List<Parameter> mapParameters(String publicLink, String annotations) {
List<Parameter> parameters = new ArrayList<>();
try {
List<Parameter> inputParameters = super.getOperatorInputParameters();
System.out.println("n. " + inputParameters.size());
for (Parameter p : inputParameters) {
switch (p.getTypology()) {
case FILE:
FileParameter fileName = new FileParameter();
fileName.setName(p.getName());
fileName.setValue(publicLink);
parameters.add(fileName);
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());
break;
case ENUM:
// to be managed...
break;
}
}
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
}
return parameters;
}
/*
* public static void main(String[] args) { String service =
* "http://dataminer-prototypes.d4science.org/wps/"; String identifier = "";
* identifier =
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.ENGLISH_NAMED_ENTITY_RECOGNIZER";
* // identifier = //
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.NEWSTANBOLWRAPPER";
* // identifier = //
* "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.GENERIC_OPINION_MINING_ENGLISH";
* String token = "df2cc5f5-63ee-48c1-b2a6-1210030c57b8-843339462"; String
* pLink =
* "http://data.d4science.org/RW9KZDJ0eU9ZZlRNWEhLYmtVa3ltL0Y1UWdhdmZvTlVHbWJQNStIS0N6Yz0";
*
* ArrayList<NlpParameter> params = new ArrayList<>(); NlpParameter p = new
* NlpParameter(NlpParameter.ANNOTATION_LIST, "", "Person,Token", 0);
* params.add(p);
*
* NlpNerRunner runner = new NlpNerRunner(service, identifier, token); //
* try { // runner.run(pLink, service, identifier, params); // } catch
* (NlpHubException e) { // e.printStackTrace(); // } }
*/
}

View File

@ -0,0 +1,34 @@
package org.gcube.nlphub.nlp;
public class NlpParameter {
public static String ANNOTATION_LIST = "annotations";
private String name, description;
private Object value;
private int objectType;
public NlpParameter(String name, String description, Object value, int objectType) {
super();
this.name = name;
this.description = description;
this.value = value;
this.objectType = objectType;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public Object getValue() {
return value;
}
public int getObjectType() {
return objectType;
}
}

View File

@ -0,0 +1,12 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# Print only messages of level TRACE or above in the package org.gcube
log4j.logger.org.gcube=TRACE
log4j.logger.org.gcube.application.framework.core.session=INFO
log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR
log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
</appender>
<logger name="org.gcube" level="INFO" />
<logger name="org.gcube.vremanagement.smartexecutor" level="TRACE" />
<logger name="org.gcube.dataharvest" level="TRACE" />
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true" version="3.0">
<display-name>NLPHub</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>NLPServlet</servlet-name>
<servlet-class>org.gcube.nlphub.NLPHub</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NLPServlet</servlet-name>
<url-pattern>/nlphub-servlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>NLPUploader</servlet-name>
<servlet-class>org.gcube.nlphub.NLPUploader</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NLPUploader</servlet-name>
<url-pattern>/nlphub-uploader-servlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>NLPMapper</servlet-name>
<servlet-class>org.gcube.nlphub.NLPMapper</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NLPMapper</servlet-name>
<url-pattern>/nlphub-mapper-servlet</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,179 @@
[type="checkbox"]+label {
margin-right: 15px !important;
}
.my-textarea {
border: 1px solid #555;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 4px;
height: 100px;
}
pre {
padding: 5px;
margin: 5px;
}
.string {
color: green;
}
.number {
color: darkorange;
}
.boolean {
color: blue;
}
.null {
color: magenta;
}
.key {
color: red;
}
.column {
margin-left: 1px;
float: left;
}
.half-width {
width: 48%;
}
.margin-left-10px {
margin-left: 10px;
}
.margin-right-10px {
margin-right: 10px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.fixed-height {
min-height: 200px;
}
.margin-3 {
margin: 2px;
}
.text-align-left {
text-align: left;
}
.text-align-right {
text-align: right;
}
.align-left {
float: left;
width: 80%;
}
.align-left-33 {
float: right;
width: 33%;
}
.centered {
margin-left: auto;
margin-right: auto;
}
.full-width {
width: 100%;
}
.vscrollable {
height: 220px;
overflow-y: auto;
}
.ajax-file-upload {
float: left;
margin: 10px;
color: white;
background-color: #4CAF50 !important;
padding: 0.6rem;
text-transform: uppercase;
vertical-align: middle;
border-radius: 2px;
display: inline-block;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
cursor: pointer;
}
#execute-button {
margin: 10px;
color: white;
/*background-color: #4CAF50 !important;*/
padding: 0.6rem;
text-transform: uppercase;
vertical-align: middle;
border-radius: 2px;
display: inline-block;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
cursor: pointer;
}
.ajax-file-upload-statusbar {
height: 1.3em;
width: 100% !important;
/*display: none !important;*/
}
.ajax-upload-dragdrop {
float: right;
border: solid 1px #dfdfdf;
width: 200px !important;
}
#file-info {
float: right;
margin-left: 10px;
}
.ajax-file-upload-progress {
height: 2em !important;
}
.full-width-bar {
width: 100%;
border-bottom: solid 1px gray;
}
.title-box {
width: 69%;
float: right;
padding-left: 3em;
}
.logo {
width: 100%;
}
#logo-image {
width: 200px;
height: auto;
}
.ajax-file-upload-container {
display: none !important;
float: right;
margin-left: 10px;
}
select {
display: block;
visibility: visible;
}

9389
src/main/webapp/css/materialize.css vendored Normal file

File diff suppressed because it is too large Load Diff

16
src/main/webapp/css/materialize.min.css vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

454
src/main/webapp/index.jsp Normal file
View File

@ -0,0 +1,454 @@
<!DOCTYPE html>
<html>
<head>
<!-- input=http%3A%2F%2Fws1-clarind.esc.rzg.mpg.de%2Fdrop-off%2Fstorage%2F1513257926038.txt&lang=en&analysis=const-parsing -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>NLPHub v1.2</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet" />
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css"
media="screen,projection" />
<link type="text/css" rel="stylesheet" href="css/custom.css" />
<!-- jQuery library -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript" src="js/jquery.simple.websocket.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadfile.min.js"></script>
<!-- <script type="text/javascript" src="js/main.js"></script> -->
<!-- scripting code -->
<script type="text/javascript">
var tableRawSize = 5;
var annotations = [];
var algorithms = [];
var languages = [];
var publicLink = null;
var pageGreen = "#4CAF50";
var pageGray = "#A0A0A0";
$("#execute-button").css("background-color", pageGray);
// ------------------------------------------------------------------------------------------------------
// Starting point: get the csv file with algorithm parameters and set the page with valid algs info.
// ------------------------------------------------------------------------------------------------------
$
.ajax({
url : "http://data.d4science.org/bnp4UDNyb21lSURkQXdDUnlSS0JkVWgzWk1KMUxWVGZHbWJQNStIS0N6Yz0",
type : "GET",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
var lineTokens = manageCsvData(data);
getAlgorithms(lineTokens);
buildAnnotationsAndLanguages();
resizeTable();
resizeLogo();
buildLanguageList();
setEventListeners();
$("#execute-button").css("background-color", pageGray);
$("#upload-button").uploadFile({
url : "/nlphub/nlphub-uploader-servlet",
fileName : "mytxtfile",
maxFileCount : 100,
multiple : false,
maxFileSize : 1024 * 1000 * 6.14,
showFileCounter : false,
showCancel : true,
dragDropStr : "<img class='img-prompt' src='img/upload.png' width='60px' height='60px' style='display:block; margin:auto; padding: 10px'>",
extErrorStr : "Error. Text file only",
sizeErrorStr : "Error. Max size: 6 Mb",
onLoad : function(obj) {
$("#file-info").remove();
$("#fu-container").append("<div id=\"file-info\"></div>");
},
onSuccess : function(files, data, xhr) {
console.log("files: " + files);
$("#file-info").empty();
$("#file-info").append("Uploaded: <span style=\"color:#4CAF50; letter-spacing: 1px; font-weight: bold;\">" + files + "</span>");
publicLink = data.message;
$("#execute-button").css("background-color", pageGreen);
if(publicLink == null) {
alert("Error uploading file.");
}
},
onError : function(files, status,
errMsg, pd) {
alert(errMsg);
}
});
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error");
}
});
manageCsvData = function(data) {
// first of all: split on the "newline" character in order to
// get all lines.
var lines = data.split("\n");
var tokens = [], lineTokens = [];
// second: parse each line
for (i in lines) {
var line = ',' + lines[i];
var tokenStart = -1;
for (var j = 0; j < line.length; j++) {
if (line.charAt(j) == '\"') {
j = line.indexOf('\"', j + 1);
if (j < 0)
return;
continue;
}
if (line.charAt(j) == ',') {
if (tokenStart == -1) {
tokenStart = j;
} else {
tokens[tokens.length] = line.substring(tokenStart + 1,
j);
tokenStart = j;
}
}
}
// get the new token and push it in the array
tokens[tokens.length] = line.substring(tokenStart + 1);
lineTokens[lineTokens.length] = tokens;
tokens = [];
}
return lineTokens;
}
getAlgorithms = function(lineTokens) {
// build the list of supported algorithms
for (i = 0; i < lineTokens.length; i++) {
if ((i == 0) || (lineTokens[i].length != 8))
continue; // skip the header
if (lineTokens[i][7].trim().toUpperCase() == "OK") {
var algName = lineTokens[i][0].trim();
var algDescription = lineTokens[i][1].trim();
var algId = lineTokens[i][2].trim();
var annotationList = lineTokens[i][3].replace(/"/g, " ").trim();
var language = lineTokens[i][4].replace(/"/g, " ").trim();
algorithms[algorithms.length] = {
"name" : algName,
"description" : algDescription,
"id" : algId,
"lang" : language,
"annotations" : annotationList
};
}
}
}
buildAnnotationsAndLanguages = function() {
// extract data about languages and annotations in order to populate the proper
// controls in the page
for (i in algorithms) {
var annotationList = algorithms[i].annotations;
var a = annotationList.split(/\s|,/);
for (j in a) {
a[j] = a[j].trim();
if (a[j].length > 0) {
var thereIs = false;
for (k in annotations) {
if (annotations[k].toUpperCase == a[j].toUpperCase()) {
thereIs = true;
break;
}
}
if (!thereIs)
annotations[annotations.length] = a[j];
}
}
var languageList = algorithms[i].lang;
var langs = languageList.split(/\s|,/);
for (j in langs) {
langs[j] = langs[j].trim();
if (langs[j].length > 0) {
var thereIs = false;
for (k in languages) {
if (languages[k].toUpperCase == langs[j].toUpperCase()) {
thereIs = true;
break;
}
}
if (!thereIs)
languages[languages.length] = langs[j];
}
}
}
}
setEventListeners = function() {
$("#input-textarea").on("keyup", function() {
if($("#input-textarea").val() == "")
$("#execute-button").css("background-color", pageGray);
else
$("#execute-button").css("background-color", pageGreen);
});
$("#execute-button").click(function() {
if((publicLink == null) && ($("#input-textarea").val() == "")) {
alert("You must upload a file or paste some text in the text area before submit a request.");
return;
}
// if some text has been written in the text area, then a corresponding text file
// must be written in the workspace and the public link is set.
if($("#input-textarea").val().length > 0) {
freeText = $("#input-textarea").val();
$
.ajax({
url : "/nlphub/nlphub-uploader-servlet?freetext=" + encodeURI(freeText),
type : "POST",
async : true,
contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
publicLink = data.message;
if(publicLink == null) {
alert("Error uploading file.");
}
launchAlgorithm();
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error");
}
});
}
else {
launchAlgorithm();
}
});
}
launchAlgorithm = function() {
if(publicLink == null) {
alert("No input text available for the service.");
return;
}
var list = buildInputAnnotationList();
var annList = "";
for(i in list) {
annList += list[i] + ",";
}
annList = annList.substring(0, annList.length-1);
var algList = "";
for(j in algorithms) {
algList += encodeURI(algorithms[j].id) + ",";
}
algList = algList.substring(0, algList.length-1);
var parameters = "annotations=" + annList;
parameters += "&lang=" + $("#language-select").val();
parameters += "&plink=" + encodeURI(publicLink);
parameters += "&algs=" + algList;
$
.ajax({
url : "/nlphub/nlphub-servlet?" + parameters,
type : "POST",
async : true,
//contentType : "text/plain; charset=utf-8",
success : function(data, stato) {
if(typeof(data.response) != 'undefined')
alert(data.message);
else if (typeof(data.error) != 'undefined')
alert(data.message);
else
alert("Unexpected response");
},
error : function(richiesta, stato, errori) {
alert("Unexpected Error");
}
});
publicLink = null;
}
resizeTable = function() {
// resize the annotation table
$("#annotations-table").empty();
var rowId = "";
var ratio = window.innerWidth / window.innerHeight;
if (ratio <= 0.35) {
tableRawSize = 1;
} else if ((ratio > 0.35) && (ratio <= 0.75)) {
tableRawSize = 2;
} else if ((ratio > 0.75) && (ratio <= 1)) {
tableRawSize = 3;
} else if ((ratio > 1) && (ratio <= 1.5)) {
tableRawSize = 4;
} else {
tableRawSize = 5;
}
for (var i = 0; i < annotations.length; i++) {
if (i % tableRawSize == 0) {
rowId = "row-" + i;
$("#annotations-table").append("<tr id=\"" + rowId +"\"></tr>");
}
var annotationElement = "<input type=\"checkbox\" id=\"check-" + i + "\" value=\"" + annotations[i] + "\" checked=\"checked\"></input> <label for=\"check-" + i + "\">"
+ annotations[i] + "</label>";
$("#" + rowId).append("<td>" + annotationElement + "</td>");
}
}
resizeLogo = function() {
if(window.innerWidth < 200)
$("#logo-image").width(window.innerWidth-10);
}
buildInputAnnotationList = function() {
var list = [];
for (var i = 0; i < annotations.length; i++) {
if($("#check-" + i).is(":Checked"))
list[list.length] = $("#check-" + i).val();
}
return list;
}
// event handlers
window.onresize = function(event) {
resizeTable();
resizeLogo();
};
$(".ajax-file-upload-abort").on("DOMAttrModified", function (event) {
$(".ajax-file-upload-abort").css("display", "none");
if(event.attributeName == "display") { // which attribute you want to watch for changes
$(".ajax-file-upload-abort").css("display", "none");
}
});
buildLanguageList = function() {
// build the language selection input control
for (i in languages) {
var opt = "<option value=\"" + languages[i] + "\" selected=\"selected\">"
+ languages[i] + "</option>";
if (i > 1)
opt = "<option value=\"" + languages[i] + "\">" + languages[i]
+ "</option>";
$("#language-select").append(opt);
}
}
// $("#upload-button").click(function() {
// $("#upload-input").click();
// });
// $("#upload-input").change(
// function() {
// $("#upload-button")
// .text(
// $("#upload-input").val().substring(
// $("#upload-input").val().lastIndexOf(
// "\\") + 1));
// });
</script>
</head>
<body style="padding: 0 15px;">
<div class="logo"><img id="logo-image" src="img/nlphub-logo-3.png"></div>
<!-- <div class="title-box"><h3>Natural Language Processing</h3></div> -->
<!-- the "main-div" contains all tabs and contents -->
<div class="main-div">
<!-- tabs div: each tab must refer a page div -->
<div class="col s12">
<ul class="tabs">
<li class="tab col s3"><a href="#ner">NER</a></li>
<li class="tab col s3"><a href="#other">other</a></li>
</ul>
</div>
<!-- "ner" div: contains the name entity recognizer interface -->
<div id="ner">
<p class="flow-text">Name Entity Recognition</p>
<fieldset>
<legend>Language selection</legend>
<div class="row">
<div class="clearfix">
<div class="column half-width">
<p class="margin-3 text-align-right">Select the desired
language:</p>
</div>
<div class="column half-width">
<select id="language-select" class="margin-3 align-left">
</select>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Input text</legend>
<div class="row">
<div class="clearfix">
<div class="column margin-right-10px">
<p>Use the button to upload a text file or drag and drop a file in the upload area; or paste a text in
the text area.</p>
</div>
<div class="column margin-left-10px">
<div class="centered full-width" id="fu-container">
<!-- <div class="waves-effect waves-light btn green darken-1"
id="upload-button">Upload text file</div>-->
<div class="waves-effect waves-light darken-1"
id="upload-button">Upload text file</div>
</div>
</div>
</div>
<div class="input-field col s12">
<textarea id="input-textarea" class="my-textarea" rows="8"
placeholder="paste your text here"></textarea>
</div>
</div>
</fieldset>
<fieldset>
<legend>Annotations (mark annotation you want to use)</legend>
<div class="vscrollable">
<table id="annotations-table">
</table>
</div>
</fieldset>
<div class="progress" id="progressBar" style="visibility: hidden;">
<div class="indeterminate"></div>
</div>
<div style="text-align: center; padding: 5px;">
<!-- <a class="waves-effect waves-light btn green darken-1" -->
<a id="execute-button">Execute</a>
</div>
<div id="result-container" style="margin-top: -20px;">
<div id="downloadLink" style="display: inline;"></div>
<pre id="result">
</pre>
</div>
</div>
<!-- end "#ner" -->
<div id="#other"></div>
</div>
<!-- end "#main-div" -->
</body>
</html>

File diff suppressed because one or more lines are too long

8
src/main/webapp/js/jquery.uploadfile.min.js vendored Executable file

File diff suppressed because one or more lines are too long

156
src/main/webapp/js/main.js Normal file
View File

@ -0,0 +1,156 @@
$(document).ready(function(){
// $("#upload-button").uploadFile({
// url : "uploader.php",
// fileName : "myfile",
// maxFileCount : 100,
// multiple : false,
// maxFileSize : 1024 * 1000 * 1,
// showFileCounter : false,
// showCancel : true,
// allowedTypes : "txt",
// //dragDropStr : "<img class='img-prompt' src='images/upload.png' width='60px' height='60px' style='display:block; margin:auto;'>",
// doneStr : "Done",
// abortStr : "End",
// cancelStr : "Cancel",
// extErrorStr : "Only text file (.txt), please",
// sizeErrorStr : "Max size: 1 Mb",
// onLoad : function(obj) {
// //resizeTutor();
// },
// onSuccess : function(files, data, xhr) {
// alert("Success");
// /*$(".ajax-file-upload-statusbar")
// .hide();
// $(".obfuscating").css('opacity', '0.6');
// $(".obfuscating").show();
// $("#uploadedimg").attr("src", "images/" + uName + "/" + files[0]);
// source = $("#uploadedimg").attr("src");
// window.setTimeout(function(){ sizePopupUpload(); $("#popup-1-section").show();}, 500);*/
// },
// onError : function(files, status,
// errMsg, pd) {
// alert(errMsg);
// }
// });
$( "#execute-button" ).click(function() {
var firstnameBox = $.trim( $('#input-textarea').val() )
if (firstnameBox == "") {
$('#input-textarea').css("border-color","red");
$('#input-textarea').attr("placeholder", "Paste your text here!");
}
else {
$('#input-textarea').css("border-color","#555");
doStartComputation();
}
});
doCallback = function(uri) {
$.ajax({
url : "nlphub-servlet",
type : 'GET',
datatype : 'json',
data : {
uri : uri
},
success : function(data) {
var obj = eval("(" + data + ")");
var str = JSON.stringify(obj, undefined, 4);
$('#result').html(syntaxHighlight(str));
}
});
}
doStartComputation = function() {
var options = "default";
options = $("input[type=checkbox]:checked").map(
function () {return this.value;}).get().join("|");
$('#result').html("");
//var token2Send = getUrlParameter("token") == null ? "" : getUrlParameter("token");
var tokenParam = getUrlParameter("token");
var token2Send = ((tokenParam == null) || (tokenParam.length == 0)) ? "18fed2d9-030b-4c77-93af-af2015d945f7-843339462" : getUrlParameter("token");
webSocket.send({
'action': 'start',
'text' : $("#input-textarea").val(),
'options' : options,
'token' : token2Send
}).done(function() {
showProgressBar(true);
enableCommands(false);
}).fail(function(e) {
console.log("failed");
});
}
doHandleResponse = function(message) {
if (message.response == "error") {
$('#result').html("<span style='color: red;'>"+message.value+"</span>");
enableCommands(true);
showProgressBar(false);
}
else if (message.response == "computing") {
showProgressBar(true);
enableCommands(false);
}
else if (message.response == "computed") {
showProgressBar(false);
enableCommands(true);
console.log("message="+message.value);
if (message.value.startsWith("http")) {
$('#downloadLink').html("Result:&nbsp;<a class=\"waves-effect waves-light btn red darken-1\" href=\""+message.value+"\">Download</a>&nbsp;" +
"<a class=\"waves-effect waves-light btn blue darken-1\" href=\"Javascript:doCallback(encodeURI('"+message.value.trim()+"'));\">View</a>");
}
}
}
});
function showProgressBar(show) {
var display = (show) ? "visible" : "hidden";
$('#progressBar').css('visibility', display);
}
function enableCommands(enable) {
if (enable) {
$('#execute-button').removeAttr("disabled");
$('#execute-button').text('Execute');
$('input[type=checkbox]').removeAttr("disabled");
} else {
$('#execute-button').text('Computing ...');
$('input[type=checkbox]').attr('disabled', 'true');
$('#execute-button').attr('disabled', 'disabled');
$('#downloadLink').html("");
}
}
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 1);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

10021
src/main/webapp/js/materialize.js vendored Normal file

File diff suppressed because it is too large Load Diff

6
src/main/webapp/js/materialize.min.js vendored Normal file

File diff suppressed because one or more lines are too long