Fixed empty left context and updated libraries.
diff --git a/pom.xml b/pom.xml
index 399261a..6eeb78f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,15 +4,20 @@
<groupId>de.mannheim.ids</groupId>
<artifactId>SRU-WS</artifactId>
<packaging>war</packaging>
- <version>1.0.1-SNAPSHOT</version>
+ <version>1.0.2</version>
<name>SRU-WS Maven Webapp</name>
<url>http://maven.apache.org</url>
- <dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
<dependency>
<groupId>eu.clarin.weblicht</groupId>
<artifactId>wlfxb</artifactId>
- <version>1.2.9</version>
+ <version>1.4.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
@@ -28,12 +33,12 @@
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
- <version>1.13</version>
+ <version>1.19.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.3.3</version>
+ <version>4.5.8</version>
</dependency>
<!-- <dependency>
<groupId>org.slf4j</groupId>
@@ -43,12 +48,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>1.7.5</version>
+ <version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
- <version>3.3.2</version>
+ <version>3.9</version>
</dependency>
</dependencies>
<build>
@@ -57,10 +62,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.1</version>
+ <version>3.8.1</version>
<configuration>
- <source>1.7</source>
- <target>1.7</target>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
</plugins>
diff --git a/src/main/java/de/mannheim/ids/sruws/SRU_WS.java b/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
index 88e45bf..6f10357 100644
--- a/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
+++ b/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
@@ -257,9 +257,15 @@
XMLStreamReader reader = f.createXMLStreamReader(is);
Corpus c = null;
- int e;
+ int e = 0;
+ boolean emptyText = false;
while (reader.hasNext()) {
- e = reader.next();
+ if (!emptyText){
+ e = reader.next();
+ }
+ else{
+ emptyText= false;
+ }
if (e == XMLEvent.START_ELEMENT &&
reader.getLocalName().equals("Result")
@@ -268,8 +274,13 @@
sb = new StringBuilder();
reader.next();
- sb.append(reader.getText());
- sb.append(" "); // left context
+ if (reader.hasText()){
+ sb.append(reader.getText());
+ sb.append(" "); // left context
+ }
+ else{
+ emptyText = true;
+ }
}
else if (e == XMLEvent.START_ELEMENT
&&
@@ -321,16 +332,31 @@
}
else if (e == XMLEvent.END_ELEMENT &&
- (reader.getLocalName().equals("kwic") ||
- reader.getLocalName().equals("Hit"))
- ) {
+ (reader.getLocalName().equals("kwic"))) {
kwic = normalizeString(sb.toString());
Sentence s = createSentence(kwic);
c.addSentence(s);
// logger.info(kwic);
kwicCollector.append(s.getSentenceString());
- }
+ }
+
+ else if (e == XMLEvent.END_ELEMENT &&
+ reader.getLocalName().equals("Hit")) {
+
+ e = reader.next();
+ if (reader.hasText()){
+ sb.append(reader.getText());
+ }
+ else{
+ emptyText = true;
+ }
+ kwic = normalizeString(sb.toString());
+ Sentence s = createSentence(kwic);
+ c.addSentence(s);
+ // logger.info(kwic);
+ kwicCollector.append(s.getSentenceString());
+ }
}
return kwicCollector.toString();
}
diff --git a/src/test/java/de/mannheim/ids/sruws/test/TestClient.java b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
index f5a995e..a5870fd 100644
--- a/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
+++ b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
@@ -1,35 +1,26 @@
package de.mannheim.ids.sruws.test;
+
+import static org.junit.Assert.assertEquals;
+
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
-import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
public class TestClient {
public static void main(String arg[]) throws IOException{
String url =
- "http://localhost:8080/SRU-WS/" +
- // "http://clarin.ids-mannheim.de/fcsws" +
+// "http://localhost:8080/SRU-WS/" +
+ "http://clarin.ids-mannheim.de/fcsws" +
"?maximumRecords=10&endpoint=korap";
HttpClient client = HttpClientBuilder.create().build();
@@ -44,21 +35,15 @@
// post.setEntity(new UrlEncodedFormEntity(urlParameters));
String query = "Baden-Württemberg";
+// String query = "Katze";
+
HttpEntity entity = new StringEntity(query, Charset.defaultCharset());
post.setEntity(entity);
HttpResponse response = client.execute(post);
- System.out.println("Sending 'POST' request to URL : " + url);
- System.out.println("Post parameters : " + post.getEntity());
- System.out.println("Response Code : " +
- response.getStatusLine().getStatusCode());
- if (response.getStatusLine().getStatusCode() != 200){
- System.out.println("Response Code : " +
- response.getStatusLine().getReasonPhrase());
- }
+ assertEquals(200,response.getStatusLine().getStatusCode());
// FileWriter fw = new FileWriter(new File("test.xml"));
-
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line;