Java Code Examples for org.apache.uima.cas.CAS#getLowLevelCAS()
The following examples show how to use
org.apache.uima.cas.CAS#getLowLevelCAS() .
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: CasDoctorUtils.java From webanno with Apache License 2.0 | 6 votes |
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>( Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs)); // Remove all that are not annotations allReachableFS.entrySet().removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType())); // Remove all that are indexed allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue()); // All that is left are non-index annotations return allReachableFS; }
Example 2
Source File: XCASDeserializer.java From uima-uimaj with Apache License 2.0 | 6 votes |
public static void deserialize(InputSource aSource, CAS aCAS, boolean aLenient) throws SAXException, IOException { XMLReader xmlReader = XMLUtils.createXMLReader(); XCASDeserializer deser = new XCASDeserializer(aCAS.getTypeSystem()); ContentHandler handler; if (aLenient) { handler = deser.getXCASHandler(aCAS, new OutOfTypeSystemData()); } else { handler = deser.getXCASHandler(aCAS); } xmlReader.setContentHandler(handler); xmlReader.parse(aSource); CASImpl casImpl = ((CASImpl) aCAS.getLowLevelCAS()); if (casImpl.is_ll_enableV2IdRefs()) { TOP highest_fs = ((XCASDeserializerHandler) handler).highestIdFs; casImpl.setLastUsedFsId(highest_fs._id); casImpl.setLastFsV2Size(highest_fs._getTypeImpl().getFsSpaceReq(highest_fs)); } }
Example 3
Source File: CasDoctorUtils.java From webanno with Apache License 2.0 | 5 votes |
public static Set<FeatureStructure> collectIndexed(CAS aCas) { LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> fses = new TreeSet<>(Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fses::add); return fses; }
Example 4
Source File: CasDoctorUtils.java From webanno with Apache License 2.0 | 5 votes |
public static Set<FeatureStructure> collectReachable(CAS aCas) { LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> fses = new TreeSet<>(Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(fses, fs)); return fses; }
Example 5
Source File: CasCopier.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Change from https://issues.apache.org/jira/browse/UIMA-3112 : * requires that the CAS returned from the getLowLevelCAS() be castable to CASImpl * @param c1 - * @param c2 - * @return true if both views are in the same CAS (e.g., they have the same base CAS) */ private boolean casViewsInSameCas(CAS c1, CAS c2) { if (null == c1 || null == c2) { return false; } CASImpl ci1 = (CASImpl) c1.getLowLevelCAS(); CASImpl ci2 = (CASImpl) c2.getLowLevelCAS(); return ci1.getBaseCAS() == ci2.getBaseCAS(); }
Example 6
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 5 votes |
private FeatureStructure createFS(CAS cas, Type type) { if (isKeep) { LowLevelCAS llCas = cas.getLowLevelCAS(); return llCas.ll_getFSForRef(llCas.ll_createFS(((TypeImpl)type).getCode())); } return cas.createFS(type); }
Example 7
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 5 votes |
private TOP createArray(CAS cas, Type type, int length) { if (isKeep) { LowLevelCAS llCas = cas.getLowLevelCAS(); return llCas.ll_getFSForRef(llCas.ll_createArray(((TypeImpl)type).getCode(), length)); } return ((CASImpl)cas).createArray((TypeImpl)type, length); }
Example 8
Source File: WebannoTsv2Writer.java From webanno with Apache License 2.0 | 4 votes |
private void setTokenAnnos(CAS aCas, Map<Integer, String> aTokenAnnoMap, Type aType, Feature aFeature) { LowLevelCAS llCas = aCas.getLowLevelCAS(); for (AnnotationFS annoFs : CasUtil.select(aCas, aType)) { boolean first = true; boolean previous = false; // exists previous annotation, place-holed O-_ should be kept for (Token token : selectCovered(Token.class, annoFs)) { if (annoFs.getBegin() <= token.getBegin() && annoFs.getEnd() >= token.getEnd()) { String annotation = annoFs.getFeatureValueAsString(aFeature); if (annotation == null) { annotation = aType.getName() + "_"; } if (aTokenAnnoMap.get(llCas.ll_getFSRef(token)) == null) { if (previous) { if (!multipleSpans.contains(aType.getName())) { aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation); } else { aTokenAnnoMap.put(llCas.ll_getFSRef(token), "O-_|" + (first ? "B-" : "I-") + annotation); first = false; } } else { if (!multipleSpans.contains(aType.getName())) { aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation); } else { aTokenAnnoMap.put(llCas.ll_getFSRef(token), (first ? "B-" : "I-") + annotation); first = false; } } } else { if (!multipleSpans.contains(aType.getName())) { aTokenAnnoMap.put(llCas.ll_getFSRef(token), aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|" + annotation); previous = true; } else { aTokenAnnoMap.put(llCas.ll_getFSRef(token), aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|" + (first ? "B-" : "I-") + annotation); first = false; previous = true; } } } } } }
Example 9
Source File: SelectFSs_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
public SelectFSs_impl(CAS cas) { this.view = (CASImpl) cas.getLowLevelCAS(); this.jcas = (JCasImpl) view.getJCas(); }
Example 10
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
public final static boolean isSameCAS(CAS c1, CAS c2) { CASImpl ci1 = (CASImpl) c1.getLowLevelCAS(); CASImpl ci2 = (CASImpl) c2.getLowLevelCAS(); return ci1.getBaseCAS() == ci2.getBaseCAS(); }
Example 11
Source File: CasCopier.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Creates a new CasCopier that can be used to copy FeatureStructures from one CAS to another. * Note that if you are merging data from multiple CASes, you must create a new CasCopier * for each source CAS. This version of the constructor supports a "lenient copy" option. When set, * the CAS copy function will ignore (not attempt to copy) FSs and features not defined in the type system * of the destination CAS, rather than throwing an exception. * * @param aSrcCas * the CAS to copy from. * @param aDestCas * the CAS to copy into. * @param lenient * ignore FSs and features not defined in the type system of the destination CAS */ public CasCopier(CAS aSrcCas, CAS aDestCas, boolean lenient) { mFsMap = new IdentityHashMap<>(((CASImpl)(aSrcCas.getLowLevelCAS())).getLastUsedFsId()); originalSrcCas = (CASImpl)aSrcCas.getLowLevelCAS(); originalTgtCas = (CASImpl)aDestCas.getLowLevelCAS(); srcTsi = originalSrcCas.getTypeSystemImpl(); tgtTsi = originalTgtCas.getTypeSystemImpl(); src2TgtType = (srcTsi == tgtTsi) ? null : new Int2ObjListMap<>(srcTsi.getTypeArraySize()); src2TgtFeat = (srcTsi == tgtTsi) ? null : new Int2ObjListMap<>(srcTsi.getNumberOfFeatures() + 1); // tInfoArray = new TypeInfo[srcTsi.getLargestTypeCode() + 1]; // srcStringType = srcTsi.stringType; // srcStringTypeCode = srcStringType.getCode(); // mDestSofaFeature = aDestCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA); this.lenient = lenient; // the next is to support the style of use where // an instance of this copier is made, corresponding to two views in the same CAS // or corresponding to two views in different CASs // and then individual FeatureStructures are copied using copyFS(...) srcCasViewImpl = (CASImpl) originalSrcCas.getLowLevelCAS(); tgtCasViewImpl = (CASImpl) originalTgtCas.getLowLevelCAS(); srcViewName = srcCasViewImpl.getViewName(); tgtViewName = tgtCasViewImpl.getViewName(); if (srcViewName == null) { // base cas isChangeViewName = (tgtViewName == null) ? false : true; } else { isChangeViewName = !srcViewName.equals(tgtViewName); } isEqualTypeSystems = srcTsi.equals(tgtTsi); }