Search in sources :

Example 6 with GoogleStorageLocation

use of org.springframework.cloud.gcp.storage.GoogleStorageLocation in project spring-cloud-gcp by spring-cloud.

the class DocumentOcrTemplateIntegrationTests method testDocumentOcrTemplate.

@Test
public void testDocumentOcrTemplate() throws ExecutionException, InterruptedException, InvalidProtocolBufferException, TimeoutException {
    GoogleStorageLocation document = GoogleStorageLocation.forFile("vision-integration-test-bucket", "test.pdf");
    GoogleStorageLocation outputLocationPrefix = GoogleStorageLocation.forFile("vision-integration-test-bucket", "it_output/test-");
    ListenableFuture<DocumentOcrResultSet> result = this.documentOcrTemplate.runOcrForDocument(document, outputLocationPrefix);
    DocumentOcrResultSet ocrPages = result.get(5, TimeUnit.MINUTES);
    String page1Text = ocrPages.getPage(1).getText();
    assertThat(page1Text).contains("Hello World. Is mayonnaise an instrument?");
    String page2Text = ocrPages.getPage(2).getText();
    assertThat(page2Text).contains("Page 2 stuff");
    ArrayList<String> pageContent = new ArrayList<>();
    Iterator<TextAnnotation> pageIterator = ocrPages.getAllPages();
    while (pageIterator.hasNext()) {
        pageContent.add(pageIterator.next().getText());
    }
    assertThat(pageContent).containsExactly("Hello World. Is mayonnaise an instrument?\n", "Page 2 stuff\n", "Page 3 stuff\n", "Page 4 stuff\n");
}
Also used : DocumentOcrResultSet(org.springframework.cloud.gcp.vision.DocumentOcrResultSet) ArrayList(java.util.ArrayList) GoogleStorageLocation(org.springframework.cloud.gcp.storage.GoogleStorageLocation) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) Test(org.junit.Test)

Aggregations

GoogleStorageLocation (org.springframework.cloud.gcp.storage.GoogleStorageLocation)6 Test (org.junit.Test)4 DocumentOcrResultSet (org.springframework.cloud.gcp.vision.DocumentOcrResultSet)4 WriteChannel (com.google.cloud.WriteChannel)1 BlobId (com.google.cloud.storage.BlobId)1 BlobInfo (com.google.cloud.storage.BlobInfo)1 AsyncBatchAnnotateFilesResponse (com.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse)1 TextAnnotation (com.google.cloud.vision.v1.TextAnnotation)1 ArrayList (java.util.ArrayList)1 Resource (org.springframework.core.io.Resource)1 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1