-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Refactor _detect_annotation() to support all annotation types. #2712
Refactor _detect_annotation() to support all annotation types. #2712
Conversation
51433d6
to
7d4a998
Compare
7d4a998
to
e766ac9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM though ISTM you should be doing
features = [feature]
in _detect_annotation
:type feature: :class:`~google.cloud.vision.feature.Feature` | ||
:param feature: The ``Feature`` indication the type of annotation to | ||
perform. | ||
:type features: list of:class:`~google.cloud.vision.feature.Feature` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -85,28 +85,58 @@ def source(self): | |||
""" | |||
return self._source | |||
|
|||
def _detect_annotation(self, feature): | |||
def _detect_annotation(self, features): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
reverse_types = { | ||
'FACE_DETECTION': 'faceAnnotations', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return detected_objects[0] | ||
return detected_objects | ||
|
||
@staticmethod |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._entity_from_response_type(feature.feature_type, results)) | ||
|
||
if len(detected_objects) == 1: | ||
return detected_objects[0] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
result = results[feature_key] | ||
detected_objects.append(SafeSearchAnnotation.from_api_repr(result)) | ||
else: | ||
for result in results[feature_key]: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
detected_objects.append(detected_object) | ||
feature_key = reverse_types[feature_type] | ||
|
||
if feature_type == 'FACE_DETECTION': |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
if feature_type == 'FACE_DETECTION': | ||
for face in results[feature_key]: | ||
detected_objects.append(Face.from_api_repr(face)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
detected_objects.append(SafeSearchAnnotation.from_api_repr(result)) | ||
else: | ||
for result in results[feature_key]: | ||
detected_objects.append(EntityAnnotation.from_api_repr(result)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Regarding your comment about if not isinstance(features, list):
features = [features] |
'LOGO_DETECTION': 'logoAnnotations', | ||
_SAFE_SEARCH_DETECTION: 'safeSearchAnnotation', | ||
'TEXT_DETECTION': 'textAnnotations', | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
No, just make your callers obey the signature. So if it accepts one feature (which all the current callers so) then they send one feature. However, as I mentioned before, just leave the change in. |
1bfd25f
to
f164c3f
Compare
Squished. Once the build goes green I'll merge. |
f164c3f
to
83b128a
Compare
…quests Refactor _detect_annotation() to support all annotation types.
Refactor _detect_annotation() to support all annotation types.
This is a step towards adding the manual detect method.
See: #2697