Java Code Examples for org.apache.uima.cas.StringArrayFS

The following examples show how to use org.apache.uima.cas.StringArrayFS. These examples are extracted from open source projects. 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 Project: biomedicus   Source File: FsCopiers.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Convenience constructor which only needs the callback for encountered feature structures.
 *
 * @param featureStructureEncounteredCallback callback for encountered feature structures
 */
FsCopiers(UnaryOperator<FeatureStructure> featureStructureEncounteredCallback,
    FeatureCopiers featureCopiers) {
  this.featureCopiers = featureCopiers;
  this.featureStructureEncounteredCallback = featureStructureEncounteredCallback;

  fsCopiers = new HashMap<>();
  fsCopiers.put(CAS.TYPE_NAME_BOOLEAN_ARRAY, copyArray(BooleanArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_BYTE_ARRAY, copyArray(ByteArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_DOUBLE_ARRAY, copyArray(DoubleArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FLOAT_ARRAY, copyArray(FloatArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FS_ARRAY, this::copyFsArray);
  fsCopiers.put(CAS.TYPE_NAME_LONG_ARRAY, copyArray(LongArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_INTEGER_ARRAY, copyArray(IntArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_SHORT_ARRAY, copyArray(ShortArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_STRING_ARRAY, copyArray(StringArrayFS.class));
}
 
Example 2
Source Project: biomedicus   Source File: FsCopiers.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Convenience constructor which only needs the callback for encountered feature structures.
 *
 * @param featureStructureEncounteredCallback callback for encountered feature structures
 */
FsCopiers(UnaryOperator<FeatureStructure> featureStructureEncounteredCallback) {
  this.featureCopiers = new FeatureCopiers(featureStructureEncounteredCallback);
  this.featureStructureEncounteredCallback = featureStructureEncounteredCallback;

  fsCopiers = new HashMap<>();
  fsCopiers.put(CAS.TYPE_NAME_BOOLEAN_ARRAY, copyArray(BooleanArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_BYTE_ARRAY, copyArray(ByteArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_DOUBLE_ARRAY, copyArray(DoubleArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FLOAT_ARRAY, copyArray(FloatArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FS_ARRAY, this::copyFsArray);
  fsCopiers.put(CAS.TYPE_NAME_LONG_ARRAY, copyArray(LongArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_INTEGER_ARRAY, copyArray(IntArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_SHORT_ARRAY, copyArray(ShortArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_STRING_ARRAY, copyArray(StringArrayFS.class));
}
 
Example 3
Source Project: uima-uimaj   Source File: XCASDeserializerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testStringArrayWithNullValues() throws Exception {
  CAS cas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
  StringArrayFS strArray = cas.createStringArrayFS(3);
  strArray.set(1, "value");
  cas.getIndexRepository().addFS(strArray);
  
  assertEquals(null, strArray.get(0));
  assertEquals("value", strArray.get(1));
  assertEquals(null, strArray.get(2));
  
  //serialize to XCAS and back
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  XCASSerializer.serialize(cas,baos);
  ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  XCASDeserializer.deserialize(bais, cas);

  //check
  Iterator iter = cas.getIndexRepository().getAllIndexedFS(cas.getTypeSystem().getType("uima.cas.StringArray"));
  StringArrayFS strArrayOut = (StringArrayFS)iter.next();
  assertEquals(null, strArrayOut.get(0));
  assertEquals("value", strArrayOut.get(1));
  assertEquals(null, strArrayOut.get(2));
}
 
Example 4
Source Project: uima-uimaj   Source File: SerDesTest6.java    License: Apache License 2.0 6 votes vote down vote up
public void testDeltaWithStrArrayMod() {
  TTypeSystem m = getTT(EqTwoTypes);
  remoteCas = setupCas(m);
  loadCas(casSrc, mSrc);
  ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
  MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();

  lfs = getIndexedFSs(remoteCas, m);

  FeatureStructure fs = lfs.get(10);
  StringArrayFS sfs = (StringArrayFS) maybeGetFeatureKind(fs, m, "Astring");
  if (sfs != null) {
    sfs.set(0, "change");
  }

  verifyDelta(marker, ri);
}
 
Example 5
Source Project: uima-uimaj   Source File: StringArrayTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testStringArrayValue() {
   String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
+ CASTestSetup.LEMMA_LIST_FEAT;
   final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
   assertTrue(lemmaList != null);
   String[] javaArray = { "1", "2", "3" };
   StringArrayFS casArray = this.cas.createStringArrayFS(3);
   casArray.copyFromArray(javaArray, 0, 0, 3);
   FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
   assertTrue(token.getFeatureValue(lemmaList) == null);
   token.setFeatureValue(lemmaList, casArray);
   assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
   String hello = "Hello.";
   casArray.set(0, hello);
   assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == hello);
 }
 
Example 6
Source Project: uima-uimaj   Source File: StringArrayTest.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: uima-uimafit   Source File: FSCollectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static StringArrayFS fillArrayFS(StringArrayFS aArrayFs, Iterable<String> aValues) {
  int i = 0;
  for (String fs : aValues) {
    aArrayFs.set(i, fs);
    i++;
  }
  return aArrayFs;
}
 
Example 8
Source Project: uima-uimaj   Source File: DebugNameValuePair.java    License: Apache License 2.0 5 votes vote down vote up
public String toString() {
  Object v = getValue();
  String className = v.getClass().getSimpleName();
  if (v instanceof StringArrayFS)
    v = className + "[" + ((StringArrayFS) v).size() + "]";
  else if (v instanceof FloatArrayFS)
    v = className + "[" + ((FloatArrayFS) v).size() + "]";
  else if (v instanceof IntArrayFS)
    v = className + "[" + ((IntArrayFS) v).size() + "]";
  else if (v instanceof ArrayFS)
    v = className + "[" + ((ArrayFS) v).size() + "]";
  return getName() + ": " + v;
}
 
Example 9
Source Project: uima-uimaj   Source File: SerDesTest4.java    License: Apache License 2.0 5 votes vote down vote up
/*******************************
 * Helper functions
 *******************************/

private void createStringA(FeatureStructure fs, String x) {
  StringArrayFS strafs = createStringArrayFS(cas, 5);
  strafs.set(3, null);
  strafs.set(2, "" + x);
  strafs.set(1, "abc" + x);
  strafs.set(0, "abc" + x);
  strafs.set(4, "def" + x);
  fs.setFeatureValue(akofAstring, strafs);
}
 
Example 10
Source Project: uima-uimaj   Source File: SerDesTest4.java    License: Apache License 2.0 5 votes vote down vote up
private StringArrayFS randomStringA(Random r) {
  int length = r.nextInt(2) + 1;
  StringArrayFS fs = createStringArrayFS(cas, length);
  for (int i = 0; i < length; i++) {
    fs.set(i, stringValues[r.nextInt(stringValues.length)]);
  }
  return fs;
}
 
Example 11
Source Project: uima-uimaj   Source File: SerDesTest6.java    License: Apache License 2.0 5 votes vote down vote up
public void testDeltaWithStringArrayMod() {
  // casSrc -> remoteCas,remoteCas updated, serialized back to srcCas
  for (int i = 0; i < 10; i++) {
    TTypeSystem m = getTT(EqTwoTypes);
    remoteCas = setupCas(m);
    loadCas(casSrc, mSrc);
    ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
    lfs = getIndexedFSs(remoteCas, m);
    FeatureStructure fs = lfs.get(10);
    StringArrayFS sa = (StringArrayFS) maybeGetFeatureKind(fs, m, "Astring");
    if (sa == null) { // could happen because features are randomly omitted
      System.out.println("    Astring feature omitted, retrying");
    } else if (sa.size() == 0) {
      System.out.println("    Astring feature array has 0 length, retrying");
    } else {
      sa.set(0, "change2");
      verifyDelta(marker, ri);
      break;
    }
    // setRandom();
    setUp();
    long seed = random.nextLong();
    random.setSeed(seed);
    System.out.println(" testDelta w/ String array mod random = " + seed + ", i = " + i);
  }
}
 
Example 12
Source Project: uima-uimaj   Source File: SerDesTest6.java    License: Apache License 2.0 5 votes vote down vote up
private void createStringA(CASImpl cas, TTypeSystem m, FeatureStructure fs, String x) {
  StringArrayFS strafs = cas.createStringArrayFS(5);
  strafs.set(3, null);
  strafs.set(2, "" + x);
  strafs.set(1, "abc" + x);
  strafs.set(0, "abc" + x);
  strafs.set(4, "def" + x);
  maybeSetFeatureKind(fs, m, "Astring", strafs);
}
 
Example 13
Source Project: uima-uimaj   Source File: SerDesTest6.java    License: Apache License 2.0 5 votes vote down vote up
private StringArrayFS randomStringA(CASImpl cas) {
  int length = random.nextInt(2) + 1;
  StringArrayFS fs = cas.createStringArrayFS(length);
  for (int i = 0; i < length; i++) {
    fs.set(i, stringValues[random.nextInt(stringValues.length)]);
  }
  return fs;
}
 
Example 14
Source Project: uima-uimaj   Source File: StringArrayTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testToArray() {
  // From CAS array to Java array.
  StringArrayFS array = this.cas.createStringArrayFS(3);
  String[] fsArray = array.toArray();
  for (int i = 0; i < 3; i++) {
    assertTrue(fsArray[i] == null);
  }
  array.set(0, "1");
  array.set(1, "2");
  array.set(2, "3");
  fsArray = array.toArray();
  assertTrue(fsArray.length == 3);
  assertTrue(fsArray[0].equals("1"));
  assertTrue(fsArray[1].equals("2"));
  assertTrue(fsArray[2].equals("3"));

  // From Java array to CAS array.
  array = this.cas.createStringArrayFS(3);
  assertTrue(array.get(0) == null);
  assertTrue(array.get(1) == null);
  assertTrue(array.get(2) == null);
  for (int i = 0; i < 3; i++) {
    array.set(i, fsArray[i]);
  }
  assertTrue(array.get(0).equals("1"));
  assertTrue(array.get(1).equals("2"));
  assertTrue(array.get(2).equals("3"));
  array.set(0, null);
  assertTrue(array.get(0) == null);
}
 
Example 15
Source Project: uima-uimaj   Source File: CasComparer.java    License: Apache License 2.0 5 votes vote down vote up
private ARRAY_TYPE getArrayType(CommonArrayFS c) {
  if (c instanceof ArrayFS) return ARRAY_TYPE.FS; 
  if (c instanceof StringArrayFS) return ARRAY_TYPE.STRING; 
  if (c instanceof BooleanArrayFS) return ARRAY_TYPE.BOOLEAN; 
  if (c instanceof ByteArrayFS) return ARRAY_TYPE.BYTE; 
  if (c instanceof ShortArrayFS) return ARRAY_TYPE.SHORT; 
  if (c instanceof IntArrayFS) return ARRAY_TYPE.INT; 
  if (c instanceof LongArrayFS) return ARRAY_TYPE.LONG; 
  if (c instanceof FloatArrayFS) return ARRAY_TYPE.FLOAT; 
  if (c instanceof DoubleArrayFS) return ARRAY_TYPE.DOUBLE;
  return null;
}
 
Example 16
Source Project: uima-uimafit   Source File: FSCollectionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public static StringArrayFS createStringArrayFS(CAS aCas, Collection<String> aCollection) {
  return fillArrayFS(aCas.createStringArrayFS(aCollection.size()), aCollection);
}
 
Example 17
Source Project: uima-uimafit   Source File: FSCollectionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public static StringArrayFS createStringArrayFS(CAS aCas, String... aArray) {
  return fillArrayFS(aCas.createStringArrayFS(aArray.length), aArray);
}
 
Example 18
Source Project: uima-uimafit   Source File: FSCollectionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public static StringArrayFS fillArrayFS(StringArrayFS aArrayFs, String... aValues) {
  aArrayFs.copyFromArray(aValues, 0, 0, aArrayFs.size());
  return aArrayFs;
}
 
Example 19
Source Project: uima-uimaj   Source File: CasAnnotationViewerTest.java    License: Apache License 2.0 4 votes vote down vote up
private void createExampleFS(CAS cas) throws Exception {
  // Set the document text
  cas.setDocumentText("this beer is good");

  // create an FS of exampleType and index it
  AnnotationFS fs = cas.createAnnotation(exampleType, 1, 5);
  cas.getIndexRepository().addFS(fs);

  // create Array FSs
  StringArrayFS strArrayFS = cas.createStringArrayFS(5);
  strArrayFS.set(0, "zzzzzz");
  strArrayFS.set(1, "yyyyyy");
  strArrayFS.set(2, "xxxxxx");
  strArrayFS.set(3, "wwwwww");
  strArrayFS.set(4, "vvvvvv");

  IntArrayFS intArrayFS = cas.createIntArrayFS(5);
  intArrayFS.set(0, Integer.MAX_VALUE);
  intArrayFS.set(1, Integer.MAX_VALUE - 1);
  intArrayFS.set(2, 42);
  intArrayFS.set(3, Integer.MIN_VALUE + 1);
  intArrayFS.set(4, Integer.MIN_VALUE);

  FloatArrayFS floatArrayFS = cas.createFloatArrayFS(5);
  floatArrayFS.set(0, Float.MAX_VALUE);
  floatArrayFS.set(1, (float) (Float.MAX_VALUE / 1000.0));
  floatArrayFS.set(2, (float) 42);
  floatArrayFS.set(3, (float) (Float.MIN_VALUE * 1000.0));
  floatArrayFS.set(4, Float.MIN_VALUE);

  ByteArrayFS byteArrayFS = cas.createByteArrayFS(5);
  byteArrayFS.set(0, (byte) 8);
  byteArrayFS.set(1, (byte) 16);
  byteArrayFS.set(2, (byte) 64);
  byteArrayFS.set(3, (byte) 128);
  byteArrayFS.set(4, (byte) 255);

  BooleanArrayFS boolArrayFS = cas.createBooleanArrayFS(8);
  boolean val = false;
  for (int i = 0; i < 8; i++) {
    boolArrayFS.set(i, val = !val);
  }

  ShortArrayFS shortArrayFS = cas.createShortArrayFS(5);
  shortArrayFS.set(0, Short.MAX_VALUE);
  shortArrayFS.set(1, (short) (Short.MAX_VALUE - 1));
  shortArrayFS.set(2, (short) (Short.MAX_VALUE - 2));
  shortArrayFS.set(3, (short) (Short.MAX_VALUE - 3));
  shortArrayFS.set(4, (short) (Short.MAX_VALUE - 4));

  LongArrayFS longArrayFS = cas.createLongArrayFS(5);
  longArrayFS.set(0, Long.MAX_VALUE);
  longArrayFS.set(1, Long.MAX_VALUE - 1);
  longArrayFS.set(2, Long.MAX_VALUE - 2);
  longArrayFS.set(3, Long.MAX_VALUE - 3);
  longArrayFS.set(4, Long.MAX_VALUE - 4);

  DoubleArrayFS doubleArrayFS = cas.createDoubleArrayFS(5);
  doubleArrayFS.set(0, Double.MAX_VALUE);
  doubleArrayFS.set(1, Double.MIN_VALUE);
  doubleArrayFS.set(2, Double.parseDouble("1.5555"));
  doubleArrayFS.set(3, Double.parseDouble("99.000000005"));
  doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444"));

  // set features of fs
  fs.setStringValue(stringFeature, "aaaaaaa");
  fs.setFloatValue(floatFeature, (float) 99.99);

  fs.setFeatureValue(intArrayFeature, intArrayFS);
  fs.setFeatureValue(floatArrayFeature, floatArrayFS);
  fs.setFeatureValue(stringArrayFeature, strArrayFS);

  // fs.setByteValue(byteFeature, Byte.MAX_VALUE);
  fs.setByteValue(byteFeature, (byte) 'z');
  fs.setFeatureValue(byteArrayFeature, byteArrayFS);
  fs.setBooleanValue(booleanFeature, true);
  fs.setFeatureValue(booleanArrayFeature, boolArrayFS);
  fs.setShortValue(shortFeature, Short.MIN_VALUE);
  fs.setFeatureValue(shortArrayFeature, shortArrayFS);
  fs.setLongValue(longFeature, Long.MIN_VALUE);
  fs.setFeatureValue(longArrayFeature, longArrayFS);
  fs.setDoubleValue(doubleFeature, Double.MAX_VALUE);
  fs.setFeatureValue(doubleArrayFeature, doubleArrayFS);

  cas.getIndexRepository().addFS(fs);
}
 
Example 20
Source Project: uima-uimaj   Source File: CASImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StringArrayFS createStringArrayFS(int length) {
  checkArrayPreconditions(length);
  return new StringArray(getTypeSystemImpl().stringArrayType, this, length);
}
 
Example 21
Source Project: uima-uimaj   Source File: DebugFSLogicalStructure.java    License: Apache License 2.0 4 votes vote down vote up
public static Object getDebugLogicalStructure_FeatureStructure(FeatureStructure fs) {

    if (fs instanceof StringArrayFS) {
      return ((StringArrayFS) fs).toArray();
    }
    if (fs instanceof FloatArrayFS) {
      return ((FloatArrayFS) fs).toArray();
    }
    if (fs instanceof IntArrayFS) {
      return ((IntArrayFS) fs).toArray();
    }
    if (fs instanceof ArrayFS) {
      return ((ArrayFS) fs).toArray();
    }
    CASImpl cas = (CASImpl) fs.getCAS();
    TypeSystem ts = cas.getTypeSystem();
    Type fsType = fs.getType();
    if (ts.subsumes(ts.getType("uima.cas.FloatList"), fsType)) {
      return (floatListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.IntegerList"), fsType)) {
      return (integerListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.StringList"), fsType)) {
      return (stringListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.FSList"), fsType)) {
      return (fsListToArray(fs));
    }

    DebugNameValuePair[] result;
    String typeName = fsType.getName();

    List<Feature> features = fsType.getFeatures();
    int nbrFeats = features.size();
    boolean isAnnotation = false;
    boolean isJCasClass = false;
    if (fs.getClass().getName().equals(typeName)) { // true for JCas cover classes
      isJCasClass = true;
    }

    if (ts.subsumes(cas.getAnnotationType(), fsType)) {
      isAnnotation = true;
    }

    result = new DebugNameValuePair[(isJCasClass ? 0 : 1) // slot for type name if not JCas
            + (isAnnotation ? 3 : nbrFeats) // annotations have 4 slot display
    ];
    int i = 0;
    if (!isJCasClass) {
      result[i++] = new DebugNameValuePair("CasType", typeName);
    }

    if (isAnnotation) {
      DebugNameValuePair[] featResults = new DebugNameValuePair[nbrFeats];
      fillFeatures(featResults, 0, fs, features);
      result[i++] = new DebugNameValuePair("Features", featResults);
      result[i++] = new DebugNameValuePair("Covered Text", ((AnnotationFS) fs).getCoveredText());
      result[i++] = new DebugNameValuePair("SubAnnotations", new UnexpandedFeatureStructures(
              (AnnotationFS) fs));
    } else {
      fillFeatures(result, isJCasClass ? 0 : 1, fs, features);
    }

    return result;
  }
 
Example 22
Source Project: uima-uimaj   Source File: XCASDeserializerTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testOutOfTypeSystem2() throws Exception {
    // deserialize a complex CAS into one with no TypeSystem
    CAS cas = CasCreationUtils.createCas(new TypeSystemDescription_impl(),
            new TypePriorities_impl(), new FsIndexDescription[0]);
    OutOfTypeSystemData ootsd = new OutOfTypeSystemData();
    InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/cas.xml"));
    XCASDeserializer deser = new XCASDeserializer(cas.getTypeSystem());
    ContentHandler deserHandler = deser.getXCASHandler(cas, ootsd);
    SAXParserFactory fact = SAXParserFactory.newInstance();
    SAXParser parser = fact.newSAXParser();
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setContentHandler(deserHandler);
    xmlReader.parse(new InputSource(serCasStream));
    serCasStream.close();

    // now reserialize including OutOfTypeSystem data
    XCASSerializer xcasSer = new XCASSerializer(cas.getTypeSystem());
    StringWriter sw = new StringWriter();
    XMLSerializer xmlSer = new XMLSerializer(sw, false);
    xcasSer.serialize(cas, xmlSer.getContentHandler(), true, ootsd);
    String xml = sw.getBuffer().toString();
//    System.out.println("debug writing temp/xmlv3.xml");
//    FileUtils.saveString2File(xml, new File("c:/temp/xmlv3.xml"));
//    System.out.println(xml);

    // deserialize into a CAS that accepts the full typesystem
    CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
    XCASDeserializer deser2 = new XCASDeserializer(cas2.getTypeSystem());
    ContentHandler deserHandler2 = deser2.getXCASHandler(cas2);
    xmlReader = parser.getXMLReader();
    xmlReader.setContentHandler(deserHandler2);
    xmlReader.parse(new InputSource(new StringReader(xml)));

    // check that array refs are not null
    Type entityType = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Entity");
    Feature classesFeat = entityType.getFeatureByBaseName("classes");
    Iterator<FeatureStructure> iter = cas2.getIndexRepository().getIndex("testEntityIndex").iterator();
    assertTrue(iter.hasNext());
    while (iter.hasNext()) {
      FeatureStructure fs = iter.next();
      StringArrayFS arrayFS = (StringArrayFS) fs.getFeatureValue(classesFeat);
      assertNotNull(arrayFS);
      for (int i = 0; i < arrayFS.size(); i++) {
        assertNotNull(arrayFS.get(i));
      }
    }
  }
 
Example 23
Source Project: uima-uimaj   Source File: SerDesTest4.java    License: Apache License 2.0 4 votes vote down vote up
public void testArrayAux() {
  ArrayList<FeatureStructure> fsl = new ArrayList<>();
  /**
   * Strings, non-array Long/Double:
   * Make equal items,
   * ser/deser, update one of the equal items, insure other not updated
   */
  FeatureStructure fsAt1 = newAkof(fsl);
  FeatureStructure fsAt2 = newAkof(fsl);
  cas.addFsToIndexes(fsAt1);
  cas.addFsToIndexes(fsAt2);

  createStringA(fsAt1, "at");
  createStringA(fsAt2, "at");
  verify("ArrayAuxStrings");

  FSIterator<FeatureStructure> it = deserCas.indexRepository.getAllIndexedFS(akof);
  FeatureStructure fsAt1d = it.next();
  FeatureStructure fsAt2d = it.next();
  StringArrayFS sa1 = (StringArrayFS) fsAt1d.getFeatureValue(akofAstring);
  StringArrayFS sa2 = (StringArrayFS) fsAt2d.getFeatureValue(akofAstring);
  sa1.set(1, "def");
  assertEquals(sa2.get(1), "abcat");
  assertEquals(sa1.get(1), "def");
  cas.reset();

  fsAt1 = newAkof(fsl);
  fsAt2 = newAkof(fsl);
  cas.addFsToIndexes(fsAt1);
  cas.addFsToIndexes(fsAt2);

  createLongA(fsAt1, 9);
  createLongA(fsAt2, 9);
  verify("ArrayAuxLongs");

  it = deserCas.indexRepository.getAllIndexedFS(akof);
  fsAt1d = it.next();
  fsAt2d = it.next();
  LongArrayFS la1 = (LongArrayFS) fsAt1d.getFeatureValue(akofAlong);
  LongArrayFS la2 = (LongArrayFS) fsAt2d.getFeatureValue(akofAlong);
  la1.set(2, 123L);
  assertEquals(la2.get(2), -45 + 9);
  assertEquals(la1.get(2), 123);
}
 
Example 24
Source Project: uima-uimaj   Source File: SerDesTest4.java    License: Apache License 2.0 4 votes vote down vote up
private StringArrayFS createStringArrayFS(CAS c, int length) {
  return (StringArrayFS) createArray(c, ((CASImpl)c).getTypeSystemImpl().stringArrayType, length);    
}
 
Example 25
Source Project: uima-uimaj   Source File: SerDesTest6.java    License: Apache License 2.0 4 votes vote down vote up
public void testArrayAux() {
  ArrayList<FeatureStructure> fsList = new ArrayList<>();
  /**
   * Strings, non-array Long/Double:
   * Make equal items,
   * ser/deser, update one of the equal items, insure other not updated
   */
  FeatureStructure fsAt1 = newAkof(casSrc, mSrc, Akof1, fsList);
  FeatureStructure fsAt2 = newAkof(casSrc, mSrc, Akof1, fsList);
  casSrc.addFsToIndexes(fsAt1);
  casSrc.addFsToIndexes(fsAt2);

  createStringA(casSrc, mSrc, fsAt1, "at");
  createStringA(casSrc, mSrc, fsAt2, "at");
  TTypeSystem m = getTT(EqTwoTypes);
  remoteCas = setupCas(m);
  verify(remoteCas, "ArrayAuxString");

  FSIterator<FeatureStructure> it = remoteCas.indexRepository.getAllIndexedFS(m.getType(Akof1));
  FeatureStructure fsAt1d = it.next();
  FeatureStructure fsAt2d = it.next();
  StringArrayFS sa1 = (StringArrayFS) maybeGetFeatureKind(fsAt1d, m, "Astring");
  StringArrayFS sa2 = (StringArrayFS) maybeGetFeatureKind(fsAt2d, m, "Astring");
  sa1.set(1, "def");
  assertEquals(sa2.get(1), "abcat");
  assertEquals(sa1.get(1), "def");

  casSrc.reset();

  fsAt1 = newAkof(casSrc, mSrc, Akof1, fsList);
  fsAt2 = newAkof(casSrc, mSrc, Akof1, fsList);
  casSrc.addFsToIndexes(fsAt1);
  casSrc.addFsToIndexes(fsAt2);

  createLongA(casSrc, mSrc, fsAt1, 9);
  createLongA(casSrc, mSrc, fsAt2, 9);
  remoteCas.reset();
  verify(remoteCas, "ArrayAuxLong");

  it = remoteCas.indexRepository.getAllIndexedFS(m.getType(Akof1));
  fsAt1d = it.next();
  fsAt2d = it.next();
  LongArrayFS la1 = (LongArrayFS) maybeGetFeatureKind(fsAt1d, m, "Along");
  LongArrayFS la2 = (LongArrayFS) maybeGetFeatureKind(fsAt2d, m, "Along");
  la1.set(2, 123L);
  assertEquals(la2.get(2), -45 + 9);
  assertEquals(la1.get(2), 123);
}
 
Example 26
Source Project: uima-uimaj   Source File: NewPrimitiveTypesTest.java    License: Apache License 2.0 4 votes vote down vote up
private FeatureStructure createExampleFS(CAS parmCas) throws Exception {
  // Create a view
  CAS englishView = parmCas.createView("EnglishDocument");
  // Set the document text
  englishView.setDocumentText("this beer is good");

  // create an FS of exampleType and index it
  AnnotationFS fs = englishView.createAnnotation(exampleType, 1, 5);

  // create Array FSs
  StringArrayFS strArrayFS = parmCas.createStringArrayFS(5);
  strArrayFS.set(0, "zzzzzz");
  strArrayFS.set(1, "yyyyyy");
  strArrayFS.set(2, "xxxxxx");
  strArrayFS.set(3, "wwwwww");
  strArrayFS.set(4, "vvvvvv");

  IntArrayFS intArrayFS = parmCas.createIntArrayFS(5);
  intArrayFS.set(0, Integer.MAX_VALUE);
  intArrayFS.set(1, Integer.MAX_VALUE - 1);
  intArrayFS.set(2, 42);
  intArrayFS.set(3, Integer.MIN_VALUE + 1);
  intArrayFS.set(4, Integer.MIN_VALUE);

  FloatArrayFS floatArrayFS = parmCas.createFloatArrayFS(5);
  floatArrayFS.set(0, Float.MAX_VALUE);
  floatArrayFS.set(1, (float) (Float.MAX_VALUE / 1000.0));
  floatArrayFS.set(2, 42);
  floatArrayFS.set(3, (float) (Float.MIN_VALUE * 1000.0));
  floatArrayFS.set(4, Float.MIN_VALUE);

  ByteArrayFS byteArrayFS = parmCas.createByteArrayFS(5);
  byteArrayFS.set(0, (byte) 8);
  byteArrayFS.set(1, (byte) 16);
  byteArrayFS.set(2, (byte) 64);
  byteArrayFS.set(3, (byte) 128);
  byteArrayFS.set(4, (byte) 255);

  BooleanArrayFS boolArrayFS = parmCas.createBooleanArrayFS(20);
  boolean val = false;
  for (int i = 0; i < 20; i++) {
    boolArrayFS.set(i, val = !val);
  }

  ShortArrayFS shortArrayFS = parmCas.createShortArrayFS(5);
  shortArrayFS.set(0, Short.MAX_VALUE);
  shortArrayFS.set(1, (short) (Short.MAX_VALUE - 1));
  shortArrayFS.set(2, (short) (Short.MAX_VALUE - 2));
  shortArrayFS.set(3, (short) (Short.MAX_VALUE - 3));
  shortArrayFS.set(4, (short) (Short.MAX_VALUE - 4));

  LongArrayFS longArrayFS = parmCas.createLongArrayFS(5);
  longArrayFS.set(0, Long.MAX_VALUE);
  longArrayFS.set(1, Long.MAX_VALUE - 1);
  longArrayFS.set(2, Long.MAX_VALUE - 2);
  longArrayFS.set(3, Long.MAX_VALUE - 3);
  longArrayFS.set(4, Long.MAX_VALUE - 4);

  DoubleArrayFS doubleArrayFS = parmCas.createDoubleArrayFS(5);
  doubleArrayFS.set(0, Double.MAX_VALUE);
  doubleArrayFS.set(1, Double.MIN_VALUE);
  doubleArrayFS.set(2, Double.parseDouble("1.5555"));
  doubleArrayFS.set(3, Double.parseDouble("99.000000005"));
  doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444"));

  // set features of fs
  fs.setStringValue(stringFeature, "aaaaaaa");
  fs.setFloatValue(floatFeature, (float) 99.99);

  fs.setFeatureValue(intArrayFeature, intArrayFS);
  fs.setFeatureValue(floatArrayFeature, floatArrayFS);
  fs.setFeatureValue(stringArrayFeature, strArrayFS);

  // fs.setByteValue(byteFeature, Byte.MAX_VALUE);
  fs.setByteValue(byteFeature, (byte) 'z');
  fs.setFeatureValue(byteArrayFeature, byteArrayFS);
  fs.setBooleanValue(booleanFeature, true);
  fs.setFeatureValue(booleanArrayFeature, boolArrayFS);
  fs.setShortValue(shortFeature, Short.MIN_VALUE);
  fs.setFeatureValue(shortArrayFeature, shortArrayFS);
  fs.setLongValue(longFeature, Long.MIN_VALUE);
  fs.setFeatureValue(longArrayFeature, longArrayFS);
  fs.setDoubleValue(doubleFeature, Double.MAX_VALUE);
  fs.setFeatureValue(doubleArrayFeature, doubleArrayFS);
  
  englishView.getIndexRepository().addFS(fs);
  return fs;
}
 
Example 27
Source Project: uima-uimaj   Source File: CasComparer.java    License: Apache License 2.0 4 votes vote down vote up
private int compareArrayFSs(TOP arrayFS1fs, Feature feat1, TOP arrayFS2fs, Feature feat2, Set<TOP> visited) {

  CommonArrayFS arrayFS1 = (CommonArrayFS)arrayFS1fs.getFeatureValue(feat1);
  CommonArrayFS arrayFS2 = (CommonArrayFS)arrayFS2fs.getFeatureValue(feat2);
  
  if (null == arrayFS1 && null == arrayFS2)return 0; // are equal
  if (null == arrayFS1) return chkEqual(-1,  "Array FS1 is null, but Array FS2 is not");
  if (null == arrayFS2) return chkEqual(-1,  "Array FS2 is null, but Array FS1 is not");

  int r, len;
  if (0 != (r = Integer.compare(len = arrayFS1.size(), arrayFS2.size()))) {
    return chkEqual(r, "ArrayFSs are different sizes, fs1 size is %d, fs2 size is %d", arrayFS1.size(), arrayFS2.size());
  }
  // are same size
  r = validateSameType(arrayFS1, arrayFS2);
  if (0 != r) return r;
  
  switch(getArrayType(arrayFS1)) {
  case FS:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compare1((TOP)((FSArray)arrayFS1).get(j), (TOP)((FSArray)arrayFS2).get(j), visited))) return r;
    }
    break;
  case BOOLEAN:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compBoolean(((BooleanArrayFS)arrayFS1).get(j), ((BooleanArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case BYTE:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((ByteArrayFS)arrayFS1).get(j), ((ByteArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case SHORT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((ShortArrayFS)arrayFS1).get(j), ((ShortArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case INT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((IntArrayFS)arrayFS1).get(j), ((IntArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case LONG:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((LongArrayFS)arrayFS1).get(j), ((LongArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case FLOAT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compDouble(((FloatArrayFS)arrayFS1).get(j), ((FloatArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case DOUBLE:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compDouble(((DoubleArrayFS)arrayFS1).get(j), ((DoubleArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case STRING:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compStr(((StringArrayFS)arrayFS1).get(j), ((StringArrayFS)arrayFS2).get(j)))) {
        return chkEqual(r, "String miscompare, s1 = %s, s2 = %s", ((StringArrayFS)arrayFS1).get(j), ((StringArrayFS)arrayFS2).get(j));
      }
    }
    break;
  }
  return 0;  // all were equal
}
 
Example 28
Source Project: uima-uimaj   Source File: CasWrapperForTstng.java    License: Apache License 2.0 4 votes vote down vote up
public StringArrayFS createStringArrayFS(int length) throws CASRuntimeException {
  return originalCAS.createStringArrayFS(length);
}