Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Vision BatchAnnotateFiles endpoint #966

Merged

Conversation

florian-3ap
Copy link
Contributor

fixes #844

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! It looks very reasonable. I just added a few minor comments.

public String extractTextFromFile(Resource fileResource, String mimeType) {
AnnotateFileResponse response = analyzeFile(fileResource, mimeType, Type.TEXT_DETECTION);

List<AnnotateImageResponse> annotateImageResponses = response.getResponsesList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 10 lines of code below are the same as what we need to do for extractTextFromImage and should be refactored into a shared private utility method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to address this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest changes, the 10 lines below are not the exact same anymore. The return value changed now to a list of strings instead of a single string. Do you think there are still some lines left that are worth moving into a separate utility method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually got me thinking, for the sake of simplicity of use, maybe we should just return a single concatenated string, separated by newlines, or maybe a customizable separator that can be configured on the class level. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this really depends on what the caller is doing with the extracted text. If you want to process the text page by page it does not make too much sense to merge it into one string. But by returning a list of strings you leave the option open to the caller how he then wants to handle the response.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just wondering if the most common usecase would be to process only 1 page anyway. In that case, a list would make it a bit more verbose to use. Which option seems more convenient for your usecase, for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say, that processing one-page PDFs are more common than processing multiple pages. In our current usecase we need to be able to process both (single and multi-page) documents.

Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! Code looks good in general.
I only have one concern about extractTextFromFile() that file can have multiple pages, details in comment below.
Additionally, I would suggest to add an integration test or a case in the existing sample code if possible.

@florian-3ap
Copy link
Contributor Author

florian-3ap commented Mar 1, 2022

Thanks for contributing! Code looks good in general.
I only have one concern about extractTextFromFile() that file can have multiple pages, details in comment below.
Additionally, I would suggest to add an integration test or a case in the existing sample code if possible.

I enhanced the spring-cloud-gcp-vision-api-sample with a PDF example. It's now working with single-page and also multi-page PDFs.

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code looks good, except for one minor comment that's unresolved.

If it's not too much to ask, two more things would be ideal:

  1. Can you add an integration test for the sample endpoint?
  2. Reference documentation in vision.adoc should be updated to describe the new functionality.

Thanks!

public String extractTextFromFile(Resource fileResource, String mimeType) {
AnnotateFileResponse response = analyzeFile(fileResource, mimeType, Type.TEXT_DETECTION);

List<AnnotateImageResponse> annotateImageResponses = response.getResponsesList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to address this comment?

Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added sample looks great. Made a few minor comments below.
Can you please also add to the existing Vision doc here with the newly added functionalities in CloudVisionTemplate? This way they are discoverable by more users.

docs/src/main/asciidoc/vision.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/vision.adoc Show resolved Hide resolved
public String extractTextFromFile(Resource fileResource, String mimeType) {
AnnotateFileResponse response = analyzeFile(fileResource, mimeType, Type.TEXT_DETECTION);

List<AnnotateImageResponse> annotateImageResponses = response.getResponsesList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually got me thinking, for the sake of simplicity of use, maybe we should just return a single concatenated string, separated by newlines, or maybe a customizable separator that can be configured on the class level. What do you think?

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-3ap Thank you so much for this contribution and your patience with the reviews!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

86.4% 86.4% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc addition looks great to me! Thank you for contributing!

@zhumin8 zhumin8 merged commit 63182a5 into GoogleCloudPlatform:main Mar 3, 2022
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
zhumin8 added a commit that referenced this pull request May 18, 2023
File was created in #966, most recent change #1871.
zhumin8 added a commit that referenced this pull request Jun 5, 2023
File was created in #966, most recent change #1871.
zhumin8 added a commit that referenced this pull request Jun 5, 2023
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.

Support "Annotate File" endpoint
3 participants