Java Code Examples for org.apache.uima.jcas.cas.StringArray

The following examples show how to use org.apache.uima.jcas.cas.StringArray. 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: uima-uimaj   Source File: XmiCompare.java    License: Apache License 2.0 6 votes vote down vote up
private void fixupTermMentionTypesUnknown(CASImpl cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType("com.ibm.watsonx.nlp_di.cas_term.Term");
  Feature f_mentionTypes = type.getFeatureByBaseName("mentionTypes");
  cas.select(type)
     .allViews()
     .map(fs -> (StringArray) fs.getFeatureValue(f_mentionTypes))
     .filter(fs -> fs != null && fs.contains("UNKNOWN"))
     .forEach(fs -> 
       {
         for (int i = 0; i < fs.size(); i++) {
           if ("UNKNOWN".equals(fs.get(i))) {
             fs.set(i, "CATEGORY");
           }
         }
       });
}
 
Example 2
Source Project: uima-uimaj   Source File: BinaryCasSerDes4.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * For delta, for each fsChange element, extract any strings
 * @param fsChange
 */
private void extractStringsFromModifications(FsChange fsChange) {
  final TOP fs = fsChange.fs;
  final TypeImpl type = fs._getTypeImpl();
  if (fsChange.arrayUpdates != null) {
    if (type.getComponentSlotKind() == SlotKind.Slot_StrRef) {
      String[] sa = ((StringArray)fs)._getTheArray();  
      fsChange.arrayUpdates.forAllInts(index -> {
        os.add(sa[index]);
      });
    } // end of is string array
  } else { // end of is array
    BitSet fm = fsChange.featuresModified;
    for (int offset = fm.nextSetBit(0); offset >= 0; offset = fm.nextSetBit(offset + 1)) {
      FeatureImpl feat = type.getFeatureImpls()[offset];
      if (feat.getSlotKind() == SlotKind.Slot_StrRef) {
        os.add(fs._getStringValueNc(feat));
      }
    } // end of iter over features
  } // end of is-not-array
}
 
Example 3
Source Project: baleen   Source File: NewFeatureUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStringArray() {
  Buzzword bw = new Buzzword(jCas);
  StringArray tags = new StringArray(jCas, 2);
  tags.set(0, "tag1");
  tags.set(1, "tag2");
  bw.setTags(tags);
  bw.addToIndexes();

  Feature f = bw.getType().getFeatureByBaseName("tags");
  StringArray newTags = new StringArray(jCas, 2);
  newTags.set(0, "first");
  newTags.set(1, "second");
  NewFeatureUtils.setPrimitiveArray(jCas, bw, f, Arrays.asList(newTags.toArray()));

  assertEquals("first", bw.getTags(0));
  assertEquals("second", bw.getTags(1));
}
 
Example 4
Source Project: bluima   Source File: MongoFieldMapping.java    License: Apache License 2.0 6 votes vote down vote up
public static void readFieldFromDb(String fieldKey, String range,
        Annotation a, Feature f, BasicDBObject dbO, JCas jCas) {

    if (dbO.containsField(fieldKey)) {

        if (range.equals("String")) {
            a.setStringValue(f, dbO.getString(fieldKey));
        } else if (range.equals("StringArray")) {
            BasicDBList vals = (BasicDBList) dbO.get(fieldKey);
            StringArray sa = new StringArray(jCas, vals.size());
            for (int i = 0; i < vals.size(); i++) {
                sa.set(i, vals.get(i).toString());
            }
            a.setFeatureValue(f, sa);
        } else if (range.equals("Integer")) {
            a.setIntValue(f, dbO.getInt(fieldKey));
        } else if (range.equals("Float")) {
            a.setFloatValue(f, (float) dbO.getDouble(fieldKey));
        } else if (range.equals("Boolean")) {
            a.setBooleanValue(f, dbO.getBoolean(fieldKey));
        } else {
            LOG.warn("range not supported " + range);
        }
    }
}
 
Example 5
Source Project: baleen   Source File: FeatureUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStringArray() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "ENG");
  rel.set(1, "WAL");
  rel.set(2, "SCO");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object[] o = FeatureUtils.featureToArray(f, da);
  assertEquals(3, o.length);
  assertTrue(o[0] instanceof String);
  assertEquals("ENG", (String) o[0]);
  assertTrue(o[1] instanceof String);
  assertEquals("WAL", (String) o[1]);
  assertTrue(o[2] instanceof String);
  assertEquals("SCO", (String) o[2]);
}
 
