Skip to content

Commit

Permalink
Merge pull request #17 from texttechnologylab/0.0.2
Browse files Browse the repository at this point in the history
added REST Client
  • Loading branch information
Wahed Hemati authored Apr 3, 2020
2 parents 5ebd5a6 + 0cb3db9 commit 6ea0077
Show file tree
Hide file tree
Showing 24 changed files with 913 additions and 28 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
Expand Down
6 changes: 6 additions & 0 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="textimager-client">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.8"/>
<installed facet="jst.utility" version="1.0"/>
</faceted-project>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.wst.validation.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1
124 changes: 101 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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.hucompute</groupId>
<artifactId>textimager-client</artifactId>
<version>0.0.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<version>0.2.1</version>
<packaging>${packaging.type}</packaging>

<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>ukp-oss-model-releases</id>
<url>http://zoidberg.ukp.informatik.tu-darmstadt.de/artifactory/public-model-releases-local</url>
Expand All @@ -28,6 +32,11 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<packaging.type>jar</packaging.type>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -60,6 +69,11 @@
</profile>
<profile>
<id>CLI</id>
<properties>
<packaging.type>jar</packaging.type>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -116,9 +130,66 @@
</plugins>
</build>
</profile>
<profile>
<id>war</id>
<properties>
<packaging.type>war</packaging.type>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<finalName>rest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-as-core</artifactId>
Expand All @@ -134,7 +205,6 @@
<artifactId>uimaj-as-activemq</artifactId>
<version>2.10.3</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -157,25 +227,33 @@
</dependency>
<dependency>
<groupId>com.github.texttechnologylab.textimager-uima</groupId>
<artifactId>textimager-uima-io</artifactId>
<version>0.0.2.rc2</version>
<artifactId>textimager-uima-types</artifactId>
<version>0.2.1.rc1</version>
</dependency>
<dependency>
<groupId>com.github.texttechnologylab.textimager-uima</groupId>
<artifactId>textimager-uima-types</artifactId>
<version>0.0.2.rc2</version>
<artifactId>textimager-uima-io</artifactId>
<version>0.2.1.rc1</version>
</dependency>
<!-- <dependency> <groupId>org.hucompute.textimager.uima</groupId> <artifactId>textimager-uima-types</artifactId>
<version>0.0.2</version> </dependency> <dependency> <groupId>org.hucompute.textimager.uima</groupId>
<artifactId>textimager-uima-io</artifactId> <version>0.0.2</version> </dependency>
<dependency> <groupId>org.hucompute.textimager.uima</groupId> <artifactId>textimager-uima-deploy</artifactId>
<version>0.0.2</version> </dependency> -->

<!-- <dependency> -->
<!-- <groupId>org.hucompute.textimager.uima</groupId> -->
<!-- <artifactId>textimager-uima-types</artifactId> -->
<!-- <version>0.0.2</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.hucompute.textimager.uima</groupId> -->
<!-- <artifactId>textimager-uima-io</artifactId> -->
<!-- <version>0.0.2</version> -->
<!-- </dependency> -->
<dependency>
<groupId>de.tudarmstadt.ukp.dkpro.core</groupId>
<artifactId>de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-parser-en-rnn</artifactId>
<version>20140104.1</version>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>

</dependencies>
</project>
16 changes: 16 additions & 0 deletions src/main/java/org/hucompute/textimager/client/rest/CasError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.hucompute.textimager.client.rest;

import java.util.HashMap;
import java.util.Map;

public class CasError {
String docId;
String status;
Map<String, String> exceptions;

public CasError(String docId, String status) {
this.docId = docId;
this.status = status;
this.exceptions = new HashMap<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.hucompute.textimager.client.rest;

import java.util.HashMap;
import java.util.Map;

import org.apache.uima.aae.UimaASApplicationEvent.EventTrigger;
import org.apache.uima.aae.client.UimaASProcessStatus;
import org.apache.uima.aae.client.UimaAsBaseCallbackListener;
import org.apache.uima.cas.CAS;
import org.apache.uima.collection.EntityProcessStatus;

import de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData;
import org.codehaus.plexus.util.ExceptionUtils;


public class ExceptionCollectorListener extends UimaAsBaseCallbackListener{
private Map<String, CasError> errors;

public boolean hasErrors() {
return !errors.isEmpty();
}

public Map<String, CasError> getErrors() {
return errors;
}

public ExceptionCollectorListener() {
super();
errors = new HashMap<>();
}

@Override
public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
super.entityProcessComplete(aCas, aStatus);

if (aStatus.isException()) {
String docId = DocumentMetaData.get(aCas).getDocumentId();
CasError casError = new CasError(docId, aStatus.getStatusMessage());

for (Exception ex : aStatus.getExceptions()) {
String name = "Unknown Error";
String fullst = ExceptionUtils.getFullStackTrace(ex);

ex.printStackTrace();

// Provide specific error names on known problems...
if (fullst.contains("Unable to load resource")) {
name = "Service Language Error";
}
else if (fullst.contains("org.apache.uima.aae.error.UimaASProcessCasTimeout")) {
name = "Service Unavailable Error";
}

casError.exceptions.put(name, fullst);
}

errors.put(docId, casError);
}
}

@Override
public void collectionProcessComplete(EntityProcessStatus aStatus) {
super.collectionProcessComplete(aStatus);
//System.out.println("collectionProcessComplete");
};

@Override
public void onBeforeMessageSend(UimaASProcessStatus status) {
super.onBeforeMessageSend(status);
//System.out.println("onBeforeMessageSend");
}

@Override
public void onBeforeProcessCAS(UimaASProcessStatus status, String nodeIP, String pid) {
super.onBeforeProcessCAS(status, nodeIP, pid);
//System.out.println("onBeforeProcessCAS");
}

@Override
public void onBeforeProcessMeta(String nodeIP, String pid) {
super.onBeforeProcessMeta(nodeIP, pid);
//System.out.println("onBeforeProcessMeta");
}

@Override
public void onUimaAsServiceExit(EventTrigger cause) {
super.onUimaAsServiceExit(cause);
//System.out.println("onUimaAsServiceExit");
}

@Override
public void initializationComplete(EntityProcessStatus aStatus) {
super.initializationComplete(aStatus);
System.out.println(aStatus);
//System.out.println("initializationComplete");
}

}
Loading

0 comments on commit 6ea0077

Please sign in to comment.