Java Code Examples for org.apache.uima.cas.FeatureStructure#setFeatureValue()
The following examples show how to use
org.apache.uima.cas.FeatureStructure#setFeatureValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebannoTsv3Reader.java From webanno with Apache License 2.0 | 6 votes |
/** * The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain * number and link number references, sorted in an ascending order <br> * Iterate over each chain number and link number references and construct the chain. */ private void addChainAnnotations(JCas aJCas) { for (Type linkType : chainAnnosPerTyep.keySet()) { for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) { Type chainType = aJCas.getCas().getTypeSystem().getType( linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN); Feature firstF = chainType.getFeatureByBaseName(FIRST); Feature nextF = linkType.getFeatureByBaseName(NEXT); FeatureStructure chain = aJCas.getCas().createFS(chainType); aJCas.addFsToIndexes(chain); AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1); AnnotationFS linkFs = firstFs; chain.setFeatureValue(firstF, firstFs); for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) { linkFs.setFeatureValue(nextF, chainAnnosPerTyep.get(linkType).get(chainNo).get(i)); linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i); } } } }
Example 2
Source File: FSUtil.java From uima-uimafit with Apache License 2.0 | 6 votes |
public static void setFeature(FeatureStructure aFS, String aFeature, float... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setFloatValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else if (feat.getRange().isArray()) { aFS.setFeatureValue(feat, createFloatArrayFS(aFS.getCAS(), aValue)); } else { aFS.setFeatureValue(feat, createFloatList(aFS.getCAS(), aValue)); } }
Example 3
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testDeltaWithRefsBelow() { lfs.clear(); loadCas(lfs); setupCas2ForDeltaSerialization(); FeatureStructure fs = createFS(cas, akof); if (includeUid) fs.setIntValue(akofUid, aint.getAndAdd(1)); fs.setFeatureValue(akofFs, lfs2.get(0)); ArrayFS<FeatureStructure> fsafs = createArrayFS(cas, 4); fsafs.set(1, lfs2.get(1)); fsafs.set(2, lfs2.get(2)); fsafs.set(3, lfs2.get(3)); fs.setFeatureValue(akofAfs, fsafs); cas = cas1; verifyDelta(marker, "DeltaWithRefsBelow"); }
Example 4
Source File: FSUtil.java From uima-uimafit with Apache License 2.0 | 6 votes |
public static void setFeature(FeatureStructure aFS, String aFeature, int... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setIntValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else if (feat.getRange().isArray()) { aFS.setFeatureValue(feat, createIntArrayFS(aFS.getCAS(), aValue)); } else { aFS.setFeatureValue(feat, createIntegerList(aFS.getCAS(), aValue)); } }
Example 5
Source File: StringArrayTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testStringArrayNullValue() throws Exception{ String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR + CASTestSetup.LEMMA_LIST_FEAT; final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName); assertTrue(lemmaList != null); StringArrayFS casArray = this.cas.createStringArrayFS(3); ((CASImpl)(casArray.getCAS())).setId2FSsMaybeUnconditionally(casArray); casArray.set(0, "1"); casArray.set(1, null); casArray.set(2, "3"); FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE)); assertTrue(token.getFeatureValue(lemmaList) == null); token.setFeatureValue(lemmaList, casArray); this.cas.addFsToIndexes(token); assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1"); assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(1) == null); LowLevelCAS llc = casArray.getCAS().getLowLevelCAS(); assertTrue(llc.ll_getStringArrayValue(llc.ll_getFSRef(casArray), 1) == null); }
Example 6
Source File: WebAnnoCasUtil.java From webanno with Apache License 2.0 | 5 votes |
private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) { Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName()); Feature roleFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeRoleFeatureName()); Feature targetFeat = linkType.getFeatureByBaseName(aFeature .getLinkTypeTargetFeatureName()); // Create all the links // FIXME: actually we could re-use existing link link feature structures List<FeatureStructure> linkFSes = new ArrayList<>(); if (aValue != null) { // remove duplicate links Set<LinkWithRoleModel> links = new HashSet<>(aValue); for (LinkWithRoleModel e : links) { // Skip links that have been added in the UI but where the target has not // yet been // set if (e.targetAddr == -1) { continue; } FeatureStructure link = aFS.getCAS().createFS(linkType); link.setStringValue(roleFeat, e.role); link.setFeatureValue(targetFeat, selectFsByAddr(aFS.getCAS(), e.targetAddr)); linkFSes.add(link); } } setLinkFeatureValue(aFS, feature, linkFSes); }
Example 7
Source File: CurationTestUtils.java From webanno with Apache License 2.0 | 5 votes |
public static FeatureStructure makeLinkFS(JCas aCas, String aSlotLabel, int aTargetBegin, int aTargetEnd) { Token token1 = new Token(aCas, aTargetBegin, aTargetEnd); token1.addToIndexes(); Type linkType = aCas.getTypeSystem().getType(LINK_TYPE); FeatureStructure linkA1 = aCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), token1); aCas.getCas().addFsToIndexes(linkA1); return linkA1; }
Example 8
Source File: AgreementTestUtils.java From webanno with Apache License 2.0 | 5 votes |
public static FeatureStructure makeLinkFS(JCas aCas, String aSlotLabel, int aTargetBegin, int aTargetEnd) { Token token1 = new Token(aCas, aTargetBegin, aTargetEnd); token1.addToIndexes(); Type linkType = aCas.getTypeSystem().getType(LINK_TYPE); FeatureStructure linkA1 = aCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), token1); aCas.getCas().addFsToIndexes(linkA1); return linkA1; }
Example 9
Source File: FeatureStructureTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testToString() { FeatureStructure listFS = this.cas.createFS(this.neListType); listFS.setFeatureValue(this.tlFeature, listFS); System.out.println("toString for fslist, tail -> node, head is null"); System.out.println(listFS.toString()); FeatureStructure value = this.cas.createFS(this.tokenType); FeatureStructure newList = this.cas.createFS(this.neListType); newList.setFeatureValue(this.tlFeature, listFS); newList.setFeatureValue(this.hdFeature, value); listFS.setFeatureValue(this.hdFeature, value); System.out.println("toString for fslist, tail is prev, prev's head: new token, head is same as rpev's head"); System.out.println(newList.toString()); }
Example 10
Source File: FeatureStructureTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testErrorDerefDifferentCAS() { CAS cas2 = CASInitializer.initCas(new CASTestSetup(), null); Type tokenType1 = this.ts.getType(CASTestSetup.TOKEN_TYPE); Feature tokenTypeFeature = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE + ":" + CASTestSetup.TOKEN_TYPE_FEAT); FeatureStructure fs1 = cas2.createFS(tokenType1); FeatureStructure fs = cas.createFS(tokenType1); boolean caught = false; try { fs.setFeatureValue(tokenTypeFeature, fs1); } catch (Exception e) { assertTrue( e instanceof CASRuntimeException); caught = true; } assertTrue(caught); }
Example 11
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static <T extends FeatureStructure> T createFloatList(CAS aCas, Collection<Float> aValues) { if (aValues == null) { return null; } TypeSystem ts = aCas.getTypeSystem(); Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_FLOAT_LIST); if (aValues.size() == 0) { return aCas.createFS(emptyType); } Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST); Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD); Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL); FeatureStructure head = aCas.createFS(nonEmptyType); FeatureStructure list = head; Iterator<Float> i = aValues.iterator(); while (i.hasNext()) { head.setFloatValue(headFeature, i.next()); if (i.hasNext()) { FeatureStructure tail = aCas.createFS(nonEmptyType); head.setFeatureValue(tailFeature, tail); head = tail; } else { head.setFeatureValue(tailFeature, aCas.createFS(emptyType)); } } return (T) list; }
Example 12
Source File: FeatureStructureTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testSetArrayValuedFeature() { FeatureStructure testFS = this.cas.createFS(this.arrayFsWithSubtypeType); assertTrue(testFS.getFeatureValue(this.arrayFsWithSubtypeTypeFeat) == null); ArrayFS arrayFS = this.cas.createArrayFS(1); testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, arrayFS); assertTrue(true); boolean caughtExc = false; try { testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, testFS); } catch (CASRuntimeException e) { caughtExc = true; assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_RANGE)); } assertTrue(caughtExc); }
Example 13
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static <T extends FeatureStructure> T createIntegerList(CAS aCas, Collection<Integer> aValues) { if (aValues == null) { return null; } TypeSystem ts = aCas.getTypeSystem(); Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST); if (aValues.size() == 0) { return aCas.createFS(emptyType); } Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST); Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD); Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL); FeatureStructure head = aCas.createFS(nonEmptyType); FeatureStructure list = head; Iterator<Integer> i = aValues.iterator(); while (i.hasNext()) { head.setIntValue(headFeature, i.next()); if (i.hasNext()) { FeatureStructure tail = aCas.createFS(nonEmptyType); head.setFeatureValue(tailFeature, tail); head = tail; } else { head.setFeatureValue(tailFeature, aCas.createFS(emptyType)); } } return (T) list; }
Example 14
Source File: FSUtil.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static void setFeature(FeatureStructure aFS, String aFeature, boolean... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setBooleanValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else { aFS.setFeatureValue(feat, createBooleanArrayFS(aFS.getCAS(), aValue)); } }
Example 15
Source File: FSUtil.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static void setFeature(FeatureStructure aFS, String aFeature, double... aValue) { Feature feat = getMandatoryFeature(aFS, aFeature); if (feat.getRange().isPrimitive()) { requireSingleValue(feat, aValue); aFS.setDoubleValue(feat, aValue[0]); } else if (aValue == null) { aFS.setFeatureValue(feat, null); } else { aFS.setFeatureValue(feat, createDoubleArrayFS(aFS.getCAS(), aValue)); } }
Example 16
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void createFloatA(FeatureStructure fs, float x) { FloatArrayFS fafs = createFloatArrayFS(cas, 6); fafs.set(0, Float.MAX_VALUE - x); // fafs.set(1, Float.MIN_NORMAL + x); fafs.set(2, Float.MIN_VALUE + x); fafs.set(3, Float.NaN); fafs.set(4, Float.NEGATIVE_INFINITY); fafs.set(5, Float.POSITIVE_INFINITY); fs.setFeatureValue(akofAfloat, fafs); }
Example 17
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testOutOfTypeSystemListElement() throws Exception { //add to type system an annotation type that has an FSList feature TypeDescription testAnnotTypeDesc = typeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation"); testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList"); //populate a CAS with such an list CAS cas = CasCreationUtils.createCas(typeSystem, null, null); Type testAnnotType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation"); Type orgType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Organization"); AnnotationFS orgAnnot1 = cas.createAnnotation(orgType, 0, 10); cas.addFsToIndexes(orgAnnot1); AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20); cas.addFsToIndexes(orgAnnot2); AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20); cas.addFsToIndexes(testAnnot); Type nonEmptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST); Type emptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST); Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head"); Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail"); FeatureStructure emptyNode = cas.createFS(emptyFsListType); FeatureStructure secondNode = cas.createFS(nonEmptyFsListType); secondNode.setFeatureValue(headFeat, orgAnnot2); secondNode.setFeatureValue(tailFeat, emptyNode); FeatureStructure firstNode = cas.createFS(nonEmptyFsListType); firstNode.setFeatureValue(headFeat, orgAnnot1); firstNode.setFeatureValue(tailFeat, secondNode); Feature listFeat = testAnnotType.getFeatureByBaseName("listFeat"); testAnnot.setFeatureValue(listFeat, firstNode); //serialize to XMI String xmiStr = serialize(cas, null); // System.out.println(xmiStr); //deserialize into a CAS that's missing the Organization type File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml"); TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(partialTypeSystemFile)); testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation"); testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList"); CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null); XmiSerializationSharedData sharedData = new XmiSerializationSharedData(); deserialize(xmiStr, partialTsCas, sharedData, true, -1); //check out of type system data Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation"); FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get(); Feature listFeat2 = testAnnotType2.getFeatureByBaseName("listFeat"); FeatureStructure listFs = testAnnot2.getFeatureValue(listFeat2); List ootsElems = sharedData.getOutOfTypeSystemElements(); assertEquals(2, ootsElems.size()); OotsElementData oed = sharedData.getOutOfTypeSystemFeatures((TOP) listFs); XmlAttribute attr = oed.attributes.get(0); assertNotNull(attr); assertEquals(CAS.FEATURE_BASE_NAME_HEAD, attr.name); assertEquals(attr.value, ((OotsElementData)ootsElems.get(0)).xmiId); //reserialize along with out of type system data String xmiStr2 = serialize(partialTsCas, sharedData); // System.out.println(xmiStr2); //deserialize into a new CAS and compare CAS cas2 = CasCreationUtils.createCas(typeSystem, null, null); deserialize(xmiStr2, cas2, null, false, -1); CasComparer.assertEquals(cas, cas2); }
Example 18
Source File: SerializationReinitTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** Test basic blob serialization */ public void testBlob() throws Exception { /* * Test that FS, indexes and strings work after repeated blob serialization * For each iteration, add two new FS, serialize and test all created so * The first FS sets the string feature using standard API => goes into stringlist * The second FS sets the string feature using lowlevel API => goes into stringheap * * Throw in tests of the byte, short and long heaps as well * */ String testString = "testString"; cas.reset(); LowLevelCAS ll_cas = cas.getLowLevelCAS(); FSIndexRepository ir = cas.getIndexRepository(); int ll_strfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theStringFeature); int ll_bytefeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theByteFeature); int ll_shortfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theShortFeature); int ll_bytearrayfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theByteArrayFeature); int ll_shortarrayfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theShortArrayFeature); int ll_longfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theLongFeature); for (int cycle = 0; cycle < 10; cycle +=2 ) { FeatureStructure newFS1 = cas.createFS(theTypeType); newFS1.setIntValue(startFeature, cycle); newFS1.setIntValue(endFeature, cycle+1); // set string using normal string feature create newFS1.setStringValue(theStringFeature, testString); newFS1.setByteValue(theByteFeature, (byte)cycle); newFS1.setShortValue(theShortFeature, (short)cycle); newFS1.setLongValue(theLongFeature, (long)cycle); ByteArrayFS newBA1 = cas.createByteArrayFS(1); ShortArrayFS newSA1 = cas.createShortArrayFS(1); newBA1.set(0, (byte)cycle); newSA1.set(0, (short)cycle); newFS1.setFeatureValue(theByteArrayFeature, newBA1); newFS1.setFeatureValue(theShortArrayFeature, newSA1); ir.addFS(newFS1); FeatureStructure newFS2 = cas.createFS(theTypeType); ByteArrayFS newBA2 = cas.createByteArrayFS(1); ShortArrayFS newSA2 = cas.createShortArrayFS(1); newFS2.setIntValue(startFeature, cycle+1); newFS2.setIntValue(endFeature, cycle+2); ir.addFS(newFS2); CASImpl ci = (CASImpl) cas; ci.setId2FSsMaybeUnconditionally(newFS2, newBA2, newSA2); // set string using lowlevel string create API final int llfs2 = ll_cas.ll_getFSRef(newFS2); final int llba2 = ll_cas.ll_getFSRef(newBA2); final int llsa2 = ll_cas.ll_getFSRef(newSA2); ll_cas.ll_setCharBufferValue(llfs2, ll_strfeatcode, testString.toCharArray(), 0, testString.length()); ll_cas.ll_setByteValue(llfs2, ll_bytefeatcode, (byte)(cycle+1)); ll_cas.ll_setShortValue(llfs2, ll_shortfeatcode, (short)(cycle+1)); ll_cas.ll_setLongValue(llfs2, ll_longfeatcode, (long)(cycle+1)); ll_cas.ll_setByteArrayValue(llba2, 0, (byte)(cycle+1)); ll_cas.ll_setShortArrayValue(llsa2, 0, (short)(cycle+1)); newFS2.setFeatureValue(theByteArrayFeature, newBA2); newFS2.setFeatureValue(theShortArrayFeature, newSA2); ir.addFS(newFS2); ByteArrayOutputStream fos = new ByteArrayOutputStream(); Serialization.serializeCAS(cas, fos); cas.reset(); ByteArrayInputStream fis = new ByteArrayInputStream(fos.toByteArray()); Serialization.deserializeCAS(cas, fis); FSIndex<AnnotationFS> idx = cas.getAnnotationIndex(theTypeType); FSIterator<AnnotationFS> iter = idx.iterator(); for (int tc = 0; tc < cycle + 1; tc++) { FeatureStructure testFS = iter.get(); iter.moveToNext(); assertTrue(tc == testFS.getIntValue(startFeature)); assertTrue(testString.equals(testFS.getStringValue(theStringFeature))); assertTrue(tc == testFS.getByteValue(theByteFeature)); assertTrue(tc == testFS.getShortValue(theShortFeature)); assertTrue(tc == testFS.getLongValue(theLongFeature)); ByteArrayFS ba = (ByteArrayFS)testFS.getFeatureValue(theByteArrayFeature); assertTrue(tc == ba.get(0)); ShortArrayFS sa = (ShortArrayFS)testFS.getFeatureValue(theShortArrayFeature); assertTrue(tc == sa.get(0)); } } }
Example 19
Source File: SerializationReinitTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaBinaryShortLongArrayMods() throws Exception { CASImpl cas2 = (CASImpl) initCAS(); CASImpl cas3 = (CASImpl) initCAS(); // create short array and long array FeatureStructure newFS1 = cas.createFS(theTypeType); ByteArrayFS newBA1 = cas.createByteArrayFS(1); ShortArrayFS newSA1 = cas.createShortArrayFS(1); LongArrayFS newLA1 = cas.createLongArrayFS(1); newBA1.set(0, (byte)1); newSA1.set(0, (short)2); newLA1.set(0, (long)4); newFS1.setFeatureValue(theByteArrayFeature, newBA1); newFS1.setFeatureValue(theShortArrayFeature, newSA1); newFS1.setFeatureValue(theLongArrayFeature, newLA1); cas.getIndexRepository().addFS(newFS1); //serialize binary, non compressed, not delta ByteArrayOutputStream fos = new ByteArrayOutputStream(); Serialization.serializeCAS(cas, fos); //deserialize into cas2 ByteArrayInputStream fis = new ByteArrayInputStream(fos.toByteArray()); Serialization.deserializeCAS(cas2, fis); CasComparer.assertEquals(cas, cas2); //======================================================================= //create Marker, add/modify fs and serialize in delta xmi format. Marker marker = cas2.createMarker(); // modify a value in the int arrays Iterator<AnnotationFS> typeIterator = cas2.getAnnotationIndex(theTypeType).iterator(); assertTrue(typeIterator.hasNext()); FeatureStructure fsWithArrays = typeIterator.next(); ((ByteArrayFS)fsWithArrays.getFeatureValue(theByteArrayFeature)).set(0, (byte) 11); ((ShortArrayFS)fsWithArrays.getFeatureValue(theShortArrayFeature)).set(0, (short) 22); ((LongArrayFS)fsWithArrays.getFeatureValue(theLongArrayFeature)).set(0, (long) 44); // serialize cas2 in delta format ByteArrayOutputStream fosDelta = new ByteArrayOutputStream(); Serialization.serializeCAS(cas2, fosDelta, marker); //====================================================================== //deserialize delta binary into cas1 ByteArrayInputStream fisDelta = new ByteArrayInputStream(fosDelta.toByteArray()); Serialization.deserializeCAS(cas, fisDelta); //====================================================================== //serialize complete cas and deserialize into cas3 and compare with cas1. ByteArrayOutputStream fosFull = new ByteArrayOutputStream(); Serialization.serializeCAS(cas2, fosFull); ByteArrayInputStream fisFull = new ByteArrayInputStream(fosFull.toByteArray()); Serialization.deserializeCAS(cas3, fisFull); CasComparer.assertEquals(cas, cas3); }
Example 20
Source File: WebAnnoCasUtil.java From webanno with Apache License 2.0 | 3 votes |
/** * Set a feature value. * * @param aFS * the feature structure. * @param aFeatureName * the feature within the annotation whose value to set. * @param aValue * the feature value. */ public static void setFeatureFS(FeatureStructure aFS, String aFeatureName, FeatureStructure aValue) { Feature labelFeature = aFS.getType().getFeatureByBaseName(aFeatureName); aFS.setFeatureValue(labelFeature, aValue); }