private void copyAnnotations(JCas jCasSrc, JCas jCasDst) { CasCopier copier = new CasCopier(jCasSrc.getCas(), jCasDst.getCas()); for (Sentence anSrc : JCasUtil.select(jCasSrc, Sentence.class)) { Sentence anDst = (Sentence) copier.copyFs(anSrc); anDst.addToIndexes(); } for (Token anSrc : JCasUtil.select(jCasSrc, Token.class)) { Token anDst = (Token) copier.copyFs(anSrc); anDst.addToIndexes(); } for (POS anSrc : JCasUtil.select(jCasSrc, POS.class)) { POS anDst = (POS) copier.copyFs(anSrc); anDst.addToIndexes(); } } }
/** * Does a complete deep copy of one CAS into another CAS. The contents of each view * in the source CAS will be copied to the same-named view in the destination CAS. If * the view does not already exist it will be created. All FeatureStructures that are * indexed in a view in the source CAS will become indexed in the same-named view in the * destination CAS. * * Note: If the feature structure and/or feature is not defined in the type system of * the destination CAS, the copy will fail (in other words, the lenient setting is false, * by default). * * @param aSrcCas * the CAS to copy from * @param aDestCas * the CAS to copy to * @param aCopySofa * if true, the sofa data and mimeType of each view will be copied. If false they will not. */ public static void copyCas(CAS aSrcCas, CAS aDestCas, boolean aCopySofa) { copyCas(aSrcCas, aDestCas, aCopySofa, false); }
/** * Does a deep copy of the contents of one CAS View into another CAS's same-named-view * If the destination view already exists in the destination CAS, * then it will be the target of the copy. Otherwise, a new view will be created with * that name and will become the target of the copy. All FeatureStructures * (except for those dropped because the target type system doesn't have the needed type) that are indexed * in the source CAS view will become indexed in the target view. * Cross-view references may result in creating additional views in the destination CAS; * for these views, any Sofa data in the source is *not* copied. Any views created because * of cross-view references will have the same view name as in the source. * * @param aSrcCasViewName the name of the view in the source CAS to copy from * @param aCopySofa if true, the sofa data and mimeType will be copied. If false they will not. */ public void copyCasView(String aSrcCasViewName, boolean aCopySofa) { copyCasView(getOrCreateView(originalSrcCas, aSrcCasViewName), aCopySofa); }
CasCopier copier = new CasCopier(aSrcCas, aDestCas, lenient); while (viewIterator.hasNext()) { CAS view = viewIterator.next(); copier.copyCasView(view, aCopySofa);
protected void afterProcess(JCas aInput, JCas aOutput) { // Copy the annotation types mentioned in PARAM_TYPES_TO_COPY // We have do do this in the afterProcess() phase, because otherwise the SofA in the // target CAS does not exist yet. CAS inputCas = aInput.getCas(); CasCopier copier = new CasCopier(inputCas, aOutput.getCas()); Feature mDestSofaFeature = aOutput.getTypeSystem() .getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA); for (String typeName : typesToCopy) { for (FeatureStructure fs : selectFS(inputCas, getType(inputCas, typeName))) { if (!copier.alreadyCopied(fs)) { FeatureStructure fsCopy = copier.copyFs(fs); // Make sure that the sofa annotation in the copy is set if (fs instanceof AnnotationBaseFS) { FeatureStructure sofa = fsCopy.getFeatureValue(mDestSofaFeature); if (sofa == null) { fsCopy.setFeatureValue(mDestSofaFeature, aOutput.getSofa()); } } aOutput.addFsToIndexes(fsCopy); } } } }
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); }
/** * Note: if lenient is in effect, this method will return false for * FSs which are not copied because the target doesn't have that type. * It also returns false for sofa FSs and the documentAnnotation FS. * @param aFS a feature structure * @return true if the given FS has already been copied using this CasCopier. */ public boolean alreadyCopied(FeatureStructure aFS) { return alreadyCopied(((FeatureStructureImpl)aFS).getAddress()); }
try { final JCas sourceView = sourceCas.getView( sourceViewName ); final CasCopier copier = new CasCopier( sourceCas.getCas(), patientCas.getCas() ); copier.copyCasView( sourceView.getCas(), viewInfo.getViewCode(), true ); _patientViewInfos.putIfAbsent( patientId, new ArrayList<>() ); _patientViewInfos.get( patientId ).add( viewInfo );
CAS outputCas = aOutput.getCas(); CasCopier copier = new CasCopier(inputCas, aOutput.getCas()); if (!copier.alreadyCopied(fs)) { FeatureStructure fsCopy = copier.copyFs(fs);
goldMentions.addAll(JCasUtil.select(goldView, EntityMention.class)); goldMentions.addAll(JCasUtil.select(goldView, Modifier.class)); CasCopier copier = new CasCopier(goldView.getCas(), systemView.getCas()); for (IdentifiedAnnotation goldMention : goldMentions) { Annotation copy = (Annotation) copier.copyFs(goldMention); Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa"); copy.setFeatureValue(sofaFeature, systemView.getSofa());
CasCopier cc = new CasCopier(inView, outView, true); cc.copyCasView(inView, outputView, true); try { writeXmi(outView, file);
private void greedyCopy(JCas existingCas, JCas emptyCas) { // nothing 'greedy' about the default implementation, which copies everything. CasCopier.copyCas(existingCas.getCas(), emptyCas.getCas(), true); }
/** * Does a deep copy of the contents of one CAS View into another CAS view, * with a possibly different name. * All FeatureStructures * (except for those dropped because the target type system doesn't have the needed type) that are indexed * in the source CAS view will become indexed in the target view. * Cross-view references may result in creating additional views in the destination CAS; * for these views, any Sofa data in the source is *not* copied. Any views created because * of cross-view references will have the same view name as in the source. * * @param aSrcCasViewName The name of the view in the Source CAS to copy from * @param aTgtCasView The view in the destination CAS to copy into * @param aCopySofa if true, the sofa data and mimeType will be copied. If false they will not. */ public void copyCasView(String aSrcCasViewName, CAS aTgtCasView, boolean aCopySofa) { copyCasView(getOrCreateView(originalSrcCas, aSrcCasViewName), aTgtCasView, aCopySofa); }
goldMentions.addAll(JCasUtil.select(goldView, EntityMention.class)); goldMentions.addAll(JCasUtil.select(goldView, Modifier.class)); CasCopier copier = new CasCopier(goldView.getCas(), systemView.getCas()); for (IdentifiedAnnotation goldMention : goldMentions) { Annotation copy = (Annotation) copier.copyFs(goldMention); Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa"); copy.setFeatureValue(sofaFeature, systemView.getSofa());
CAS aCas = aJCas.getCas(); CasCopier textCopier = new CasCopier(textCas, aCas); CasCopier hypoCopier = new CasCopier(hypoCas, aCas); textCopier.copyCasView(textCas.getView(LAP_ImplBase.TEXTVIEW), true); hypoCopier.copyCasView(hypoCas.getView(LAP_ImplBase.HYPOTHESISVIEW), true);
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try { value = JCasFactory.createJCas(); } catch (UIMAException e) { throw new AnalysisEngineProcessException(e); } DocumentMetaData.copy(aJCas, value); CasCopier.copyCas(aJCas.getCas(), value.getCas(), true); }
/** * Does a deep copy of the contents of one CAS View into another CAS view, * with a possibly different name. * If the destination view already exists in the destination CAS, * then it will be the target of the copy. Otherwise, a new view will be created with * that name and will become the target of the copy. * All FeatureStructures * (except for those dropped because the target type system doesn't have the needed type) that are indexed * in the source CAS view will become indexed in the target view. * Cross-view references may result in creating additional views in the destination CAS; * for these views, any Sofa data in the source is *not* copied. Any views created because * of cross-view references will have the same view name as in the source. * * @param aSrcCasView The view in the source to copy from * @param aTgtCasViewName The name of the view in the destination CAS to copy into * @param aCopySofa if true, the sofa data and mimeType will be copied. If false they will not. */ public void copyCasView(CAS aSrcCasView, String aTgtCasViewName, boolean aCopySofa) { copyCasView(aSrcCasView, getOrCreateView(originalTgtCas, aTgtCasViewName), aCopySofa); }
goldMentions.addAll(JCasUtil.select(goldView, EntityMention.class)); goldMentions.addAll(JCasUtil.select(goldView, Modifier.class)); CasCopier copier = new CasCopier(goldView.getCas(), systemView.getCas()); for (IdentifiedAnnotation goldMention : goldMentions) Annotation copy = (Annotation) copier.copyFs(goldMention); Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa"); copy.setFeatureValue(sofaFeature, systemView.getSofa());
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try { value = JCasFactory.createJCas(); } catch (UIMAException e) { throw new AnalysisEngineProcessException(e); } try { DocumentMetaData.copy(aJCas, value); } catch (IllegalArgumentException e) { // Ignore missing DocumentMetaData } CasCopier.copyCas(aJCas.getCas(), value.getCas(), true); }
goldMentions.addAll(JCasUtil.select(goldView, EntityMention.class)); goldMentions.addAll(JCasUtil.select(goldView, Modifier.class)); CasCopier copier = new CasCopier(goldView.getCas(), systemView.getCas()); for (IdentifiedAnnotation goldMention : goldMentions) Annotation copy = (Annotation) copier.copyFs(goldMention); Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa"); copy.setFeatureValue(sofaFeature, systemView.getSofa());