org.apache.uima.jcas.cas.StringArray.toArray()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(78)

本文整理了Java中org.apache.uima.jcas.cas.StringArray.toArray()方法的一些代码示例,展示了StringArray.toArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringArray.toArray()方法的具体详情如下:
包路径:org.apache.uima.jcas.cas.StringArray
类名称:StringArray
方法名:toArray

StringArray.toArray介绍

暂无

代码示例

代码示例来源:origin: uk.gov.dstl.baleen/baleen-uima

/**
 * Create a new string array from a stringarray
 *
 * @param jCas the jCas which will own the StringArray
 * @param stringarray the string aray
 * @return the string array (non-null)
 */
public static String[] toArray(StringArray array) {
 if (array == null) {
  return new String[0];
 } else {
  return array.toArray();
 }
}

代码示例来源:origin: dstl/baleen

/**
 * Create a new string array from a stringarray
 *
 * @param jCas the jCas which will own the StringArray
 * @param stringarray the string aray
 * @return the string array (non-null)
 */
public static String[] toArray(StringArray array) {
 if (array == null) {
  return new String[0];
 } else {
  return array.toArray();
 }
}

代码示例来源:origin: dstl/baleen

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());
 }
}

代码示例来源:origin: uk.gov.dstl.baleen/baleen-uima

/**
 * 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());
 }
}

代码示例来源:origin: dstl/baleen

/**
 * 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());
 }
}

代码示例来源:origin: de.julielab/jcore-xmi-db-writer

/**
 * Reads all {@link XmiMetaData} types from the CAS index, writes the
 * actual sofa xmi:id to sofaID mapping into a map, removes the annotations
 * from the index and returns the map.
 *
 * @param aJCas
 * @param docId
 * @return
 */
private Map<String, Integer> getOriginalSofaIdMappings(JCas aJCas, DocumentId docId) {
  if (storeAll)
    return Collections.emptyMap();
  XmiMetaData xmiMetaData;
  try {
    xmiMetaData = JCasUtil.selectSingle(aJCas, XmiMetaData.class);
    if (xmiMetaData.getSofaIdMappings() == null)
      return Collections.emptyMap();
  } catch (IllegalArgumentException e) {
    // in case there is no XMI meta data
    return Collections.emptyMap();
  }
  // note that we change the mapping orientation; originally stored
  // was xmiID:sofaID[sofaName]; but for the XmiSplitter input we need
  // it the other way round.
  Map<String, Integer> map = Stream.of(xmiMetaData.getSofaIdMappings().toArray()).map(line -> line.split("="))
      .collect(Collectors.toMap(split -> split[1], split -> Integer.parseInt(split[0])));
  log.trace("Got Sofa XMI map from the CAS: {} for document {}", map, docId);
  return map;
}

代码示例来源:origin: dstl/baleen

private Map<String, Object> serialiseDocumentAnnotation(final DocumentAnnotation da) {
 final Map<String, Object> map = new HashMap<>();
 map.put(JsonJCas.DA_DOCUMENT_TYPE, da.getDocType());
 map.put(JsonJCas.DA_LANGUAGE, da.getLanguage());
 map.put(JsonJCas.DA_SOURCE_URI, da.getSourceUri());
 map.put(JsonJCas.DA_CLASSIFICATION, da.getDocumentClassification());
 final String[] caveats =
   da.getDocumentCaveats() != null ? da.getDocumentCaveats().toArray() : new String[0];
 map.put(JsonJCas.DA_CAVEATS, caveats);
 final String[] rels =
   da.getDocumentReleasability() != null
     ? da.getDocumentReleasability().toArray()
     : new String[0];
 map.put(JsonJCas.DA_RELEASABILITY, rels);
 return map;
}

代码示例来源:origin: de.julielab/jcore-db-reader

public static String setDBProcessingMetaData(DataBaseConnector dbc, boolean readDataTable, String tableName, byte[][] data, JCas cas) {
  String pkString = null;
  // remove previously added dbMetaData
  JCasUtil.select(cas, DBProcessingMetaData.class).forEach(x -> x.removeFromIndexes());
  DBProcessingMetaData dbMetaData = new DBProcessingMetaData(cas);
  List<Integer> pkIndices = dbc.getPrimaryKeyIndices();
  StringArray pkArray = new StringArray(cas, pkIndices.size());
  for (int i = 0; i < pkIndices.size(); ++i) {
    Integer index = pkIndices.get(i);
    String pkElementValue = new String(data[index], Charset.forName("UTF-8"));
    pkArray.set(i, pkElementValue);
  }
  if (log.isDebugEnabled())
    log.debug("Setting primary key to {}", Arrays.toString(pkArray.toArray()));
  dbMetaData.setPrimaryKey(pkArray);
  if (!readDataTable)
    dbMetaData.setSubsetTable(
        tableName.contains(".") ? tableName : dbc.getActivePGSchema() + "." + tableName);
  dbMetaData.addToIndexes();
  return pkString;
}

