Adding more logs
This commit is contained in:
parent
27c90be145
commit
2ba2340081
@ -51,6 +51,9 @@ public class RedactionController implements RedactionResource {
|
|||||||
@Override
|
@Override
|
||||||
public AnalyzeResult analyze(@RequestBody AnalyzeRequest analyzeRequest) {
|
public AnalyzeResult analyze(@RequestBody AnalyzeRequest analyzeRequest) {
|
||||||
|
|
||||||
|
log.info("Starting redaction analysis...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(analyzeRequest.getDocument()))) {
|
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(analyzeRequest.getDocument()))) {
|
||||||
pdDocument.setAllSecurityToBeRemoved(true);
|
pdDocument.setAllSecurityToBeRemoved(true);
|
||||||
|
|
||||||
@ -63,6 +66,8 @@ public class RedactionController implements RedactionResource {
|
|||||||
.getRuleSetId());
|
.getRuleSetId());
|
||||||
|
|
||||||
log.info("Redaction analysis successful...");
|
log.info("Redaction analysis successful...");
|
||||||
|
log.debug("Finishing redaction analysis took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
|
|
||||||
return AnalyzeResult.builder()
|
return AnalyzeResult.builder()
|
||||||
.sectionGrid(classifiedDoc.getSectionGrid())
|
.sectionGrid(classifiedDoc.getSectionGrid())
|
||||||
@ -80,12 +85,17 @@ public class RedactionController implements RedactionResource {
|
|||||||
|
|
||||||
public AnnotateResponse annotate(@RequestBody AnnotateRequest annotateRequest) {
|
public AnnotateResponse annotate(@RequestBody AnnotateRequest annotateRequest) {
|
||||||
|
|
||||||
|
log.info("Starting redaction annotation...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(annotateRequest.getDocument()))) {
|
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(annotateRequest.getDocument()))) {
|
||||||
|
|
||||||
pdDocument.setAllSecurityToBeRemoved(true);
|
pdDocument.setAllSecurityToBeRemoved(true);
|
||||||
dictionaryService.updateDictionary(annotateRequest.getRedactionLog().getRuleSetId());
|
dictionaryService.updateDictionary(annotateRequest.getRedactionLog().getRuleSetId());
|
||||||
annotationService.annotate(pdDocument, annotateRequest.getRedactionLog(), annotateRequest.getSectionGrid());
|
annotationService.annotate(pdDocument, annotateRequest.getRedactionLog(), annotateRequest.getSectionGrid());
|
||||||
|
|
||||||
|
log.debug("Finishing redaction annotation took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
|
||||||
pdDocument.save(byteArrayOutputStream);
|
pdDocument.save(byteArrayOutputStream);
|
||||||
return AnnotateResponse.builder().document(byteArrayOutputStream.toByteArray()).build();
|
return AnnotateResponse.builder().document(byteArrayOutputStream.toByteArray()).build();
|
||||||
@ -100,12 +110,17 @@ public class RedactionController implements RedactionResource {
|
|||||||
@Override
|
@Override
|
||||||
public RedactionResult classify(@RequestBody RedactionRequest pdfSegmentationRequest) {
|
public RedactionResult classify(@RequestBody RedactionRequest pdfSegmentationRequest) {
|
||||||
|
|
||||||
|
log.info("Starting redaction classification...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfSegmentationRequest.getDocument()))) {
|
try (PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfSegmentationRequest.getDocument()))) {
|
||||||
pdDocument.setAllSecurityToBeRemoved(true);
|
pdDocument.setAllSecurityToBeRemoved(true);
|
||||||
|
|
||||||
Document classifiedDoc = pdfSegmentationService.parseDocument(pdDocument);
|
Document classifiedDoc = pdfSegmentationService.parseDocument(pdDocument);
|
||||||
pdfVisualisationService.visualizeClassifications(classifiedDoc, pdDocument);
|
pdfVisualisationService.visualizeClassifications(classifiedDoc, pdDocument);
|
||||||
|
|
||||||
|
log.info("Finishing redaction classification took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
return convert(pdDocument, classifiedDoc.getPages().size(), pdfSegmentationRequest.getRuleSetId());
|
return convert(pdDocument, classifiedDoc.getPages().size(), pdfSegmentationRequest.getRuleSetId());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@ -29,8 +29,10 @@ import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
|
|||||||
import com.iqser.red.service.redaction.v1.model.SectionGrid;
|
import com.iqser.red.service.redaction.v1.model.SectionGrid;
|
||||||
import com.iqser.red.service.redaction.v1.model.SectionRectangle;
|
import com.iqser.red.service.redaction.v1.model.SectionRectangle;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AnnotationService {
|
public class AnnotationService {
|
||||||
@ -40,6 +42,9 @@ public class AnnotationService {
|
|||||||
|
|
||||||
public void annotate(PDDocument document, RedactionLog redactionLog, SectionGrid sectionGrid) throws IOException {
|
public void annotate(PDDocument document, RedactionLog redactionLog, SectionGrid sectionGrid) throws IOException {
|
||||||
|
|
||||||
|
log.info("Annotating document...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
Map<Integer, List<RedactionLogEntry>> redactionLogPerPage = convertRedactionLog(redactionLog);
|
Map<Integer, List<RedactionLogEntry>> redactionLogPerPage = convertRedactionLog(redactionLog);
|
||||||
|
|
||||||
for (int page = 1; page <= document.getNumberOfPages(); page++) {
|
for (int page = 1; page <= document.getNumberOfPages(); page++) {
|
||||||
@ -56,6 +61,8 @@ public class AnnotationService {
|
|||||||
addAnnotations(logEntries, pdPage, page);
|
addAnnotations(logEntries, pdPage, page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Finishing document annotation took: {}.", System.currentTimeMillis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,9 @@ public class DictionaryService {
|
|||||||
|
|
||||||
public void updateDictionary(String ruleSetId) {
|
public void updateDictionary(String ruleSetId) {
|
||||||
|
|
||||||
|
log.info("Updating dictionary...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
long version = dictionaryClient.getVersion(ruleSetId);
|
long version = dictionaryClient.getVersion(ruleSetId);
|
||||||
|
|
||||||
var foundDictionary = dictionariesByRuleSets.get(ruleSetId);
|
var foundDictionary = dictionariesByRuleSets.get(ruleSetId);
|
||||||
@ -45,11 +48,16 @@ public class DictionaryService {
|
|||||||
if (foundDictionary == null || version > foundDictionary.getDictionaryVersion()) {
|
if (foundDictionary == null || version > foundDictionary.getDictionaryVersion()) {
|
||||||
updateDictionaryEntry(ruleSetId, version);
|
updateDictionaryEntry(ruleSetId, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Finishing dictionary update took: {}.", System.currentTimeMillis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateDictionaryEntry(String ruleSetId, long version) {
|
private void updateDictionaryEntry(String ruleSetId, long version) {
|
||||||
|
|
||||||
|
log.info("Updating dictionary entries...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DictionaryRepresentation dictionaryRepresentation = new DictionaryRepresentation();
|
DictionaryRepresentation dictionaryRepresentation = new DictionaryRepresentation();
|
||||||
|
|
||||||
@ -82,10 +90,17 @@ public class DictionaryService {
|
|||||||
log.warn("Got some unknown feignException", e);
|
log.warn("Got some unknown feignException", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Finishing dictionary entries update took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateExternalDictionary(Dictionary dictionary, String ruleSetId) {
|
public void updateExternalDictionary(Dictionary dictionary, String ruleSetId) {
|
||||||
|
|
||||||
|
log.info("Updating external dictionary...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
dictionary.getDictionaryModels().forEach(dm -> {
|
dictionary.getDictionaryModels().forEach(dm -> {
|
||||||
if (dm.isRecommendation() && !dm.getLocalEntries().isEmpty()) {
|
if (dm.isRecommendation() && !dm.getLocalEntries().isEmpty()) {
|
||||||
dictionaryClient.addEntries(dm.getType(), ruleSetId, new ArrayList<>(dm.getLocalEntries()), false);
|
dictionaryClient.addEntries(dm.getType(), ruleSetId, new ArrayList<>(dm.getLocalEntries()), false);
|
||||||
@ -95,6 +110,9 @@ public class DictionaryService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log.info("Finishing external dictionary update took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -51,14 +51,23 @@ public class EntityRedactionService {
|
|||||||
|
|
||||||
public void processDocument(Document classifiedDoc, String ruleSetId, ManualRedactions manualRedactions) {
|
public void processDocument(Document classifiedDoc, String ruleSetId, ManualRedactions manualRedactions) {
|
||||||
|
|
||||||
|
log.info("Processing document...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
dictionaryService.updateDictionary(ruleSetId);
|
dictionaryService.updateDictionary(ruleSetId);
|
||||||
KieContainer container = droolsExecutionService.updateRules(ruleSetId);
|
KieContainer container = droolsExecutionService.updateRules(ruleSetId);
|
||||||
long rulesVersion = droolsExecutionService.getRulesVersion(ruleSetId);
|
long rulesVersion = droolsExecutionService.getRulesVersion(ruleSetId);
|
||||||
|
|
||||||
Dictionary dictionary = dictionaryService.getDeepCopyDictionary(ruleSetId);
|
Dictionary dictionary = dictionaryService.getDeepCopyDictionary(ruleSetId);
|
||||||
|
|
||||||
|
long current = System.currentTimeMillis() - startTime;
|
||||||
|
log.info("Preparing took: {}.", current);
|
||||||
|
|
||||||
Set<Entity> documentEntities = new HashSet<>(findEntities(classifiedDoc, container, manualRedactions, dictionary, false, null));
|
Set<Entity> documentEntities = new HashSet<>(findEntities(classifiedDoc, container, manualRedactions, dictionary, false, null));
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Finding entries took: {}.", current);
|
||||||
|
|
||||||
if (dictionary.hasLocalEntries()) {
|
if (dictionary.hasLocalEntries()) {
|
||||||
|
|
||||||
Map<Integer, Set<Entity>> hintsPerSectionNumber = new HashMap<>();
|
Map<Integer, Set<Entity>> hintsPerSectionNumber = new HashMap<>();
|
||||||
@ -72,6 +81,9 @@ public class EntityRedactionService {
|
|||||||
Set<Entity> foundByLocal = findEntities(classifiedDoc, container, manualRedactions, dictionary, true, hintsPerSectionNumber);
|
Set<Entity> foundByLocal = findEntities(classifiedDoc, container, manualRedactions, dictionary, true, hintsPerSectionNumber);
|
||||||
EntitySearchUtils.addEntitiesWithHigherRank(documentEntities, foundByLocal, dictionary);
|
EntitySearchUtils.addEntitiesWithHigherRank(documentEntities, foundByLocal, dictionary);
|
||||||
EntitySearchUtils.removeEntitiesContainedInLarger(documentEntities);
|
EntitySearchUtils.removeEntitiesContainedInLarger(documentEntities);
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Adding local dictionary annotations took: {}.", current);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entity entity : documentEntities) {
|
for (Entity entity : documentEntities) {
|
||||||
@ -90,10 +102,17 @@ public class EntityRedactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Adding entity position sequence took: {}.", current);
|
||||||
|
|
||||||
dictionaryService.updateExternalDictionary(dictionary, ruleSetId);
|
dictionaryService.updateExternalDictionary(dictionary, ruleSetId);
|
||||||
|
|
||||||
classifiedDoc.setDictionaryVersion(dictionary.getVersion());
|
classifiedDoc.setDictionaryVersion(dictionary.getVersion());
|
||||||
classifiedDoc.setRulesVersion(rulesVersion);
|
classifiedDoc.setRulesVersion(rulesVersion);
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Adjusting rules set took: {}.", current);
|
||||||
|
log.info("Finishing document processing took: {}.", System.currentTimeMillis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,9 @@ import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
|||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RedactionLogCreatorService {
|
public class RedactionLogCreatorService {
|
||||||
@ -48,6 +50,9 @@ public class RedactionLogCreatorService {
|
|||||||
public void createRedactionLog(Document classifiedDoc, int numberOfPages, ManualRedactions manualRedactions,
|
public void createRedactionLog(Document classifiedDoc, int numberOfPages, ManualRedactions manualRedactions,
|
||||||
String ruleSetId) {
|
String ruleSetId) {
|
||||||
|
|
||||||
|
log.info("Creating redaction log...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
||||||
|
|
||||||
for (int page = 1; page <= numberOfPages; page++) {
|
for (int page = 1; page <= numberOfPages; page++) {
|
||||||
@ -58,14 +63,26 @@ public class RedactionLogCreatorService {
|
|||||||
addEntries(classifiedDoc, manualRedactions, page, ruleSetId);
|
addEntries(classifiedDoc, manualRedactions, page, ruleSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long current = System.currentTimeMillis() - startTime;
|
||||||
|
log.info("Adding entries took: {}.", current);
|
||||||
|
|
||||||
if (manualRedactionPages.contains(page)) {
|
if (manualRedactionPages.contains(page)) {
|
||||||
addManualEntries(classifiedDoc, manualRedactions, page, ruleSetId);
|
addManualEntries(classifiedDoc, manualRedactions, page, ruleSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Adding manual entries took: {}.", current);
|
||||||
|
|
||||||
if (!classifiedDoc.getPages().get(page - 1).getImageBounds().isEmpty()) {
|
if (!classifiedDoc.getPages().get(page - 1).getImageBounds().isEmpty()) {
|
||||||
addImageEntries(classifiedDoc, page, ruleSetId);
|
addImageEntries(classifiedDoc, page, ruleSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current = System.currentTimeMillis() - startTime - current;
|
||||||
|
log.info("Adding image entries took: {}.", current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Finishing redaction log creation took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,9 @@ public class PdfSegmentationService {
|
|||||||
|
|
||||||
public Document parseDocument(PDDocument pdDocument) throws IOException {
|
public Document parseDocument(PDDocument pdDocument) throws IOException {
|
||||||
|
|
||||||
|
log.info("Parsing document...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
|
|
||||||
List<Page> pages = new ArrayList<>();
|
List<Page> pages = new ArrayList<>();
|
||||||
@ -91,6 +94,8 @@ public class PdfSegmentationService {
|
|||||||
|
|
||||||
sectionsBuilderService.buildSections(document);
|
sectionsBuilderService.buildSections(document);
|
||||||
|
|
||||||
|
log.info("Finishing document parsing took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,11 +20,17 @@ import com.iqser.red.service.redaction.v1.server.tableextraction.model.AbstractT
|
|||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class SectionsBuilderService {
|
public class SectionsBuilderService {
|
||||||
|
|
||||||
public void buildSections(Document document) {
|
public void buildSections(Document document) {
|
||||||
|
|
||||||
|
log.debug("Building sections...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
List<AbstractTextContainer> chunkWords = new ArrayList<>();
|
List<AbstractTextContainer> chunkWords = new ArrayList<>();
|
||||||
List<Paragraph> chunkBlockList = new ArrayList<>();
|
List<Paragraph> chunkBlockList = new ArrayList<>();
|
||||||
List<Header> headers = new ArrayList<>();
|
List<Header> headers = new ArrayList<>();
|
||||||
@ -97,6 +103,9 @@ public class SectionsBuilderService {
|
|||||||
document.setHeaders(headers);
|
document.setHeaders(headers);
|
||||||
document.setFooters(footers);
|
document.setFooters(footers);
|
||||||
document.setUnclassifiedTexts(unclassifiedTexts);
|
document.setUnclassifiedTexts(unclassifiedTexts);
|
||||||
|
|
||||||
|
log.debug("Finishing section building took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,11 +23,17 @@ import com.iqser.red.service.redaction.v1.server.tableextraction.model.Ruling;
|
|||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
||||||
import com.iqser.red.service.redaction.v1.server.tableextraction.utils.Utils;
|
import com.iqser.red.service.redaction.v1.server.tableextraction.utils.Utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class TableExtractionService {
|
public class TableExtractionService {
|
||||||
|
|
||||||
public void extractTables(CleanRulings cleanRulings, Page page) {
|
public void extractTables(CleanRulings cleanRulings, Page page) {
|
||||||
|
|
||||||
|
log.debug("Extracting tables...");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
List<Cell> cells = findCells(cleanRulings.getHorizontal(), cleanRulings.getVertical());
|
List<Cell> cells = findCells(cleanRulings.getHorizontal(), cleanRulings.getVertical());
|
||||||
|
|
||||||
List<TextBlock> toBeRemoved = new ArrayList<>();
|
List<TextBlock> toBeRemoved = new ArrayList<>();
|
||||||
@ -78,6 +84,9 @@ public class TableExtractionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page.getTextBlocks().removeAll(toBeRemoved);
|
page.getTextBlocks().removeAll(toBeRemoved);
|
||||||
|
|
||||||
|
log.debug("Finishing table extraction took: {}.", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user