You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2014/09/08 22:57:52 UTC
svn commit: r1623570 -
/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
Author: schor
Date: Mon Sep 8 20:57:52 2014
New Revision: 1623570
URL: http://svn.apache.org/r1623570
Log:
[UIMA-3969] add debug dump method, remove extra System.output, and remove test of number-of-children, since it's not used (the only user was Vinci serialization, and then only with XCAS, not XMI serialization).
Modified:
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java?rev=1623570&r1=1623569&r2=1623570&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java Mon Sep 8 20:57:52 2014
@@ -23,8 +23,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Iterator;
@@ -44,7 +46,6 @@ import org.apache.uima.cas.ArrayFS;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.FSIndex;
-import org.apache.uima.cas.FSIndexRepository;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
@@ -53,14 +54,13 @@ import org.apache.uima.cas.Marker;
import org.apache.uima.cas.StringArrayFS;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
-import org.apache.uima.cas.impl.XmiCasSerializer.CasDocSerializer;
+import org.apache.uima.cas.impl.XmiCasSerializer.XmiDocSerializer;
import org.apache.uima.cas.impl.XmiSerializationSharedData.OotsElementData;
import org.apache.uima.cas.impl.XmiSerializationSharedData.XmiArrayElement;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.cas_data.impl.CasComparer;
import org.apache.uima.internal.util.XmlAttribute;
import org.apache.uima.internal.util.XmlElementNameAndContents;
-import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
@@ -143,7 +143,8 @@ public class XmiCasDeserializerTest exte
// reserialize as XMI
String xml = serialize(cas, null);
-// System.out.println(xml);
+// dumpStr2File(xml, "145");
+
// deserialize into another CAS
CAS cas2 = CasCreationUtils.createCas(typeSystemDescription, new TypePriorities_impl(), indexes);
@@ -336,7 +337,7 @@ public class XmiCasDeserializerTest exte
//serialize complete
XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
String xml = serialize(cas1, sharedData);
- System.out.println(xml);
+// System.out.println(xml);
int maxOutgoingXmiId = sharedData.getMaxXmiId();
//deserialize into cas2
@@ -361,7 +362,7 @@ public class XmiCasDeserializerTest exte
// serialize cas2 in delta format
String deltaxml1 = serialize(cas2, sharedData2, marker);
- System.out.println(deltaxml1);
+// System.out.println(deltaxml1);
//deserialize delta xmi into cas1
this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
@@ -387,7 +388,7 @@ public class XmiCasDeserializerTest exte
//serialize complete
XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
String xml = serialize(cas1, sharedData);
- System.out.println(xml);
+// System.out.println(xml);
int maxOutgoingXmiId = sharedData.getMaxXmiId();
//deserialize into cas2
@@ -417,7 +418,7 @@ public class XmiCasDeserializerTest exte
// serialize cas2 in delta format
String deltaxml1 = serialize(cas2, sharedData2, marker);
- System.out.println(deltaxml1);
+// System.out.println(deltaxml1);
//deserialize delta xmi into cas1
this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
@@ -441,7 +442,7 @@ public class XmiCasDeserializerTest exte
//serialize complete
XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
String xml = serialize(cas1, sharedData);
- System.out.println(xml);
+// System.out.println(xml);
int maxOutgoingXmiId = sharedData.getMaxXmiId();
//deserialize into cas2
@@ -466,7 +467,7 @@ public class XmiCasDeserializerTest exte
// serialize cas2 in delta format
String deltaxml1 = serialize(cas2, sharedData2, marker);
- System.out.println(deltaxml1);
+// System.out.println(deltaxml1);
//deserialize delta xmi into cas1
this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow);
@@ -776,7 +777,7 @@ public class XmiCasDeserializerTest exte
XmiSerializationSharedData serSharedData = new XmiSerializationSharedData();
String xmiStr = serialize(cas, serSharedData);
int maxOutgoingXmiId = serSharedData.getMaxXmiId();
-
+
// deserialize into two new CASes, each with its own instance of XmiSerializationSharedData
// so we can get consistent IDs later when serializing back.
CAS newCas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
@@ -871,6 +872,7 @@ public class XmiCasDeserializerTest exte
// Serialize/deserialize again in case merge created duplicate ids
String newSerCasMerged = serialize(cas, serSharedData);
+
deserialize(newSerCasMerged, cas, serSharedData, false, -1);
//check covered text of annotations
@@ -1410,7 +1412,7 @@ public class XmiCasDeserializerTest exte
//serialize complete cas and deserialize into cas3 and compare with cas1.
String fullxml = serialize(cas2, sharedData2);
XmiSerializationSharedData sharedData3 = new XmiSerializationSharedData();
- this.deserialize(fullxml, cas3, sharedData3, true,-1);
+ this.deserialize(fullxml, cas3, sharedData3, true, -1);
CasComparer.assertEquals(cas1, cas3);
//System.out.println("CAS1 " + serialize(cas1, new XmiSerializationSharedData()));
@@ -1772,21 +1774,37 @@ public class XmiCasDeserializerTest exte
CasComparer.assertEquals(originalCas, newCas);
}
- public void testGetNumChildren() throws Exception {
- // deserialize a complex XCAS
- CAS cas = CasCreationUtils.createCas(typeSystem, null, indexes);
-// InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/cas.xml"));
-// XCASDeserializer.deserialize(serCasStream, cas);
+// public void testdebugnc() throws Exception {
+// CAS cas = CasCreationUtils.createCas(typeSystem, null, indexes);
+// InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/simpleCas.xmi"));
+// XmiCasDeserializer.deserialize(serCasStream, cas);
// serCasStream.close();
- InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/simpleCas.xmi"));
- XmiCasDeserializer.deserialize(serCasStream, cas);
- serCasStream.close();
-
- // call serializer with a ContentHandler that checks numChildren
- XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
- GetNumChildrenTestHandler handler = new GetNumChildrenTestHandler(xmiSer, (CASImpl)cas);
- xmiSer.serialize(cas, handler, handler.tcds);
- }
+//
+// XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
+// String r = serialize(cas, sharedData);
+//
+// { File f = new File("C:/au/wksp431/apache/json-work/tempdebug.xml");
+// PrintWriter pw = new PrintWriter(f);
+// pw.println(r);
+// pw.close();
+// }
+//
+// }
+// public void testGetNumChildren() throws Exception {
+// // deserialize a complex XCAS
+// CAS cas = CasCreationUtils.createCas(typeSystem, null, indexes);
+//// InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/cas.xml"));
+//// XCASDeserializer.deserialize(serCasStream, cas);
+//// serCasStream.close();
+// InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/simpleCas.xmi"));
+// XmiCasDeserializer.deserialize(serCasStream, cas);
+// serCasStream.close();
+//
+// // call serializer with a ContentHandler that checks numChildren
+// XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
+// GetNumChildrenTestHandler handler = new GetNumChildrenTestHandler(xmiSer, (CASImpl)cas);
+// xmiSer.serialize(cas, handler, handler.tcds);
+// }
/** Utility method for serializing a CAS to an XMI String
* */
@@ -1861,54 +1879,81 @@ public class XmiCasDeserializerTest exte
}
return true;
}
-
- static class GetNumChildrenTestHandler extends DefaultHandler {
- XmiCasSerializer xmiSer;
- Stack<Integer> childCountStack = new Stack<Integer>();
- private CasDocSerializer tcds;
-
- GetNumChildrenTestHandler(XmiCasSerializer xmiSer, CASImpl cas) {
- this.xmiSer = xmiSer;
- tcds = xmiSer.getTestCasDocSerializer(this, cas);
- childCountStack.push(Integer.valueOf(1));
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- // TODO Auto-generated method stub
- super.startElement(uri, localName, qName, attributes);
- childCountStack.push(Integer.valueOf(tcds.getNumChildren()));
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public void endElement(String uri, String localName, String qName) throws SAXException {
- // TODO Auto-generated method stub
- super.endElement(uri, localName, qName);
- //check that we've seen the expected number of child elements
- //(count on top of stack should be 0)
- Integer count = (Integer)childCountStack.pop();
- assertEquals(0, count.intValue());
-
- //decremenet child count of our parent
- count = (Integer)childCountStack.pop();
- childCountStack.push(Integer.valueOf(count.intValue() - 1));
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
- */
- public void characters(char[] ch, int start, int length) throws SAXException {
- // text node is considered a child
- if (length > 0) {
- Integer count = (Integer)childCountStack.pop();
- childCountStack.push(Integer.valueOf(count.intValue() - 1));
- }
- }
-
- }
+ /** for debug
+ *
+ * @param s - string to dump
+ * @param name - file name part
+ */
+ private static void dumpStr2File(String s, String namepart) throws FileNotFoundException {
+
+ File f = new File("C:/au/wksp431/apache/json-work/temp" + namepart + ".xml");
+ PrintWriter pw = new PrintWriter(f);
+ pw.println(s);
+ pw.close();
+
+ }
+// /**
+// * Extends the SAX Normal default handler used to output xml
+// * Keeps a stack of counts:
+// * For every startElement call, pushes the number of children of that element onto the stack
+// * For every endElement call, test if at number has been decremented to 0
+// * Inner endElement calls decrement the count (of their parentt,
+// * Inner "text" elements also do this (for their parent)
+// */
+// static class GetNumChildrenTestHandler extends DefaultHandler {
+// XmiCasSerializer xmiSer;
+// Stack<Integer> childCountStack = new Stack<Integer>();
+// private XmiDocSerializer tcds;
+//
+// GetNumChildrenTestHandler(XmiCasSerializer xmiSer, CASImpl cas) {
+// this.xmiSer = xmiSer;
+// tcds = xmiSer.getTestXmiDocSerializer(this, cas);
+// childCountStack.push(Integer.valueOf(1));
+// }
+//
+// /* (non-Javadoc)
+// * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+// */
+// public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+// // TODO Auto-generated method stub
+// super.startElement(uri, localName, qName, attributes);
+// childCountStack.push(Integer.valueOf(tcds.getNumChildren()));
+// System.out.format("Debug: NumberOfChildren: Starting element %s, setting count to %d%n", qName, tcds.getNumChildren());
+// }
+//
+// /* (non-Javadoc)
+// * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+// */
+// public void endElement(String uri, String localName, String qName) throws SAXException {
+// // TODO Auto-generated method stub
+// super.endElement(uri, localName, qName);
+// //check that we've seen the expected number of child elements
+// //(count on top of stack should be 0)
+// Integer count = (Integer)childCountStack.pop();
+// assertEquals(0, count.intValue());
+//
+// //decremenet child count of our parent
+// count = (Integer)childCountStack.pop();
+// childCountStack.push(Integer.valueOf(count.intValue() - 1));
+// System.out.format("Debug: NumberOfChildren: ending element %s, decr parent count to %d%n", qName, count - 1);
+//
+// }
+//
+// /* (non-Javadoc)
+// * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+// */
+// public void characters(char[] ch, int start, int length) throws SAXException {
+// // text node is considered a child
+// if (length > 0) {
+// Integer count = (Integer)childCountStack.pop();
+// childCountStack.push(Integer.valueOf(count.intValue() - 1));
+// System.out.format("Debug: NumberOfChildren: ending text element, decr parent count to %d%n", count - 1);
+// } else {
+// System.out.format("Debug: NumberOfChildren: ending empty text element, not decr count%n");
+// }
+// }
+//
+//
+// }
}