/** * Finds the sentence annotation containing the given token. * * \param token the token * \return the sentence or an invalid sentence if not found */ SentenceAnnotation SentenceAnnotation::findSentenceContainingToken(TokenAnnotation& token) { FSIterator iterator = token.getView().getAnnotationIndex(tSentenceAnnotation).iterator(); if (iterator.isValid()) { iterator.moveToFirst(); while (iterator.isValid()) { AnnotationFS annotation(iterator.get()); SentenceAnnotation sentence(annotation); if ((sentence.getFirstToken().getIndex() <= token.getIndex()) && (sentence.getLastToken().getIndex() >= token.getIndex())) return sentence; iterator.moveToNext(); } } return SentenceAnnotation(); }
void CASDeserializer::deserializeIndexedFSs(vector<SerializedCAS::TyNum> & crIndexFSs, uima::CAS & rCAS) { uima::internal::CASImpl & rCASImpl = uima::internal::CASImpl::promoteCAS(rCAS); uima::lowlevel::FSHeap & crHeap = rCASImpl.getHeap(); uima::lowlevel::IndexRepository * crIndexRep = &rCASImpl.getIndexRepository(); uima::lowlevel::FSHeap::TyFSHeap const & rTempFSHeap = crHeap.iv_clTemporaryHeap; SerializedCAS::TyNum iMaxOffset = rTempFSHeap.getTopOfHeap(); vector<SerializedCAS::TyNum>::const_iterator cit, loopit; vector<SerializedCAS::TyNum> perLoopIndexedFSs; cit = crIndexFSs.begin(); int numViews = *cit++; int loopSize = *cit; crIndexRep->reset(); // deserialize base CAS if (loopSize > 0) { lastSegmentUsed = 0; perLoopIndexedFSs.insert(perLoopIndexedFSs.end(), cit+1, cit+1+loopSize); cit += loopSize + 1; for (loopit = perLoopIndexedFSs.begin(); loopit != perLoopIndexedFSs.end(); ++loopit) { assert( *loopit < iMaxOffset ); crIndexRep->add( *loopit ); } } // book keeping for all Sofas rCAS.getBaseCas()->iv_sofaCount = 1; // reserve for initial view FSIndex fsIdx = crIndexRep->getIndex(CAS::INDEXID_SOFA); FSIterator fsIt = fsIdx.iterator(); while (fsIt.isValid()) { SofaFS aSofa = (SofaFS) fsIt.get(); if ( 0 == aSofa.getSofaID().compare(UnicodeString(CAS::NAME_DEFAULT_SOFA)) ) { rCAS.registerInitialSofa(); } else { // only bump sofa count if not initial View rCAS.bumpSofaCount(); } rCAS.getView(aSofa)->registerView(aSofa); fsIt.moveToNext(); } for (int view = 1; view <= numViews; view++) { // Check if sofa's index has anything in it loopSize = *cit; if (0 == loopSize) { cit++; continue; } CAS* tcas = rCAS.getViewBySofaNum(view); uima::internal::CASImpl & crTCASImpl = uima::internal::CASImpl::promoteCAS(*tcas); crIndexRep = &crTCASImpl.getIndexRepository(); crIndexRep->reset(); perLoopIndexedFSs.clear(); perLoopIndexedFSs.insert(perLoopIndexedFSs.end(), cit+1, cit+1+loopSize); cit += loopSize + 1; for (loopit = perLoopIndexedFSs.begin(); loopit != perLoopIndexedFSs.end(); ++loopit) { assert( *loopit < iMaxOffset ); crIndexRep->add( *loopit ); } tcas->pickupDocumentAnnotation(); } }