代码示例来源:origin: dstl/baleen

final String[] array = decorations.toArray();
for (final String a : array) {
 switch (a.toUpperCase()) {

代码示例来源:origin: dstl/baleen

/** Create a map containing information from the DocumentAnnotation object */
public static Map<String, Object> createDocumentAnnotationMap(DocumentAnnotation da) {
 Map<String, Object> map = new HashMap<>();
 if (!Strings.isNullOrEmpty(da.getSourceUri())) {
  map.put("sourceUri", da.getSourceUri());
 }
 map.put("dateAccessed", da.getTimestamp());
 if (!Strings.isNullOrEmpty(da.getDocType())) {
  map.put("docType", da.getDocType());
 }
 if (!Strings.isNullOrEmpty(da.getDocumentClassification())) {
  map.put("classification", da.getDocumentClassification().toUpperCase());
 }
 if (da.getDocumentCaveats() != null) {
  String[] caveats = da.getDocumentCaveats().toArray();
  if (caveats.length > 0) {
   map.put("caveats", caveats);
  }
 }
 if (da.getDocumentReleasability() != null) {
  String[] rels = da.getDocumentReleasability().toArray();
  if (rels.length > 0) {
   map.put("releasability", rels);
  }
 }
 return map;
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_mongodb

static void writeFieldToDb(String range, BasicDBObject o, Annotation a,
    String dbKey, Feature f) {
  if (range.equals("String")) {
    o.put(dbKey, a.getStringValue(f));
  } else if (range.equals("StringArray")) {
    StringArray sa = (StringArray) a.getFeatureValue(f);
    if (sa != null) {
      String[] vals = sa.toArray();
      o.put(dbKey, Lists.newArrayList(vals));
    }
  } else if (range.equals("Integer")) {
    o.put(dbKey, a.getIntValue(f));
  } else if (range.equals("Float")) {
    o.put(dbKey, a.getFloatValue(f));
  } else if (range.equals("Boolean")) {
    o.put(dbKey, a.getBooleanValue(f));
  } else {
    LOG.warn("range not supported " + range);
  }
}

代码示例来源:origin: dstl/baleen

String[] caveats = da.getDocumentCaveats().toArray();
if (caveats.length > 0) {
 document.put("caveats", caveats);
String[] rels = da.getDocumentReleasability().toArray();
if (rels.length > 0) {
 document.put("releasability", rels);

代码示例来源:origin: dstl/baleen

Arrays.stream(e.getArguments().toArray()).map(this::normalize).forEach(list::add);

代码示例来源:origin: ClearTK/cleartk

private static Object[] getPrimitiveArrayFeatureValue(
  JCas view,
  FeatureStructure featureStructure,
  Feature feature) throws CleartkExtractorException {
 TypeSystem typeSystem = view.getTypeSystem();
 Type type = feature.getRange();
 if (type.isArray()) {
  Type componentType = type.getComponentType();
  FeatureStructure featureValue = featureStructure.getFeatureValue(feature);
  if (componentType.equals(typeSystem.getType("uima.cas.String"))) {
   return ((StringArray) featureValue).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Boolean"))) {
   return Arrays.asList(((BooleanArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Double"))) {
   return Arrays.asList(((DoubleArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Float"))) {
   return Arrays.asList(((FloatArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Byte"))) {
   return Arrays.asList(((ByteArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Short"))) {
   return Arrays.asList(((ShortArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Integer"))) {
   return Arrays.asList(((IntegerArray) featureValue).toArray()).toArray();
  } else if (componentType.equals(typeSystem.getType("uima.cas.Long"))) {
   return Arrays.asList(((LongArray) featureValue).toArray()).toArray();
  }
 } else
  throw CleartkExtractorException.notPrimitiveArray(feature);
 return null;
}

代码示例来源:origin: de.julielab/jcore-db-reader

for (int i = 0; i < identifiers.size(); i++) {
  StringArray primaryKey = (StringArray) identifiers.get(i);
  documentIdsForQuery.add(primaryKey.toArray());

代码示例来源:origin: dstl/baleen

@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));
 }
}

相关文章