Example 6
Source Project: uima-uimaj   Source File: CASImpl.java    License: Apache License 2.0 6 votes vote down vote up
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 7
Source Project: ambiverse-nlu   Source File: NYTCollectionReader.java    License: Apache License 2.0 5 votes vote down vote up
private static StringArray toStringArray(List<String> stringList, JCas aJCas) {
    if (!stringList.isEmpty()) {
        String[] strings = stringList.toArray(new String[0]);
        int length = strings.length;
        StringArray stringArray = new StringArray(aJCas, length);
        stringArray.copyFromArray(strings, 0, 0, length);
        return stringArray;
    } else {
        return new StringArray(aJCas, 0);
    }
}
 
Example 8
Source Project: uima-uimaj   Source File: DocumentAnnotationTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testToString() throws InvalidXMLException, IOException, ResourceInitializationException, CASException {
  File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem_docmetadata.xml");
  TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
          new XMLInputSource(typeSystemFile));
  
  source = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null);
  jcas = source.getJCas();
  
  DocMeta d = new DocMeta(jcas);
  d.setFeat("a string");
  d.setFeat2("b string");
  d.setFeat3("c string");
  
  FSArray fsa = new FSArray(jcas, 2);
  fsa.set(0, new Annotation(jcas, 1,2));
  fsa.set(1, new Annotation(jcas, 3,4));
  d.setArrayFs(fsa);
  
  IntegerArray intarr = new IntegerArray(jcas, 2);
  intarr.set(0,  10);
  intarr.set(1,  -10);
  d.setArrayints(intarr);
  
  StringArray strarr = new StringArray(jcas, 2);
  strarr.set(0,  "first");
  strarr.set(1,  "second");
  d.setArraystr(strarr);
  
  System.out.println(d.toString());
}
 
Example 9
Source Project: baleen   Source File: NewFeatureUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static StringArray getStringArray(JCas jCas, Collection<?> list) {
  final StringArray a = new StringArray(jCas, list.size());
  int i = 0;
  for (final Object s : list) {
    a.set(i++, s.toString());
  }
  return a;
}
 
Example 10
Source Project: baleen   Source File: AbstractAhoCorasickAnnotator.java    License: Apache License 2.0 5 votes vote down vote up
private void setPropertyArray(BaleenAnnotation entity, Method method, List<Object> obj) {
  if (StringArray.class.isAssignableFrom(method.getParameterTypes()[0])) {
    try {
      StringArray sa = listToStringArray(entity.getCAS().getJCas(), obj);
      method.invoke(entity, sa);
    } catch (Exception e) {
      getMonitor().error(ERROR_CANT_ASSIGN_ENTITY_PROPERTY, e);
    }
  } else {
    getMonitor()
        .error(
            "Unsupported array type {} - property will be skipped",
            method.getParameterTypes()[0].getName());
  }
}
 
Example 11
Source Project: baleen   Source File: MongoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuzzwordProperty() throws Exception {
  jCas.setDocumentText("Hello Sydney (Australia), this is a test");
  processJCas(MONGO, erd, COLLECTION, MONGO_COLL, TYPE, "Buzzword");

  assertEquals(1, JCasUtil.select(jCas, Buzzword.class).size());
  Buzzword b = JCasUtil.selectByIndex(jCas, Buzzword.class, 0);
  assertEquals("Sydney (Australia", b.getValue());
  assertEquals("Sydney (Australia", b.getCoveredText());

  StringArray tags = b.getTags();
  assertEquals(1, tags.size());
  assertEquals("broken_regex", tags.get(0));
}
 
Example 12
Source Project: bluima   Source File: BlueCasUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static List<String> toList(StringArray tokens) {
    List<String> l = new ArrayList<String>(tokens.size());
    for (int i = 0; i < tokens.size(); i++) {
        l.add(tokens.get(i));
    }
    return l;
}
 
