org.apache.uima.jcas.cas.ShortArray Java Examples
The following examples show how to use
org.apache.uima.jcas.cas.ShortArray.
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: CASImpl.java From uima-uimaj with Apache License 2.0 | 6 votes |
public TOP createArray(TypeImpl array_type, int arrayLength) { TypeImpl_array tia = (TypeImpl_array) array_type; TypeImpl componentType = tia.getComponentType(); if (componentType.isPrimitive()) { checkArrayPreconditions(arrayLength); switch (componentType.getCode()) { case intTypeCode: return new IntegerArray(array_type, this, arrayLength); case floatTypeCode: return new FloatArray(array_type, this, arrayLength); case booleanTypeCode: return new BooleanArray(array_type, this, arrayLength); case byteTypeCode: return new ByteArray(array_type, this, arrayLength); case shortTypeCode: return new ShortArray(array_type, this, arrayLength); case longTypeCode: return new LongArray(array_type, this, arrayLength); case doubleTypeCode: return new DoubleArray(array_type, this, arrayLength); case stringTypeCode: return new StringArray(array_type, this, arrayLength); default: throw Misc.internalError(); } } // return (TOP) createArrayFS(/* array_type, */ arrayLength); // for backwards compat w/ v2, don't create typed arrays if (IS_DISABLE_SUBTYPE_FSARRAY_CREATION) { return (TOP) createArrayFS(arrayLength); } else { return (TOP) createArrayFS(array_type, arrayLength); } }
Example #2
Source File: NewFeatureUtils.java From baleen with Apache License 2.0 | 5 votes |
private static ShortArray getShortArray(JCas jCas, Collection<?> list) { final ShortArray a = new ShortArray(jCas, list.size()); int i = 0; for (final Object s : list) { a.set(i++, ((Number) s).shortValue()); } return a; }
Example #3
Source File: FeatureStructureImplC.java From uima-uimaj with Apache License 2.0 | 5 votes |
private boolean isOkArray(TypeImpl range, Object v) { if (v == null) { return true; } final int rangeTypeCode = range.getCode(); /* The assignment is stricter than the Java rules - must match */ switch (rangeTypeCode) { case TypeSystemConstants.booleanArrayTypeCode: return v instanceof BooleanArray; case TypeSystemConstants.byteArrayTypeCode: return v instanceof ByteArray; case TypeSystemConstants.shortArrayTypeCode: return v instanceof ShortArray; case TypeSystemConstants.intArrayTypeCode: return v instanceof IntegerArray; case TypeSystemConstants.floatArrayTypeCode: return v instanceof FloatArray; case TypeSystemConstants.longArrayTypeCode: return v instanceof LongArray; case TypeSystemConstants.doubleArrayTypeCode: return v instanceof DoubleArray; case TypeSystemConstants.stringArrayTypeCode: return v instanceof StringArray; // case TypeSystemConstants.javaObjectArrayTypeCode: // return v instanceof JavaObjectArray; case TypeSystemConstants.fsArrayTypeCode: return v instanceof FSArray; } // it is possible that the array has a special type code corresponding to a type "someUserType"[] // meaning an array of some user type. UIMA implements these as instances of FSArray (I think) if (!(v instanceof FSArray)) { return false; } return true; }
Example #4
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public ShortArray emptyShortArray() { if (null == svd.emptyShortArray) { svd.emptyShortArray = new ShortArray(this.getJCas(), 0); } return svd.emptyShortArray; }
Example #5
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 4 votes |
public static ShortArray createShortArray(JCas aJCas, Collection<Short> aCollection) { return fillArray(new ShortArray(aJCas, aCollection.size()), aCollection); }
Example #6
Source File: CasToInlineXmlTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testCasToInlineXml() throws Exception { // Jira https://issues.apache.org/jira/browse/UIMA-2406 File typeSystemFile1 = JUnitExtension.getFile("ExampleCas/testTypeSystem_arrays.xml"); File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes_arrays.xml"); TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile1)); FsIndexDescription[] indexes = UIMAFramework.getXMLParser().parseFsIndexCollection(new XMLInputSource(indexesFile)) .getFsIndexes(); CAS srcCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); JCas jcas = srcCas.getJCas(); jcas.setDocumentText("1 2 3 4 5 6 7 8 9"); OfShorts f = new OfShorts(jcas); ShortArray a = new ShortArray(jcas, 3); a.set(0, (short)0); a.set(1, (short)1); a.set(2, (short)2); f.setF1Shorts(a); f.addToIndexes(); OfStrings ss = new OfStrings(jcas); StringArray sa = new StringArray(jcas, 3); sa.set(0, "0s"); sa.set(1, "1s"); sa.set(2, "2s"); ss.setF1Strings(sa); ss.addToIndexes(); CasToInlineXml c2x = new CasToInlineXml(); String result = c2x.generateXML(srcCas).trim(); System.out.println(result); int s = result.indexOf("<Document>"); result = result.substring(s); result = canonicalizeNl(result); // Java 9 xml formatter formats the text with a new line and indentations String expected = "<Document>\n" + IND+"<uima.tcas.DocumentAnnotation sofa=\"Sofa\" begin=\"0\" end=\"17\" language=\"x-unspecified\">\n" + IND+IND+"<org.apache.uima.testTypeSystem_arrays.OfStrings sofa=\"Sofa\" begin=\"0\" end=\"0\" f1Strings=\"[0s,1s,2s]\"/>\n" + IND+IND+"<org.apache.uima.testTypeSystem_arrays.OfShorts sofa=\"Sofa\" begin=\"0\" end=\"0\" f1Shorts=\"[0,1,2]\"/>" + (Misc.isJava9ea() ? "\n " : "") + "1 2 3 4 5 6 7 8 9" + (Misc.isJava9ea() ? "\n " : "") + "</uima.tcas.DocumentAnnotation>\n" + "</Document>"; for (int i = 0; i < result.length(); i++ ) { if (result.charAt(i) != expected.charAt(i)) { System.out.format("Unequal compare at position %,d, char code result = %d, expected = %d%n", i, (int)result.charAt(i), (int)expected.charAt(i)); break; } } boolean whitespaceFlag = XMLUnit.getIgnoreWhitespace(); XMLUnit.setIgnoreWhitespace(true); try { XMLAssert.assertXMLEqual(expected, result); } finally { XMLUnit.setIgnoreWhitespace(whitespaceFlag); } // assertEquals(expected, result.trim()); }
Example #7
Source File: CasComparer.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * * @param fs1 * @param fs2 * @param visited when called for sorting FSs, is sortCompareSeen(cleared); * when called for comparing for equality, holds FSs already compared in other views * @return */ private int compare1(TOP fs1, TOP fs2, Set<TOP> visited) { if (!isSortUse) { // only do null check for non- sort use if (fs1 == null && fs2 == null) { return 0; } if (fs1 == null) return chkEqual(-1, "fs1 was null and fs2 was not"); if (fs2 == null) return chkEqual(1, "fs2 was null and fs1 was not"); } boolean wasPresent1 = !visited.add(fs1); boolean wasPresent2 = !visited.add(fs2); if (wasPresent1 && wasPresent2) { return 0; // already checked and found equal } if (!wasPresent1 && !wasPresent2) { int r; TypeImpl t1, t2; if (0 != (r = compStr((t1 = (TypeImpl) fs1.getType()).getName(), (t2 = (TypeImpl) fs2.getType()).getName()))) { return chkEqual(r, "Types of FSs are different: Type1 = %s, Type2 = %s", t1, t2); } // types are the same if (CAS.TYPE_NAME_SOFA.equals(t1.getName())) { if (isSortUse) { return Integer.compare(((Sofa)fs1).getSofaNum(), ((Sofa)fs2).getSofaNum()); } return 0; // skip comparing sofa so this routine can be used for cas copier testing } if (t1.isArray()) { final int len1 = ((CommonArrayFS)fs1).size(); if (0 != (r = Integer.compare(len1, ((CommonArrayFS)fs2).size()))) { return r; } SlotKind kind = t1.getComponentSlotKind(); switch(kind) { case Slot_BooleanRef: return compareAllArrayElements(len1, i -> Boolean.compare(((BooleanArray )fs1).get(i), ((BooleanArray)fs2).get(i)), "Miscompare Boolean Arrays %n%s%n%s", fs1, fs2); case Slot_ByteRef: return compareAllArrayElements(len1, i -> Byte .compare(((ByteArray )fs1).get(i), ((ByteArray )fs2).get(i)), "Miscompare Byte Arrays %n%s%n%s" , fs1, fs2); case Slot_ShortRef: return compareAllArrayElements(len1, i -> Short .compare(((ShortArray )fs1).get(i), ((ShortArray )fs2).get(i)), "Miscompare Short Arrays %n%s%n%s" , fs1, fs2); case Slot_Int: return compareAllArrayElements (len1, i -> Integer.compare(((IntegerArray )fs1).get(i), ((IntegerArray)fs2).get(i)), "Miscompare Integer Arrays %n%s%n%s", fs1, fs2); case Slot_LongRef: return compareAllArrayElements(len1, i -> Long .compare(((LongArray )fs1).get(i), ((LongArray )fs2).get(i)), "Miscompare Long Arrays %n%s%n%s", fs1, fs2); case Slot_Float: return compareAllArrayElements (len1, i -> Integer.compare(Float.floatToRawIntBits (((FloatArray )fs1).get(i)), Float.floatToRawIntBits (((FloatArray )fs2).get(i))), "Miscompare Float Arrays %n%s%n%s", fs1, fs2); case Slot_DoubleRef: return compareAllArrayElements(len1, i -> Long .compare(Double.doubleToRawLongBits(((DoubleArray)fs1).get(i)), Double.doubleToRawLongBits(((DoubleArray)fs2).get(i))), "Miscompare Double Arrays %n%s%n%s", fs1, fs2); case Slot_HeapRef: return compareAllArrayElements(len1, i -> compare1((TOP)((FSArray<?> )fs1).get(i), (TOP)((FSArray<?> )fs2).get(i), visited), "Miscompare FS Arrays %n%s%n%s", fs1, fs2); case Slot_StrRef: return compareAllArrayElements(len1, i -> Misc.compareStrings(((StringArray )fs1).get(i), ((StringArray )fs2).get(i)), "Miscompare String Arrays %n%s%n%s", fs1, fs2); default: Misc.internalError(); return 0; // only to avoid a compile error } } ts = fs1.getCAS().getTypeSystem(); return compareFeatures(fs1, fs2, t1.getFeatureImpls(), t2.getFeatureImpls(), visited); } // getting here: one was already traversed, the other not. Possible use case: // fs1 is a list with a loop; fs2 is a list without a loop // arbitrarily return the one with a loop first if (fs1 instanceof EmptyList) { return 0; // allow different or shared EmptyList instances to compare equal // because some deserializers or user code can create them as shared or not } if (wasPresent1) { return chkEqual(-1, "First element had a ref loop %s%n, second didn't so far %s", fs1, fs2); } return chkEqual(-1, "Second element had a ref loop %s%n, first didn't so far %s", fs2, fs1); }
Example #8
Source File: CAS.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @return a lazily created shared (for this CAS) 0-length array */ default ShortArray emptyShortArray() { return ((CASImpl)getLowLevelCAS()).emptyShortArray(); }
Example #9
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
@Override public void ll_setShortArrayValue(int fsRef, int position, short value) { ((ShortArray) getFsFromId_checked(fsRef)).set(position, value); }
Example #10
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
@Override public short ll_getShortArrayValue(int fsRef, int position) { return ((ShortArray) getFsFromId_checked(fsRef)).get(position); }
Example #11
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
@Override public ShortArrayFS createShortArrayFS(int length) throws CASRuntimeException { checkArrayPreconditions(length); return new ShortArray(this.getJCas(), length); }
Example #12
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 4 votes |
public static ShortArray fillArray(ShortArray aArray, short... aValues) { return (ShortArray) fillArrayFS(aArray, aValues); }
Example #13
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 4 votes |
public static ShortArray fillArray(ShortArray aArray, Iterable<Short> aValues) { return (ShortArray) fillArrayFS(aArray, aValues); }
Example #14
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 4 votes |
public static ShortArray createShortArray(JCas aJCas, short... aArray) { return fillArray(new ShortArray(aJCas, aArray.length), aArray); }
Example #15
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed getter for aArrayMrShort - gets an indexed value - * @generated * @param i index in the array to get * @return value of the element at index i */ public short getAArrayMrShort(int i) { return ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrShort)))).get(i);}
Example #16
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** setter for aArrayMrShort - sets * @generated * @param v value to set into the feature */ public void setAArrayMrShort(ShortArray v) { _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aArrayMrShort), v); }
Example #17
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** getter for aArrayMrShort - gets * @generated * @return value of the feature */ public ShortArray getAArrayMrShort() { return (ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrShort)));}
Example #18
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed setter for aArrayShort - sets an indexed value - * @generated * @param i index in the array to set * @param v value to set into the array */ public void setAArrayShort(int i, short v) { ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayShort)))).set(i, v); }
Example #19
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed setter for aArrayMrShort - sets an indexed value - * @generated * @param i index in the array to set * @param v value to set into the array */ public void setAArrayMrShort(int i, short v) { ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrShort)))).set(i, v); }
Example #20
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed getter for aArrayShort - gets an indexed value - * @generated * @param i index in the array to get * @return value of the element at index i */ public short getAArrayShort(int i) { return ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayShort)))).get(i);}
Example #21
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** setter for aArrayShort - sets * @generated * @param v value to set into the feature */ public void setAArrayShort(ShortArray v) { _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aArrayShort), v); }
Example #22
Source File: AllTypes.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** getter for aArrayShort - gets * @generated * @return value of the feature */ public ShortArray getAArrayShort() { return (ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayShort)));}
Example #23
Source File: OfShorts.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed setter for f1Shorts - sets an indexed value - * @generated * @param i index in the array to set * @param v value to set into the array */ public void setF1Shorts(int i, short v) { ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_f1Shorts)))).set(i, v); }
Example #24
Source File: OfShorts.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** indexed getter for f1Shorts - gets an indexed value - * @generated * @param i index in the array to get * @return value of the element at index i */ public short getF1Shorts(int i) { return ((ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_f1Shorts)))).get(i);}
Example #25
Source File: OfShorts.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** setter for f1Shorts - sets * @generated * @param v value to set into the feature */ public void setF1Shorts(ShortArray v) { _setFeatureValueNcWj(wrapGetIntCatchException(_FH_f1Shorts), v); }
Example #26
Source File: OfShorts.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** getter for f1Shorts - gets * @generated * @return value of the feature */ public ShortArray getF1Shorts() { return (ShortArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_f1Shorts)));}
Example #27
Source File: JCas.java From uima-uimaj with Apache License 2.0 | 2 votes |
/** * Retrieve a lazily-created constant from the cas which holds a 0-length instance. * Since this can be a common value, we * avoid creating multiple copies of it. All uses can use the same value because it is not * updatable (it has no subfields). This is initialized lazily on first reference, and reset when * the CAS is reset. * @return 0-length instance of a ShortArray */ default ShortArray emptyShortArray() { return this.getCas().emptyShortArray(); }