You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2008/01/08 14:39:49 UTC
svn commit: r609975 - in /incubator/uima/sandbox/trunk/SimpleServer/src/main:
java/org/apache/uima/simpleserver/
java/org/apache/uima/simpleserver/config/impl/
java/org/apache/uima/simpleserver/output/
java/org/apache/uima/simpleserver/output/impl/ jav...
Author: twgoetz
Date: Tue Jan 8 05:39:45 2008
New Revision: 609975
URL: http://svn.apache.org/viewvc?rev=609975&view=rev
Log:
Jira UIMA-690: make SimpleServer inline xml output format work even if begin and end positions are not mapped.
https://issues.apache.org/jira/browse/UIMA-690
Modified:
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/ResultExtractor.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/TypeMapImpl.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/InlineXMLGenerator.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/ResultEntry.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/impl/ResultEntryImpl.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ResultMerger.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/resources/tokenizerSpec.xml
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/ResultExtractor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/ResultExtractor.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/ResultExtractor.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/ResultExtractor.java Tue Jan 8 05:39:45 2008
@@ -78,7 +78,8 @@
// Check that there either is no filter, or the FS passes the filter.
if ((filter == null) || filter.match(annotation)) {
// Create a new result entry, fill with attributes and add result set.
- ResultEntryImpl resultEntry = new ResultEntryImpl(tspec.getOutputTag());
+ ResultEntryImpl resultEntry = new ResultEntryImpl(tspec.getOutputTag(), annotation
+ .getBegin(), annotation.getEnd());
makeOutputs(resultEntry, annotation, tspec);
resultEntries.add(resultEntry);
}
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/TypeMapImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/TypeMapImpl.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/TypeMapImpl.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/TypeMapImpl.java Tue Jan 8 05:39:45 2008
@@ -24,7 +24,6 @@
import java.util.List;
import org.apache.uima.simpleserver.config.Filter;
-import org.apache.uima.simpleserver.config.SimpleFilter;
import org.apache.uima.simpleserver.config.Output;
import org.apache.uima.simpleserver.config.TypeMap;
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/InlineXMLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/InlineXMLGenerator.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/InlineXMLGenerator.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/InlineXMLGenerator.java Tue Jan 8 05:39:45 2008
@@ -26,14 +26,14 @@
import java.util.TreeSet;
/*
- * This class contains static methods responsible for creation of
- * inline-xml from the given Result object.
+ * This class contains static methods responsible for creation of inline-xml from the given Result
+ * object.
*/
public class InlineXMLGenerator {
/*
- * main method of this class - decides, which annotations should be taken, and
- * produces the string with inline-xml.
+ * main method of this class - decides, which annotations should be taken, and produces the string
+ * with inline-xml.
*/
public static String getInlineXML(Result result) {
// a list of all positions where some tags begin
@@ -65,16 +65,11 @@
// first of all, we decide which annotions to take
// this loop iterates over all available annotations
loop: for (ResultEntry entry : result.getResultEntries()) {
- String strBegin = entry.getAttriuteValue("begin");
- String strEnd = entry.getAttriuteValue("end");
- if ((strBegin == null) || (strEnd == null)) {
- continue loop;
- }
Integer begin;
Integer end;
try {
- begin = new Integer(strBegin);
- end = new Integer(strEnd);
+ begin = new Integer(entry.getBegin());
+ end = new Integer(entry.getEnd());
} catch (NumberFormatException e) {
// we don't take annotations without features "begin" and "end"
continue loop;
@@ -202,8 +197,7 @@
}
/*
- * sorts the beginning tags by length descending and adds them to the given
- * string buffer
+ * sorts the beginning tags by length descending and adds them to the given string buffer
*/
private static void printBeginTags(List<ResultEntry> list, StringBuffer sb) {
while (!list.isEmpty()) {
@@ -222,8 +216,7 @@
}
/*
- * sorts the ending tags by length ascending and adds them to the given string
- * buffer
+ * sorts the ending tags by length ascending and adds them to the given string buffer
*/
private static void printEndTags(List<ResultEntry> list, StringBuffer sb) {
while (!list.isEmpty()) {
@@ -255,11 +248,7 @@
* gets the length of an annotation
*/
private static int len(ResultEntry entry) {
- String strBegin = entry.getAttriuteValue("begin");
- String strEnd = entry.getAttriuteValue("end");
- int b = Integer.parseInt(strBegin);
- int e = Integer.parseInt(strEnd);
- return e - b + 1;
+ return entry.getEnd() - entry.getBegin() + 1;
}
/*
@@ -322,8 +311,7 @@
}
/*
- * escapes the XML characters in the given text and adds the result to the
- * given string buffer
+ * escapes the XML characters in the given text and adds the result to the given string buffer
*/
public static void normalize(String aStr, StringBuffer aResultBuf, boolean aNewlinesToSpaces) {
if (aStr != null) {
@@ -360,21 +348,16 @@
}
/*
- * determines whether the given annotation has a conflict with another
- * annotation with specified begin and end positions.
+ * determines whether the given annotation has a conflict with another annotation with specified
+ * begin and end positions.
*/
private static boolean isConflict(ResultEntry entry, int begin, int end) {
- String strBegin = entry.getAttriuteValue("begin");
- String strEnd = entry.getAttriuteValue("end");
- int b = Integer.parseInt(strBegin);
- int e = Integer.parseInt(strEnd);
- return isConflict(b, e, begin, end);
+ return isConflict(entry.getBegin(), entry.getEnd(), begin, end);
}
/*
- * determines whether the anotations with begin positions b1 and b2 and end
- * positions e1 and e2 cross each other, producing a conflict in the xml
- * output
+ * determines whether the anotations with begin positions b1 and b2 and end positions e1 and e2
+ * cross each other, producing a conflict in the xml output
*/
private static boolean isConflict(int b1, int e1, int b2, int e2) {
if (b1 == b2) {
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/ResultEntry.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/ResultEntry.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/ResultEntry.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/ResultEntry.java Tue Jan 8 05:39:45 2008
@@ -48,4 +48,8 @@
*/
public String getCoveredText();
+ public int getBegin();
+
+ public int getEnd();
+
}
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/impl/ResultEntryImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/impl/ResultEntryImpl.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/impl/ResultEntryImpl.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/output/impl/ResultEntryImpl.java Tue Jan 8 05:39:45 2008
@@ -31,13 +31,27 @@
* No sophisticated logic, just a bean-like class.
*/
public class ResultEntryImpl implements ResultEntry {
- private String entryName;
+
+ private final String entryName;
+
+ private final int begin;
+
+ private final int end;
private List<String> attributeNames;
private Map<String, String> attributes;
private String coveredText = null;
+
+ public ResultEntryImpl(String entryName, int begin, int end) {
+ super();
+ this.entryName = entryName;
+ this.begin = begin;
+ this.end = end;
+ this.attributes = new HashMap<String, String>();
+ this.attributeNames = new LinkedList<String>();
+ }
public String getCoveredText() {
return this.coveredText;
@@ -56,17 +70,6 @@
return this.entryName;
}
- public void setEntryName(String entryName) {
- this.entryName = entryName;
- }
-
- public ResultEntryImpl(String entryName) {
- super();
- this.entryName = entryName;
- this.attributes = new HashMap<String, String>();
- this.attributeNames = new LinkedList<String>();
- }
-
/*
* (non-Javadoc)
*
@@ -90,5 +93,19 @@
*/
public List<String> getAttributeNames() {
return this.attributeNames;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.simpleserver.output.ResultEntry#getBegin()
+ */
+ public int getBegin() {
+ return this.begin;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.simpleserver.output.ResultEntry#getEnd()
+ */
+ public int getEnd() {
+ return this.end;
}
}
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ResultMerger.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ResultMerger.java?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ResultMerger.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ResultMerger.java Tue Jan 8 05:39:45 2008
@@ -59,6 +59,8 @@
* and sends the requests simultaneously to the URLs received as
* parameters "url1", "url2", etc.
*
+ * TODO: does not currently work, needs to be fixed.
+ *
*/
public class ResultMerger extends SimpleServerServlet {
@@ -273,7 +275,7 @@
if (resultElements.item(i) instanceof Element) {
Element element = (Element) resultElements.item(i);
// create a ResultEntry object
- ResultEntryImpl entry = new ResultEntryImpl(element.getNodeName());
+ ResultEntryImpl entry = new ResultEntryImpl(element.getNodeName(), 0, 0);
// fill the ResultEntry with data read from the element
NamedNodeMap attributes = element.getAttributes();
int k = attributes.getLength();
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/resources/tokenizerSpec.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/resources/tokenizerSpec.xml?rev=609975&r1=609974&r2=609975&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/resources/tokenizerSpec.xml (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/resources/tokenizerSpec.xml Tue Jan 8 05:39:45 2008
@@ -26,4 +26,7 @@
<type name="org.apache.uima.TokenAnnotation" outputTag="token"
outputCoveredText="true">
</type>
+ <type name="org.apache.uima.SentenceAnnotation" outputTag="sentence"
+ outputCoveredText="true">
+ </type>
</uimaSimpleServerSpec>