public boolean equals(Object o) { if (o == null) { return false; } if (!(o instanceof TOP)) return false; TOP fs = (TOP) o; if ((this.addr == fs.addr) && (this.jcasType.casImpl.getBaseCAS() == fs.jcasType.casImpl.getBaseCAS())) { return true; } return false; }
public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (!(o instanceof FeatureStructureImplC)) { return false; } FeatureStructureImplC fs = (FeatureStructureImplC) o; if ((this.addr == fs.addr) && (this.casImpl.getBaseCAS() == fs.casImpl.getBaseCAS())) { return true; } return false; }
/** * @see UimaContextAdmin#returnedCAS(AbstractCas) */ public void returnedCAS(AbstractCas aCAS) { //remove Base CAS from outstanding CASes set CAS baseCas = null; if (aCAS instanceof JCas) { baseCas = ((JCas)aCAS).getCasImpl().getBaseCAS(); } else if (aCAS instanceof CASImpl) { baseCas = ((CASImpl)aCAS).getBaseCAS(); } mOutstandingCASes.remove(baseCas); // mOutstandingCASes is thread-safe (Concurrent hash map) }
private void copyCasViewDifferentCASs(CAS aSrcCasView, CAS aTgtCasView, boolean aCopySofa) { if (originalSrcCasImpl.getBaseCAS() == originalTgtCasImpl.getBaseCAS()) { throw new UIMARuntimeException(UIMARuntimeException.ILLEGAL_CAS_COPY_TO_SAME_CAS, null); } copyCasView(aSrcCasView, aTgtCasView, aCopySofa); }
/** * 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(); } }
public void serialize(CAS cas, JsonContentHandlerJacksonWrapper jch, XmiSerializationSharedData sharedData, Marker marker) throws IOException { JsonDocSerializer ser = new JsonDocSerializer(jch, ((CASImpl) cas).getBaseCAS(), sharedData, (MarkerImpl) marker); try { ser.cds.needNameSpaces = false; ser.cds.serialize(); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } throw new RuntimeException(e); } }
/** * Write the CAS data to a SAX content handler. * * @param cas * The CAS to be serialized. * @param contentHandler * The SAX content handler the data is written to. * @param encodeDoc * If set to false, no uima.tcas.Document structure will be created, and the document * text will not be serialized. * @param outOfTypeSystemData * data not part of the CAS type system, which should be inserted into the XCAS output * * @throws IOException passed thru * @throws SAXException passed thru */ public void serialize(CAS cas, ContentHandler contentHandler, boolean encodeDoc, OutOfTypeSystemData outOfTypeSystemData) throws IOException, SAXException { contentHandler.startDocument(); XCASDocSerializer ser = new XCASDocSerializer(contentHandler, ((CASImpl) cas).getBaseCAS()); ser.serialize(encodeDoc, outOfTypeSystemData); contentHandler.endDocument(); // System.out.println("Done serializing " + ser.fsCount + " FSs."); }
@Override public void setOwner(CasOwner aCasOwner) { CASImpl baseCas = getBaseCAS(); if (baseCas != this) { baseCas.setOwner(aCasOwner); } else { super.setOwner(aCasOwner); } }
@Override public void release() { CASImpl baseCas = getBaseCAS(); if (baseCas != this) { baseCas.release(); } else { super.release(); } }
protected void populateCasToCasPoolAndUimaContextMaps(CasPool aCasPool, UimaContext aUimaContext) { CAS[] casArray = new CAS[aCasPool.getSize()]; for (int i = 0; i < casArray.length; i++) { casArray[i] = ((CASImpl) aCasPool.getCas()).getBaseCAS(); mCasToCasPoolMap.put(casArray[i], aCasPool); if (aUimaContext != null) { mCasToUimaContextMap.put(casArray[i], aUimaContext); } } for (int i = 0; i < casArray.length; i++) { aCasPool.releaseCas(casArray[i]); } }
public AbstractCas next() throws AnalysisEngineProcessException { // get a new CAS CAS cas = mUimaContext.getEmptyCas(CAS.class); // check if type system changed; if so, notify CollectionReader checkTypeSystemChange(cas); // Get the right view of the CAS. Sofa-aware components get the base CAS. // Sofa-unaware components get whatever is mapped to the default text sofa. CAS view = ((CASImpl) cas).getBaseCAS(); if (!mSofaAware) { view = cas.getView(CAS.NAME_DEFAULT_SOFA); } try { mCollectionReader.getNext(view); } catch (CollectionException e) { throw new AnalysisEngineProcessException(e); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } return cas; }
@Override public final int ll_getFSRef(FeatureStructure fsImpl) { if (null == fsImpl) { return NULL; } final FeatureStructureImpl fsi = (FeatureStructureImpl) fsImpl; if (this != fsi.getCASImpl()) { if (this.getBaseCAS() != fsi.getCASImpl().getBaseCAS()) { // https://issues.apache.org/jira/browse/UIMA-3429 throw new CASRuntimeException(CASRuntimeException.DEREF_FS_OTHER_CAS, new Object[] {fsi.toString(), this.toString() } ); } } return fsi.getAddress(); }
/** * Push the indexed FSs onto the queue. */ private void enqueueIndexed() { FSIndexRepositoryImpl ir = (FSIndexRepositoryImpl) cas.getBaseCAS().getBaseIndexRepository(); int[] fsarray = ir.getIndexedFSs(); for (int k = 0; k < fsarray.length; k++) { enqueueIndexed(fsarray[k], 0); } // Get indexes for each SofaFS in the CAS int numViews = cas.getBaseSofaCount(); for (int sofaNum = 1; sofaNum <= numViews; sofaNum++) { FSIndexRepositoryImpl loopIR = (FSIndexRepositoryImpl) cas.getBaseCAS() .getSofaIndexRepository(sofaNum); if (loopIR != null) { fsarray = loopIR.getIndexedFSs(); for (int k = 0; k < fsarray.length; k++) { enqueueIndexed(fsarray[k], sofaNum); } } } }
private JCasImpl(CASImpl cas) throws CASException { // * A new instance of JCas exists for each CAS // * At this point, some but not necessarily all of the Types have been // loaded // * the typeArray needs to be big enough to hold all the types // * that will be loaded. this.casImpl = cas; this.isUsedCache = cas.doUseJcasCache(); if (casImpl != casImpl.getBaseCAS()) { sharedView = ((JCasImpl) casImpl.getBaseCAS().getJCas()).sharedView; sharedView.errorSet.clear(); } else { sharedView = new JCasSharedView(cas, this.isUsedCache); } this.ll_IndexRepository = casImpl.ll_getIndexRepository(); this.jfsIndexRepository = new JFSIndexRepositoryImpl(this, cas.getIndexRepository()); // * acquire the lock for this thread that is the same lock // * used in the getNextIndexIncr operation. This will block // * any other (meaning on another thread) // * loading of the JCas Type classes until this thread's loading // * completes. synchronized (JCasImpl.class) { ClassLoader cl = cas.getJCasClassLoader(); instantiateJCas_Types(cl); } // end of synchronized block }
public CASImpl setupCasFromCasMgrSerializer(CASMgrSerializer casMgrSerializer) { CASImpl cas = this.getBaseCAS(); if (null != casMgrSerializer) { TypeSystemImpl ts = casMgrSerializer.getTypeSystem(); cas.svd.casMetadata = ts.casMetadata; cas.commitTypeSystem(); // reset index repositories -- wipes out Sofa index cas.indexRepository = casMgrSerializer.getIndexRepository(cas); cas.indexRepository.commit(); // get handle to existing initial View CAS initialView = cas.getInitialView(); // throw away all other View information as the CAS definition may have // changed cas.svd.sofa2indexMap.clear(); cas.svd.sofaNbr2ViewMap.clear(); cas.svd.viewCount = 0; // freshen the initial view ((CASImpl) initialView).refreshView(cas.svd.baseCAS, null); setViewForSofaNbr(1, initialView); cas.svd.viewCount = 1; } return cas; }
public TOP(JCas jcas) { CASImpl casImpl = (CASImpl)jcas.getCas(); this.jcasType = jcas.getType(getTypeIndexID()); if (null == jcasType) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS, new String[] { this.getClass().getName() }); throw e; } boolean isSubtypeOfAnnotationBase = casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode); if (isSubtypeOfAnnotationBase && (casImpl.getBaseCAS() == casImpl)) { throw new CASRuntimeException(CASRuntimeException.DISALLOW_CREATE_ANNOTATION_IN_BASE_CAS, new String[] { this.getClass().getName() }); } this.addr = jcasType.ll_cas.ll_createFS(jcasType.casTypeCode); jcas.putJfsFromCaddr(addr, this); if (casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode)) { casImpl.setSofaFeat(addr, casImpl.getSofaRef()); } }
private XCASDeserializerHandler(CASImpl aCAS, OutOfTypeSystemData ootsData) { super(); this.cas = aCAS.getBaseCAS(); // Reset the CAS. cas.resetNoQuestions(); this.fsTree = new RedBlackTree<FSInfo>(); this.idLess = new ArrayList<FSInfo>(); this.buffer = new StringBuffer(); this.outOfTypeSystemData = ootsData; this.indexRepositories = new ArrayList<FSIndexRepository>(); this.views = new ArrayList<CAS>(); // using the baseCas for indexing Sofas indexRepositories.add(this.cas.getBaseIndexRepository()); // There should always be another index for the Initial View indexRepositories.add(this.cas.getView(CAS.NAME_DEFAULT_SOFA).getIndexRepository()); this.sofaTypeCode = cas.ll_getTypeSystem().ll_getCodeForType( cas.getTypeSystem().getType(CAS.TYPE_NAME_SOFA)); this.annotBaseType = this.cas.getAnnotationType(); this.sofaRefMap = new IntVector(); this.indexMap = new IntVector(); // add entry for baseCAS ... point non-compliant annotations at first Sofa sofaRefMap.add(1); // add entry for baseCAS ... _indexed=0 stays in 0 indexMap.add(0); }
public int ll_createFSAnnotCheck(int typeCode) { final int addr = ll_createFS(typeCode); final TypeSystemImpl ts = this.svd.casMetadata.ts; final boolean isAnnot = ts.subsumes(TypeSystemImpl.annotBaseTypeCode, typeCode); if (isAnnot && (this == this.getBaseCAS())) { CASRuntimeException e = new CASRuntimeException( CASRuntimeException.DISALLOW_CREATE_ANNOTATION_IN_BASE_CAS, new String[] { ts.ll_getTypeForCode(typeCode).getName() }); throw e; } if (isAnnot) { this.setFeatureValueNotJournaled(addr, TypeSystemImpl.annotSofaFeatCode, this.getSofaRef()); } return addr; }
protected void applyChanges(JCas aSourceView, JCas aTargetView) { AlignedString as = AlignmentFactory.createAlignmentsFor(aSourceView); // Set the text of the new Sofa aTargetView.setDocumentText(as.get()); // Set document language aTargetView.setDocumentLanguage(aSourceView.getDocumentLanguage()); // Optionally we may want to remember the AlignedString for the backmapper. AlignmentStorage.getInstance().put(aSourceView.getCasImpl().getBaseCAS(), aSourceView.getViewName(), aTargetView.getViewName(), as); } }
public void writeViewsCommons() throws Exception { // Get indexes for each SofaFS in the CAS int numViews = cas.getBaseSofaCount(); for (int sofaNum = 1; sofaNum <= numViews; sofaNum++) { FSIndexRepositoryImpl loopIR = (FSIndexRepositoryImpl) cas.getBaseCAS().getSofaIndexRepository(sofaNum); final int sofaAddr = getSofaAddr(sofaNum); if (loopIR != null) { if (!isDelta) { int[] fsarray = loopIR.getIndexedFSs(); csss.writeView(sofaAddr, fsarray); } else { // is Delta Cas if (sofaNum != 1 && this.marker.isNew(sofaAddr)) { // for views created after mark (initial view never is - it is always created with the CAS) // write out the view as new int[] fsarray = loopIR.getIndexedFSs(); csss.writeView(sofaAddr, fsarray); } else if (loopIR.isModified()) { csss.writeView(sofaAddr, loopIR.getAddedFSs(), loopIR.getDeletedFSs(), loopIR.getReindexedFSs()); } } } } }