googleLanguageR icon indicating copy to clipboard operation
googleLanguageR copied to clipboard

Entity sentiment shows but document sentiment shows NA

Open madilk opened this issue 4 years ago • 4 comments

Hello, I'm not sure if this is an issue or it's just me but here goes. Thanks for creating this package. I'm trying to run Entity sentiment analysis on a column. Here's my API call for it. nlp <- gl_nlp( cleanData$translatedText, nlp_type = "analyzeEntitySentiment", type="PLAIN_TEXT", language="en" )

When I run nlp$entities, I can see entity level sentiment google language r entity sentiment

However, when I try nlp$documentSentiment, I see NA's across all my 5 rows of text data NA for document level sentiment google language R

Can you pls help me understand why would this be the case? and what can I do to improve my code here? Thanks.

madilk avatar Mar 20 '21 18:03 madilk

What if you send it in as one string? The code looks like it will send in each element in your column individually. Try paste(x, collapse = " ")

MarkEdmondson1234 avatar Mar 20 '21 19:03 MarkEdmondson1234

Hi Mark, Here's how the output looks when I try paste command. How can I save these as two dataframes?

  1. with sentiment score per entity
  2. document level sentiment

Thanks

git

madilk avatar Mar 21 '21 10:03 madilk

Ah I meant in the text you send in - what does

nlp <- gl_nlp(paste(cleanData$translatedText, collapse = " "),
                        nlp_type = "analyzeEntitySentiment", type="PLAIN_TEXT", language="en" )

...look like? It may be that the document sentiment needs a minimum number of letters to work.

MarkEdmondson1234 avatar Mar 22 '21 08:03 MarkEdmondson1234

As per this link [for Classification function], at least 20 tokens are required https://cloud.google.com/natural-language/docs/classifying-text 2 out 5 rows in my sample data are fairly long. Also when I try the paste command within gl_nlp, I'm getting NA doc sentiment text length

madilk avatar Mar 22 '21 16:03 madilk