Skip to content

Conversation

@manu-schaaf
Copy link
Member

Previously, the implementations for setting source & target view differentiated between drivers, most notably for the UIMA driver as UIMA Analysis Engines do not support different source and target views. Additionally, designating a non-existing target view in all the other drivers would only create an empty view, while the UIMA driver allowed to copy the CAS into the newly created view.

The proposed changes unify these implementations and align their interfaces in pipeline definitions:

final String sourceViewName = pipelineComponent.getSourceView();
final JCas sourceView = jc.getView(sourceViewName);

final String targetViewName = pipelineComponent.getTargetView();
JCas targetView = sourceView;
if (targetViewName != null & !Objects.equals(sourceViewName, targetViewName)) {
    try {
        targetView = jc.getView(targetViewName);
    } catch (CASException | CASRuntimeException e) {
        targetView = jc.createView(targetViewName);
        if (pipelineComponent.getInitializeTargetView()) {
            targetView.setDocumentText(sourceView.getDocumentText());
            targetView.setDocumentLanguage(sourceView.getDocumentLanguage());
            try {
                DocumentMetaData documentMetaData = DocumentMetaData.get(sourceView);
                CasCopier casCopier = new CasCopier(sourceView.getCas(), targetView.getCas());
                casCopier.copyFs(documentMetaData).addToIndexes();
            } catch (IllegalArgumentException ignored) {}
        } else {
            throw e;
        }
    }
}

The associated methods have been updated and, where appropriate, deprecated:

class DUUIPipelineComponent {
    @Deprecated
    public DUUIPipelineComponent withWriteToView(String viewName) {...}
    @Deprecated
    public DUUIPipelineComponent withWriteToView(String viewName, boolean initializeTargetView) {...}
    @Deprecated
    public String getViewName()
    
    // Added
    public DUUIPipelineComponent withInitializeTargetView(boolean bool) {...}

    // Updated
    public DUUIPipelineComponent withView(String viewName){...}
    public DUUIPipelineComponent withSourceView(String viewName) {...}
    public DUUIPipelineComponent withTargetView(String viewName) {...}
}

@Myyyvothrr
Copy link
Member

Thanks looks good, should be no problem to merge. Is this actually still a draft?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants