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