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 2017/09/12 19:55:17 UTC
svn commit: r1808149 - in /uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml
Author: schor
Date: Tue Sep 12 19:55:16 2017
New Revision: 1808149
URL: http://svn.apache.org/viewvc?rev=1808149&view=rev
Log:
[UIMA-5558] fix special case xmi serialization for 0 length string arrays and lists; add a new test case.
Added:
uima/uimaj/trunk/uimaj-core/src/test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java?rev=1808149&r1=1808148&r2=1808149&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java Tue Sep 12 19:55:16 2017
@@ -717,7 +717,8 @@ public class XmiCasSerializer {
protected void writeArrays(int addr, int typeCode, int typeClass) throws SAXException {
XmlElementName xmlElementName = cds.typeCode2namespaceNames[typeCode];
- if (typeClass == LowLevelCAS.TYPE_CLASS_STRINGARRAY) {
+ if (typeClass == LowLevelCAS.TYPE_CLASS_STRINGARRAY &&
+ cds.cas.ll_getArraySize(addr) != 0) { //https://issues.apache.org/jira/browse/UIMA-5558
// string arrays are encoded as elements, in case they contain whitespace
List<XmlElementNameAndContents> childElements = new ArrayList<XmlElementNameAndContents>();
@@ -917,6 +918,8 @@ public class XmiCasSerializer {
case LowLevelCAS.TYPE_CLASS_STRINGARRAY:
if (cds.isStaticMultiRef(featCode)) {
attrValue = cds.getXmiId(featValRaw);
+ } else if (cds.cas.ll_getArraySize(featValRaw) == 0) {
+ attrValue = ""; //https://issues.apache.org/jira/browse/UIMA-5558
} else {
stringArrayToElementList(featName, featValRaw, childElements);
attrValue = null;
@@ -952,11 +955,15 @@ public class XmiCasSerializer {
// if (array.length > 0 && !arrayAndListFSs.put(featVal, featVal)) {
// reportWarning("Warning: multiple references to a ListFS. Reference identity will not be preserved.");
// }
- for (String string : listOfStrings) {
- childElements.add(new XmlElementNameAndContents(new XmlElementName("", featName,
- featName), string));
+ if (featValRaw != CASImpl.NULL && listOfStrings.isEmpty()) { https://issues.apache.org/jira/browse/UIMA-5558
+ attrValue = "";
+ } else {
+ for (String string : listOfStrings) {
+ childElements.add(new XmlElementNameAndContents(new XmlElementName("", featName,
+ featName), string));
+ }
+ attrValue = null;
}
- attrValue = null;
}
break;
@@ -1090,7 +1097,7 @@ public class XmiCasSerializer {
case LowLevelCAS.TYPE_CLASS_BYTEARRAY:
fs = new ByteArrayFSImpl(addr, cds.cas);
break;
- default: {
+ default: { // used for string arrays of 0 length
return "";
}
}
@@ -1112,6 +1119,15 @@ public class XmiCasSerializer {
}
}
+ /**
+ * https://issues.apache.org/jira/browse/UIMA-5558
+ *
+ * If the string array has 0 length, no child elements are generated.
+ * In that case,
+ * @param featName -
+ * @param addr -
+ * @param resultList -
+ */
private void stringArrayToElementList(
String featName,
int addr,
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=1808149&r1=1808148&r2=1808149&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 Tue Sep 12 19:55:16 2017
@@ -64,10 +64,13 @@ import org.apache.uima.internal.util.Xml
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.cas.EmptyFSList;
import org.apache.uima.jcas.cas.EmptyIntegerList;
+import org.apache.uima.jcas.cas.EmptyStringList;
import org.apache.uima.jcas.cas.FSArray;
import org.apache.uima.jcas.cas.FSList;
import org.apache.uima.jcas.cas.IntegerList;
import org.apache.uima.jcas.cas.NonEmptyFSList;
+import org.apache.uima.jcas.cas.StringArray;
+import org.apache.uima.jcas.cas.StringList;
import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.TypeDescription;
@@ -115,6 +118,92 @@ public class XmiCasDeserializerTest exte
}
/**
+ * test case for https://issues.apache.org/jira/projects/UIMA/issues/UIMA-5558
+ * @throws Exception
+ */
+ public void testSerialize_with_0_length_array() throws Exception {
+
+ TypeSystemDescription typeSystemDescription = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(JUnitExtension.getFile("ExampleCas/testTypeSystem_small_withoutMultiRefs.xml")));
+ CAS cas = CasCreationUtils.createCas(typeSystemDescription, new TypePriorities_impl(), null);
+
+ TypeSystem ts = cas.getTypeSystem();
+ Type refType = ts.getType("RefType"); // super is Annotation
+ Feature ref = refType.getFeatureByBaseName("ref");
+ Feature ref_StringArray = refType.getFeatureByBaseName("ref_StringArray");
+ Feature ref_StringList = refType.getFeatureByBaseName("ref_StringList");
+ JCas jcas = cas.getJCas();
+
+ String xml;
+
+ // deserialize into another CAS
+ SAXParserFactory fact = SAXParserFactory.newInstance();
+ SAXParser parser = fact.newSAXParser();
+ XMLReader xmlReader = parser.getXMLReader();
+
+ CAS cas2 = CasCreationUtils.createCas(typeSystemDescription, new TypePriorities_impl(), null);
+ XmiCasDeserializer deser2;
+ ContentHandler deserHandler2;
+
+ {
+ StringArray stringArray = new StringArray(jcas, 0);
+
+
+ AnnotationFS fsRef = cas.createAnnotation(refType, 0, 0);
+ fsRef.setFeatureValue(ref_StringArray, stringArray);
+ cas.addFsToIndexes(fsRef); // gets serialized in=place
+
+ xml = serialize(cas, null);
+
+ // deserialize into another CAS
+ fact = SAXParserFactory.newInstance();
+ parser = fact.newSAXParser();
+ xmlReader = parser.getXMLReader();
+
+ deser2 = new XmiCasDeserializer(cas2.getTypeSystem());
+ deserHandler2 = deser2.getXmiCasHandler(cas2);
+ xmlReader.setContentHandler(deserHandler2);
+ xmlReader.parse(new InputSource(new StringReader(xml)));
+
+ CasComparer.assertEquals(cas, cas2);
+ AnnotationFS fs2 = cas2.getAnnotationIndex(refType).iterator().get();
+ StringArrayFS fsa2 = (StringArrayFS) fs2.getFeatureValue(ref_StringArray);
+ assertEquals(0, fsa2.size());
+ }
+
+ // ------- repeat with lists in place of arrays --------------
+
+ cas.reset();
+
+ StringList stringlist0 = new EmptyStringList(jcas);
+
+// fsarray.addToIndexes(); // if added to indexes, forces serialization of FSArray as an element
+
+ AnnotationFS fsRef = cas.createAnnotation(refType, 0, 0);
+ fsRef.setFeatureValue(ref_StringList, stringlist0);
+ cas.addFsToIndexes(fsRef); // gets serialized in=place
+
+ xml = serialize(cas, null);
+
+ // deserialize into another CAS
+ parser = fact.newSAXParser();
+ xmlReader = parser.getXMLReader();
+
+ cas2.reset();
+
+ deser2 = new XmiCasDeserializer(cas2.getTypeSystem());
+ deserHandler2 = deser2.getXmiCasHandler(cas2);
+ xmlReader.setContentHandler(deserHandler2);
+ xmlReader.parse(new InputSource(new StringReader(xml)));
+
+ CasComparer.assertEquals(cas, cas2);
+ AnnotationFS fs2 = cas2.getAnnotationIndex(refType).iterator().get();
+ FeatureStructure fsl2 = fs2.getFeatureValue(ref_StringList);
+ assertTrue(fsl2.getType().getShortName().equals("EmptyStringList"));
+
+ }
+
+ /**
* test case for https://issues.apache.org/jira/browse/UIMA-5532
* @throws Exception
*/
@@ -165,6 +254,8 @@ public class XmiCasDeserializerTest exte
// ------- repeat with lists in place of arrays --------------
cas.reset();
+ fs1 = new TOP(jcas); //https://issues.apache.org/jira/browse/UIMA-5544
+ fs2 = new TOP(jcas);
FSList fslist2 = new EmptyFSList(jcas);
FSList fslist1 = new NonEmptyFSList(jcas, fs2, fslist2);
Added: uima/uimaj/trunk/uimaj-core/src/test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml?rev=1808149&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml (added)
+++ uima/uimaj/trunk/uimaj-core/src/test/resources/ExampleCas/testTypeSystem_small_withoutMultiRefs.xml Tue Sep 12 19:55:16 2017
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ -->
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <types>
+ <typeDescription>
+ <name>RefType</name>
+ <description/>
+ <supertypeName>uima.tcas.Annotation</supertypeName>
+ <features>
+ <featureDescription>
+ <name>ref_StringList</name>
+ <description/>
+ <rangeTypeName>uima.cas.StringList</rangeTypeName>
+ </featureDescription>
+ <featureDescription>
+ <name>ref_StringArray</name>
+ <description/>
+ <rangeTypeName>uima.cas.StringArray</rangeTypeName>
+ </featureDescription>
+ <featureDescription>
+ <name>ref</name>
+ <description/>
+ <rangeTypeName>uima.cas.TOP</rangeTypeName>
+ </featureDescription>
+
+ </features>
+ </typeDescription>
+ </types>
+</typeSystemDescription>