Example 13
Source Project: bluima   Source File: PdfCollectionReader.java    License: Apache License 2.0 5 votes vote down vote up
static void extractTables(TableExtractor extractor, File f, JCas jcas) {
    try {
        ArrayList<Table> tables = extractor.extract(f, null);
        if (tables != null) {
            for (Table table : tables) {

                DataTable dt = new DataTable(jcas);
                dt.setTableId(table.getOrder());
                dt.setPageNumber(table.getPageNumber());
                // dt.setRowCount(table.getRowNumber());
                dt.setRowCount(table.getTableBody().size());
                dt.setColumnCount(table.getColumnNumber());
                dt.setCaption(table.getCaption());
                dt.setReferenceText(table.getRefTextList());

                ArrayList<String> tHeadings = table.getHeading();
                dt.setHeadings(new StringArray(jcas, tHeadings.size()));
                for (int i = 0; i < tHeadings.size(); i++) {
                    dt.setHeadings(i, tHeadings.get(i));
                }

                ArrayList<String> tBody = table.getTableBody();
                dt.setBody(new StringArray(jcas, tBody.size()));
                for (int i = 0; i < tBody.size(); i++) {
                    dt.setBody(i, tBody.get(i));
                }
                dt.addToIndexes();
            }
        }
    } catch (Throwable t) {
        LOG.warn("cannot extract tables from {}: {}", f.getAbsolutePath(),
                t);
    }
}
 
Example 14
Source Project: uima-uimaj   Source File: BinaryCasSerDes6.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add all the strings ref'd by this FS.
 *   - if it is a string array, do all the array items
 *   - else scan the features and do all string-valued features, in feature offset order
 * For delta, this isn't done here - another routine driven by FsChange info does this.
 */
private void addStringsFromFS(TOP fs) {
  if (fs instanceof StringArray) {
    for (String s : ((StringArray)fs)._getTheArray()) {
      os.add(s);
    }
    return;
  }
  
  for (FeatureImpl fi : fs._getTypeImpl().getFeatureImpls()) {
    if (fi.getRange() instanceof TypeImpl_string) {
      os.add(fs._getStringValueNc(fi));
    }
  }
}
 
Example 15
Source Project: baleen   Source File: UimaTypesUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new List from a StringArray
 *
 * @param array the string array
 * @return the list (non-null)
 */
public static List<String> toList(StringArray array) {
  if (array == null) {
    return Collections.emptyList();
  } else {
    return Arrays.asList(array.toArray());
  }
}
 
Example 16
Source Project: baleen   Source File: FeatureUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNull() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "ENG");
  rel.set(1, "WAL");
  rel.set(2, "SCO");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object o = FeatureUtils.featureToObject(f, da);
  assertNull(o);
}
 
Example 17
Source Project: baleen   Source File: UimaTypesUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNulls() {
  String[] javaSa = UimaTypesUtils.toArray(null);
  assertEquals(0, javaSa.length);

  StringArray uimaSa = UimaTypesUtils.toArray(jCas, null);
  assertEquals(0, uimaSa.size());

  uimaSa = UimaTypesUtils.toArray(jCas, Collections.emptyList());
  assertEquals(0, uimaSa.size());
}
 
Example 18
Source Project: uima-uimaj   Source File: CASImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StringArray emptyStringArray() {
    if (null == svd.emptyStringArray) {
      svd.emptyStringArray = new StringArray(this.getJCas(), 0);
    }
    return svd.emptyStringArray;
  }
 
Example 19
Source Project: uima-uimaj   Source File: XmiCompare.java    License: Apache License 2.0 5 votes vote down vote up
void canonicalizeStringFirstVariant(String t, String f, String v, CASImpl cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType(t);
  Feature feat = ts.getFeatureByFullName(t + ":" + f);
  Feature featv = ts.getFeatureByFullName(t + ":" + v);  // v is the variant array
  cas.select(type).allViews().forEach(fs ->
    { StringArray sa = (StringArray) fs.getFeatureValue(featv);
      if (sa != null && sa.size() > 2) {
        String item = fs.getStringValue(feat);
        if (sa.contains(item)) {
          fs.setStringValue(feat, sa.get(0));
        }
      }
    });
}
 
Example 20
Source Project: uima-uimaj   Source File: JCasTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testStringArrayAPI() {
  StringArray sa = new StringArray(jcas, 3);
  String[] values = {"1", "2", "3"}; 
  sa.copyFromArray(values, 0, 0, 3);
  
   int i = 0;
   for (String s : sa) {
     assert(s.equals(values[i++]));
   }
}
 
Example 21
Source Project: baleen   Source File: Postgres.java    License: Apache License 2.0 5 votes vote down vote up
private Array createVarcharArray(Connection conn, StringArray s) throws SQLException {
  if (s == null) {
    return conn.createArrayOf(VARCHAR, new String[] {});
  } else {
    return conn.createArrayOf(VARCHAR, s.toArray());
  }
}
 
