Skip to content

Commit

Permalink
#4347 - CAS doctor fails to generate a proper report on projects not …
Browse files Browse the repository at this point in the history
…containing INITIAL_CASes

- Disable implicit CAS doctor check when creating the INITIAL_CAS since either CAS Doctor on the panel is run immediately after or the usual option CAS Doctor check is run on document open
  • Loading branch information
reckart committed Dec 5, 2023
1 parent 7e899cc commit 6de7202
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public CAS createOrReadInitialCas(SourceDocument aDocument, CasUpgradeMode aUpgr
// adding this feature, the existing projects do not yet have initial CASes, so
// we create them here lazily
try {
return importExportService.importCasFromFile(
return importExportService.importCasFromFileNoChecks(
getSourceDocumentFile(aDocument), aDocument,
aFullProjectTypeSystem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ CAS importCasFromFile(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException;

CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument)
throws UIMAException, IOException;

CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException;

/**
* Exports the given CAS to a file on disk.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument,
public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
var cas = importCasFromFileNoChecks(aFile, aDocument, aFormat, aFullProjectTypeSystem);

// Convert the source document to CAS
var format = getReadableFormatById(aFormat).orElseThrow(
() -> new IOException("No reader available for format [" + aFormat + "]"));

runCasDoctorOnImport(aDocument, format, cas);

return cas;
}

@Override
public CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument)
throws UIMAException, IOException
{
return importCasFromFileNoChecks(aFile, aDocument, aDocument.getFormat(), null);
}

@Override
public CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
return importCasFromFileNoChecks(aFile, aDocument, aDocument.getFormat(),
aFullProjectTypeSystem);
}

private CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
TypeSystemDescription tsd = aFullProjectTypeSystem;

Expand All @@ -311,11 +342,11 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aForma
}

// Convert the source document to CAS
FormatSupport format = getReadableFormatById(aFormat).orElseThrow(
var format = getReadableFormatById(aFormat).orElseThrow(
() -> new IOException("No reader available for format [" + aFormat + "]"));

// Prepare a CAS with the project type system
CAS cas = WebAnnoCasUtil.createCas(tsd);
var cas = WebAnnoCasUtil.createCas(tsd);
format.read(aDocument.getProject(), WebAnnoCasUtil.getRealCas(cas), aFile);

// Create sentence / token annotations if they are missing - sentences first because
Expand All @@ -327,8 +358,6 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aForma
cas.getAnnotationIndex(getType(cas, Token.class)).size(),
cas.getAnnotationIndex(getType(cas, Sentence.class)).size(), aFile, aFile.length());

runCasDoctorOnImport(aDocument, format, cas);

return cas;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm)

try {
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER,
(doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet),
(doc, user) -> createOrReadInitialCasWithoutSavingOrChecks(doc, messageSet),
(cas) -> casDoctor.repair(project, cas, messageSet.messages), //
true);
}
Expand Down Expand Up @@ -257,7 +257,7 @@ private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm)
try {
objectCount++;
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER,
(doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet),
(doc, user) -> createOrReadInitialCasWithoutSavingOrChecks(doc, messageSet),
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), //
false);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm)
aTarget.add(this);
}

private CAS createOrReadInitialCasWithoutSaving(SourceDocument aDocument,
private CAS createOrReadInitialCasWithoutSavingOrChecks(SourceDocument aDocument,
LogMessageSet aMessageSet)
throws IOException, UIMAException
{
Expand All @@ -350,8 +350,8 @@ private CAS createOrReadInitialCasWithoutSaving(SourceDocument aDocument,
UNMANAGED_NON_INITIALIZING_ACCESS);
}

CAS cas = importExportService
.importCasFromFile(documentService.getSourceDocumentFile(aDocument), aDocument);
var cas = importExportService.importCasFromFileNoChecks(
documentService.getSourceDocumentFile(aDocument), aDocument);
aMessageSet.messages.add(
LogMessage.info(getClass(), "Created initial CAS for [%s]", aDocument.getName()));
return cas;
Expand Down

0 comments on commit 6de7202

Please sign in to comment.