test_class.declarator: service
test_class.modifier: private
test_class.original_string: private DocumentConversionService service;
test_class.type: DocumentConversionService
test_class.var_name: service
test_class.file: common/src/test/java/uk/ac/kcl/iop/brc/core/pipeline/common/service/DocumentConversionServiceTest.java
test_class.identifier: DocumentConversionServiceTest
test_case.body: @Test
      public void shouldTryOCRByConvertingToTiff() throws TikaException, IOException, SAXException, CanNotProcessCoordinateException {
          InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("test_ocr_pdf.pdf");
          byte[] bytes = IOUtils.toByteArray(resourceAsStream);
  
          String text = service.tryOCRByConvertingToTiff(new DNCWorkCoordinate().sourceTable("table1"), bytes);
          System.out.println(text);
  
          assertTrue(text.contains("This is a random"));
      }
test_case.class_method_signature: DocumentConversionServiceTest.shouldTryOCRByConvertingToTiff()
test_case.full_signature: @Test public void shouldTryOCRByConvertingToTiff()
test_case.identifier: shouldTryOCRByConvertingToTiff
test_case.invocations: getResourceAsStream getClassLoader getClass toByteArray tryOCRByConvertingToTiff sourceTable println assertTrue contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void shouldTryOCRByConvertingToTiff()
focal_class.declarator: logger = Logger.getLogger(DocumentConversionService.class)
focal_class.modifier: private
focal_class.original_string: private Logger logger = Logger.getLogger(DocumentConversionService.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: imageMagickInstalled = null
focal_class.modifier: public
focal_class.original_string: public Boolean imageMagickInstalled = null;
focal_class.type: Boolean
focal_class.var_name: imageMagickInstalled
focal_class.declarator: config = new TesseractOCRConfig(getClass().getClassLoader().getResourceAsStream("TesseractOCRConfig.properties"))
focal_class.modifier: private
focal_class.original_string: private TesseractOCRConfig config = new TesseractOCRConfig(getClass().getClassLoader().getResourceAsStream("TesseractOCRConfig.properties"));
focal_class.type: TesseractOCRConfig
focal_class.var_name: config
focal_class.file: common/src/main/java/uk/ac/kcl/iop/brc/core/pipeline/common/service/DocumentConversionService.java
focal_class.identifier: DocumentConversionService
focal_class.class_method_signature: DocumentConversionService.convertToText(byte[] data)
focal_class.full_signature: public String convertToText(byte[] data)
focal_class.identifier: convertToText
focal_class.modifiers: public
focal_class.parameters: (byte[] data)
focal_class.return: String
focal_class.signature: String convertToText(byte[] data)
focal_class.class_method_signature: DocumentConversionService.convertToXHTML(byte[] data)
focal_class.full_signature: public String convertToXHTML(byte[] data)
focal_class.identifier: convertToXHTML
focal_class.modifiers: public
focal_class.parameters: (byte[] data)
focal_class.return: String
focal_class.signature: String convertToXHTML(byte[] data)
focal_class.class_method_signature: DocumentConversionService.convertWithHandler(byte[] data, DefaultHandler handler)
focal_class.full_signature: private String convertWithHandler(byte[] data, DefaultHandler handler)
focal_class.identifier: convertWithHandler
focal_class.modifiers: private
focal_class.parameters: (byte[] data, DefaultHandler handler)
focal_class.return: String
focal_class.signature: String convertWithHandler(byte[] data, DefaultHandler handler)
focal_class.class_method_signature: DocumentConversionService.tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)
focal_class.full_signature: public String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)
focal_class.identifier: tryOCRByConvertingToTiff
focal_class.modifiers: public
focal_class.parameters: (DNCWorkCoordinate coordinate, byte[] bytes)
focal_class.return: String
focal_class.signature: String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)
focal_class.class_method_signature: DocumentConversionService.getOCRResultFromTiff(File tiffFile)
focal_class.full_signature: private String getOCRResultFromTiff(File tiffFile)
focal_class.identifier: getOCRResultFromTiff
focal_class.modifiers: private
focal_class.parameters: (File tiffFile)
focal_class.return: String
focal_class.signature: String getOCRResultFromTiff(File tiffFile)
focal_class.class_method_signature: DocumentConversionService.validateImageMagick()
focal_class.full_signature: private void validateImageMagick()
focal_class.identifier: validateImageMagick
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void validateImageMagick()
focal_class.class_method_signature: DocumentConversionService.hasImageMagick()
focal_class.full_signature: private boolean hasImageMagick()
focal_class.identifier: hasImageMagick
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean hasImageMagick()
focal_class.class_method_signature: DocumentConversionService.getImageMagickProg()
focal_class.full_signature: private String getImageMagickProg()
focal_class.identifier: getImageMagickProg
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getImageMagickProg()
focal_class.class_method_signature: DocumentConversionService.makeTiffFromPDF(DNCWorkCoordinate coordinate, File input)
focal_class.full_signature: private File makeTiffFromPDF(DNCWorkCoordinate coordinate, File input)
focal_class.identifier: makeTiffFromPDF
focal_class.modifiers: private
focal_class.parameters: (DNCWorkCoordinate coordinate, File input)
focal_class.return: File
focal_class.signature: File makeTiffFromPDF(DNCWorkCoordinate coordinate, File input)
focal_class.class_method_signature: DocumentConversionService.logStream(final InputStream stream)
focal_class.full_signature: private void logStream(final InputStream stream)
focal_class.identifier: logStream
focal_class.modifiers: private
focal_class.parameters: (final InputStream stream)
focal_class.return: void
focal_class.signature: void logStream(final InputStream stream)
focal_method.body: public String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes) throws CanNotProcessCoordinateException {
          validateImageMagick();
          File pdfFile = null;
          File tiffFile = null;
          try {
              pdfFile = File.createTempFile(coordinate.getFileName(), ".pdf");
              FileUtils.writeByteArrayToFile(pdfFile, bytes);
              tiffFile = makeTiffFromPDF(coordinate, pdfFile);
              if (tiffFile == null) {
                  throw new CanNotProcessCoordinateException("Could not convert PDF to Tiff: " + coordinate);
              }
              return getOCRResultFromTiff(tiffFile);
          } catch (Exception e) {
              logger.error(e.getMessage());
              e.printStackTrace();
          } finally {
              FileTools.deleteFiles(pdfFile, tiffFile);
          }
          throw new CanNotProcessCoordinateException("Could not convert PDF to Tiff: " + coordinate);
      }
focal_method.class_method_signature: DocumentConversionService.tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)
focal_method.full_signature: public String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)
focal_method.identifier: tryOCRByConvertingToTiff
focal_method.invocations: validateImageMagick createTempFile getFileName writeByteArrayToFile makeTiffFromPDF getOCRResultFromTiff error getMessage printStackTrace deleteFiles
focal_method.modifiers: public
focal_method.parameters: (DNCWorkCoordinate coordinate, byte[] bytes)
focal_method.return: String
focal_method.signature: String tryOCRByConvertingToTiff(DNCWorkCoordinate coordinate, byte[] bytes)