Example 22
Source Project: baleen   Source File: AllAnnotationsJsonConsumerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException {
  jCas.setDocumentText(TEXT);
  tempDirectory = Files.createTempDirectory(AllAnnotationsJsonConsumerTest.class.getSimpleName());
  tempDirectory.toFile().deleteOnExit();

  DocumentAnnotation documentAnnotation = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  documentAnnotation.setSourceUri(SOURCEURI);

  Paragraph paragraph1 = new Paragraph(jCas);
  paragraph1.setBegin(0);
  paragraph1.setDepth(1);
  paragraph1.setEnd(52);
  paragraph1.addToIndexes();

  Person entity1 = new Person(jCas);
  entity1.setBegin(70);
  entity1.setEnd(73);
  entity1.setValue("cat");
  entity1.addToIndexes();

  Event event = new Event(jCas);
  event.setBegin(53);
  event.setEnd(105);
  event.setArguments(new StringArray(jCas, 2));
  event.setArguments(0, "cat");
  event.setArguments(1, "dog");
  event.setEntities(new FSArray(jCas, 1));
  event.setEntities(0, entity1);
  event.addToIndexes();
}
 
Example 23
Source Project: baleen   Source File: GremlinConsumerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  jCas.setDocumentText("Hello James! Is your e-mail address [email protected]? 'No', said James.");

  DocumentAnnotation da = getDocumentAnnotation(jCas);
  da.setDocType("test");
  da.setSourceUri("http://www.example.com/hello.txt");

  StringArray sa = new StringArray(jCas, 2);
  sa.set(0, "UK");
  sa.set(1, "US");
  da.setDocumentCaveats(sa);

  ReferenceTarget rt = new ReferenceTarget(jCas);
  rt.addToIndexes();

  Entity e1 = new Person(jCas, 6, 11);
  e1.setValue("James");
  e1.setReferent(rt);
  e1.addToIndexes();

  Entity e1a = new Person(jCas, 60, 65);
  e1a.setValue("James");
  e1a.setReferent(rt);
  e1a.addToIndexes();

  Entity e2 = new CommsIdentifier(jCas, 36, 47);
  e2.setValue("[email protected]");
  e2.addToIndexes();

  processJCas(GremlinConsumer.PARAM_GRAPH_CONFIG, tmpConfig.getPath());

  // TODO: Write some proper tests that actually check something
}
 
Example 24
Source Project: uima-uimaj   Source File: BinaryCasSerDes.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Doing updates for delta cas for existing objects.
 * Cases:
 *   - item in heap-stored-array = update the corresponding item in the FS
 *   - non-ref in feature slot - update the corresponding feature
 *   - ref (to long/double value, to string)
 *       -- these always reference entries in long/string tables that are new (above the line)
 *       -- these have already been deserialized
 *   - ref (to main heap) - can update this directly       
 *   NOTE: entire aux arrays never have their refs to the aux heaps updated, for 
 *           arrays of boolean, byte, short, long, double
 *   NOTE: Slot updates for FS refs always point to addr which are in the addr2fs table or are 0 (null),
 *           because if the ref is to a new one, those have been already deserialized by this point, and
 *                   if the ref is to a below-the-line one, those are already put into the addr2fs table
 * @param bds - helper data
 * @param slotAddr - the main heap slot addr being updated
 * @param slotValue - the new value
 */
