@Override public CASImpl getCasImpl() { testLiveness(); return delegate.getCasImpl(); }
public static void writeSerializedCas(JCas aJCas, File aFile) throws IOException { FileUtils.forceMkdir(aFile.getParentFile()); try (ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(aFile))) { CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); os.writeObject(serializer); } }
protected TOP_Type(JCas jcas, Type casType, boolean installGenerator) { this.jcas = jcas; this.casImpl = jcas.getCasImpl(); this.ll_cas = this.casImpl; this.casType = casType; this.instanceOf_Type = this; this.casTypeCode = ((TypeImpl) this.casType).getCode(); this.lowLevelTypeChecks = false; this.lowLevelArrayBoundChecks = false; this.useExistingInstance = true; // Add generator to CASImpl for this type // NOTE Getter used for FSGenerator to get the subtype instance value // NOTE Above comment is irrelevant - because this call has to be in // every subclass, because at the time this executes in TOP_Type, // it is because the subclass invoked it via super(x,y), and the // subclass's instance vars haven't yet been set // Solution: every superClass that could be instantiated (TOP is not one of them) // during the super calls will incorrectly set the generator for the casType, but // this is OK because after the supers all run, the bottom one runs and sets it correctly. // if (installGenerator) { // ((CASImpl) ll_cas).getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, // getFSGenerator()); // } }
public static void readSerializedCas(JCas aJCas, File aFile) throws IOException { try (ObjectInputStream is = new ObjectInputStream(new FileInputStream(aFile))) { CASCompleteSerializer serializer = (CASCompleteSerializer) is.readObject(); deserializeCASComplete(serializer, aJCas.getCasImpl()); // Initialize the JCas sub-system which is the most often used API in DKPro Core // components aJCas.getCas().getJCas(); } catch (CASException | ClassNotFoundException e) { throw new IOException(e); } } }
/** * @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) }
void invalidate() { // TODO: Fixme: this is one of the places where we hacked the timeout solution delegate.getCasImpl().enableReset(true); delegate.release(); this.alive = false; }
private void writeTypeSystem(CAS cas, DataOutputStream aOS) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(512); DeflaterOutputStream dos = new DeflaterOutputStream(bos); ObjectOutputStream typeOS = new ObjectOutputStream(dos); CASMgrSerializer casMgrSerializer; try { casMgrSerializer = serializeCASMgr(cas.getJCas().getCasImpl()); typeOS.writeObject(casMgrSerializer); } catch (CASException e) { throw new IOException(e); } typeOS.flush(); dos.flush(); dos.finish(); aOS.writeInt(bos.size()); bos.writeTo(aOS); aOS.flush(); } }
private AlignedString getAlignedString(JCas aSomeCase, String from, String to) throws AnalysisEngineProcessException, CASException { CAS baseCas = aSomeCase.getCasImpl().getBaseCAS(); // Try to get the AlignedString for the current JCas. AlignmentStorage asstore = AlignmentStorage.getInstance(); AlignedString as = asstore.get(baseCas, to, from); if (as == null) { // Attempt to reconstruct the alignment from the SofaChangeAnnotations. // This only works when they have not been altered in the mean time. ExtendedLogger logger = getLogger(); if (logger.isInfoEnabled()) { logger.info("No mapping found from [" + from + "] to [" + to + "] on [" + baseCas.hashCode() + "]. " + "Restoring mapping from SofaChangeAnnotation found in [" + to + "]." ); } JCas view = aSomeCase.getCas().getView(to).getJCas(); as = AlignmentFactory.createAlignmentsFor(view); } // If there is none we have to fail. Practically this should never happen // when the alignment state is reconstructed in the previous step. if (as == null) { throw new AnalysisEngineProcessException(new IllegalStateException( "No mapping found from [" + from + "] to [" + to + "] on [" + baseCas.hashCode() + "]")); } return as; }
public void releaseCas(AbstractCas aCAS) { if (!(aCAS instanceof CASImpl) && !(aCAS instanceof JCas)) { throw new UIMARuntimeException(UIMARuntimeException.UNSUPPORTED_CAS_INTERFACE, new Object[] {aCAS.getClass()}); } CASImpl baseCas = (aCAS instanceof JCas) ? ((JCas)aCAS).getCasImpl().getBaseCAS() : ((CASImpl)aCAS).getBaseCAS(); if (baseCas.containsCasState(CasState.UIMA_AS_WAIT_4_RESPONSE)) { throw new UIMARuntimeException(UIMARuntimeException.CAS_RELEASE_NOT_ALLOWED_WHILE_WAITING_FOR_UIMA_AS, new Object[0]); } CasPool pool = mCasToCasPoolMap.get(baseCas); if (pool == null) { // CAS doesn't belong to this CasManager! throw new UIMARuntimeException(UIMARuntimeException.CAS_RELEASED_TO_WRONG_CAS_MANAGER, new Object[0]); } else { //see if we have a UimaContext that we can notify that CAS was release UimaContextAdmin uc = (UimaContextAdmin)mCasToUimaContextMap.get(baseCas); if (uc != null) { uc.returnedCAS(aCAS); } //release the CAS pool.releaseCas((CAS) aCAS); } }
private void storeReferencesAndTargetsInMap(Map<Integer, CoreferenceLink> aReferencesMap, eu.clarin.weblicht.wlfxb.tc.api.ReferencedEntity entity, TextCorpus aCorpusData, Map<String, Token> aTokens, JCas aJcas) { for (Reference reference : entity.getReferences()) { StringBuilder sbTokens = new StringBuilder(); for (eu.clarin.weblicht.wlfxb.tc.api.Token token : aCorpusData.getReferencesLayer() .getTokens(reference)) { sbTokens.append(token.getID()).append(" "); } String[] referenceTokens = sbTokens.toString().split(" "); int begin = getOffsets(referenceTokens, aTokens)[0]; int end = getOffsets(referenceTokens, aTokens)[1]; CoreferenceLink link = new CoreferenceLink(aJcas); link.setBegin(begin); link.setEnd(end); String referencesType = reference.getType() == null ? "nam" : reference.getType(); link.setReferenceType(referencesType); if (reference.getRelation() != null) { link.setReferenceRelation(reference.getRelation()); } link.addToIndexes(); aReferencesMap.put(aJcas.getCasImpl().ll_getFSRef(link), link); } }
private void storeReferencesAndTargetsInMap(Map<Integer, CoreferenceLink> aReferencesMap, eu.clarin.weblicht.wlfxb.tc.api.ReferencedEntity entity, TextCorpus aCorpusData, Map<String, Token> aTokens, JCas aJcas) { for (Reference reference : entity.getReferences()) { StringBuilder sbTokens = new StringBuilder(); for (eu.clarin.weblicht.wlfxb.tc.api.Token token : aCorpusData.getReferencesLayer() .getTokens(reference)) { sbTokens.append(token.getID()).append(" "); } String[] referenceTokens = sbTokens.toString().split(" "); int begin = getOffsets(referenceTokens, aTokens)[0]; int end = getOffsets(referenceTokens, aTokens)[1]; CoreferenceLink link = new CoreferenceLink(aJcas); link.setBegin(begin); link.setEnd(end); String referencesType = reference.getType() == null ? "nam" : reference.getType(); link.setReferenceType(referencesType); if (reference.getRelation() != null) { link.setReferenceRelation(reference.getRelation()); } link.addToIndexes(); aReferencesMap.put(aJcas.getCasImpl().ll_getFSRef(link), link); } }
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); } }
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());