As this issue in python section:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues/4425
AnalyzeSyntax request is returning -1 for all offsets. I'm using Ruby Natural Language Client Library v0.28.0
The documentation says that I need to send the encoding type to get the offsets I want.
So I'm trying to do that writing:
syntax = language.analyze_syntax content: text, type: :PLAIN_TEXT, encoding_type: 'UTF8'
but I'm getting this error:
Unknown field name 'encoding_type' in initialization map entry.
How Is the correct form to write the request?
I'm trying to send the encoding_type: 'UTF8'.
Thanks in advance.
Also I follow this documentationof v0.25.0:
https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/v0.25.0/google%2Fcloud%2Flanguage%2Fv1%2Flanguageserviceclient?
method=analyze_syntax-instance
And tried to do the following:
document = { content: text, type: :PLAIN_TEXT }
encoding_type = Google::Cloud::Language::V1::EncodingType::UTF8
syntax = language.analyze_syntax(document, encoding_type)
But I got this error:
wrong number of arguments (given 2, expected 1)
Hi @jicardu, 0.28.0 introduced some breaking changes; encoding_type is now a keyword argument, so your request should look like:
document = { content: text, type: :PLAIN_TEXT }
encoding_type = Google::Cloud::Language::V1::EncodingType::UTF8
syntax = language.analyze_syntax(document, encoding_type: encoding_type)
The documentation for the latest version of the client library is available here; I noticed you were looking at documentation for the google-cloud 0.25.0 metapackage (which bundles together many Google Cloud client libraries), whose versioning doesn't move in sync with the google-cloud-language gem.
Hi @jicardu, thank you for opening this issue. The core problem you are having is that you are not providing the correct value for encoding_type. In your first example you are providing a string value for the encoding_type.
syntax = language.analyze_syntax content: text, type: :PLAIN_TEXT, encoding_type: 'UTF8'
Providing a string is incorrect, and this is why the offset is being returned as -1. Instead, the value for encoding_type can be a symbol, as are already correctly providing a symbol for type. With this change, you should see a valid offset being returned.
syntax = language.analyze_syntax content: text, type: :PLAIN_TEXT, encoding_type: :UTF8
In your second example, you are using the other valid value, one of the Ruby constants defined in the EncodingType module. However, in that example, you are passing it as a positional argument, and not as a named argument as was used in the first code example.
document = { content: text, type: :PLAIN_TEXT }
encoding_type = Google::Cloud::Language::V1::EncodingType::UTF8
syntax = language.analyze_syntax(document, encoding_type)
If the encoding type value is passed as a named argument then a valid offset should be returned.
document = { content: text, type: :PLAIN_TEXT }
encoding_type = Google::Cloud::Language::V1::EncodingType::UTF8
syntax = language.analyze_syntax(document, encoding_type: Google::Cloud::Language::V1::EncodingType::UTF8)
Does this help? Do you have any other questions or concerns?
@geigerj @blowmage Thank you so much!
Most helpful comment
Hi @jicardu, thank you for opening this issue. The core problem you are having is that you are not providing the correct value for
encoding_type. In your first example you are providing a string value for theencoding_type.Providing a string is incorrect, and this is why the offset is being returned as
-1. Instead, the value forencoding_typecan be a symbol, as are already correctly providing a symbol fortype. With this change, you should see a valid offset being returned.In your second example, you are using the other valid value, one of the Ruby constants defined in the
EncodingTypemodule. However, in that example, you are passing it as a positional argument, and not as a named argument as was used in the first code example.If the encoding type value is passed as a named argument then a valid
offsetshould be returned.Does this help? Do you have any other questions or concerns?