private void updateHeapSlot(BinDeserSupport bds, int slotAddr, int slotValue, Int2ObjHashMap<TOP, TOP> addr2fs) {
  TOP fs = bds.fs;
  TypeImpl type = fs._getTypeImpl();
  if (type.isArray()) {
    // only heap stored arrays have mod updates.  
    final int hsai = slotAddr - bds.fsStartAddr - arrayContentOffset;  // heap stored array index
    switch(type.getComponentSlotKind()) {
    // heap stored arrays
    case Slot_Int: ((IntegerArray)fs).set(hsai,                   slotValue);  break;
    case Slot_Float: ((FloatArray)fs).set(hsai, CASImpl.int2float(slotValue)); break;
    
    case Slot_StrRef: ((StringArray)fs).set(hsai,  stringHeap.getStringForCode(slotValue)); break;
    case Slot_HeapRef:((FSArray    )fs).set(hsai, addr2fs.get(slotValue)); break;
    
    default: Misc.internalError();
    } // end of switch for component type of arrays
  } else { // end of arrays
    // is plain fs with fields
    final int offset0 = slotAddr - bds.fsStartAddr - 1;  // 0 based offset of feature, -1 for type code word
    FeatureImpl feat = type.getFeatureImpls()[offset0];
    SlotKind slotKind = feat.getSlotKind();
    switch(slotKind) {
    case Slot_Boolean:
    case Slot_Byte:   
    case Slot_Short:  
    case Slot_Int:    
    case Slot_Float: fs._setIntLikeValue(slotKind, feat, slotValue); break;
    
    case Slot_LongRef:   fs.setLongValue(feat, longHeap.getHeapValue(slotValue)); break;
    case Slot_DoubleRef: fs.setDoubleValue(feat, CASImpl.long2double(longHeap.getHeapValue(slotValue))); break;
    case Slot_StrRef: {
      String s = stringHeap.getStringForCode(slotValue);        
      if (updateStringFeature(fs, feat, s, null)) {
        fs.setStringValue(feat, stringHeap.getStringForCode(slotValue));
      }
      break;
    }
      
    case Slot_HeapRef:   fs.setFeatureValue(feat, addr2fs.get(slotValue)); break;
    default: Misc.internalError();
    }
  }
}
 
Example 25
Source Project: newsleak   Source File: Metadata.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/** getter for metaTripletsNames - gets 
 * @generated
 * @return value of the feature 
 */
public StringArray getMetaTripletsNames() {
  if (Metadata_Type.featOkTst && ((Metadata_Type)jcasType).casFeat_metaTripletsNames == null)
    jcasType.jcas.throwFeatMissing("metaTripletsNames", "uhh_lt.newsleak.types.Metadata");
  return (StringArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Metadata_Type)jcasType).casFeatCode_metaTripletsNames)));}
 
Example 26
Source Project: newsleak   Source File: Metadata.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/** setter for metaTripletsNames - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setMetaTripletsNames(StringArray v) {
  if (Metadata_Type.featOkTst && ((Metadata_Type)jcasType).casFeat_metaTripletsNames == null)
    jcasType.jcas.throwFeatMissing("metaTripletsNames", "uhh_lt.newsleak.types.Metadata");
  jcasType.ll_cas.ll_setRefValue(addr, ((Metadata_Type)jcasType).casFeatCode_metaTripletsNames, jcasType.ll_cas.ll_getFSRef(v));}
 
Example 27
Source Project: newsleak   Source File: Metadata.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/** getter for metaTripletsValues - gets 
 * @generated
 * @return value of the feature 
 */
public StringArray getMetaTripletsValues() {
  if (Metadata_Type.featOkTst && ((Metadata_Type)jcasType).casFeat_metaTripletsValues == null)
    jcasType.jcas.throwFeatMissing("metaTripletsValues", "uhh_lt.newsleak.types.Metadata");
  return (StringArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Metadata_Type)jcasType).casFeatCode_metaTripletsValues)));}
 
Example 28
Source Project: newsleak   Source File: Metadata.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/** getter for metaTripletsTypes - gets 
 * @generated
 * @return value of the feature 
 */
public StringArray getMetaTripletsTypes() {
  if (Metadata_Type.featOkTst && ((Metadata_Type)jcasType).casFeat_metaTripletsTypes == null)
    jcasType.jcas.throwFeatMissing("metaTripletsTypes", "uhh_lt.newsleak.types.Metadata");
  return (StringArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Metadata_Type)jcasType).casFeatCode_metaTripletsTypes)));}
 
Example 29
Source Project: newsleak   Source File: Metadata.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/** setter for metaTripletsTypes - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setMetaTripletsTypes(StringArray v) {
  if (Metadata_Type.featOkTst && ((Metadata_Type)jcasType).casFeat_metaTripletsTypes == null)
    jcasType.jcas.throwFeatMissing("metaTripletsTypes", "uhh_lt.newsleak.types.Metadata");
  jcasType.ll_cas.ll_setRefValue(addr, ((Metadata_Type)jcasType).casFeatCode_metaTripletsTypes, jcasType.ll_cas.ll_getFSRef(v));}
 
Example 30
Source Project: uima-uimaj   Source File: CasToInlineXmlTest.java    License: Apache License 2.0 4 votes vote down vote up
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());
  }