Title: | An Interface to Google's Cloud Natural Language API |
---|---|
Description: | Interact with Google's Cloud Natural Language API <https://cloud.google.com/natural-language/> (v1) via R. The API has four main features, all of which are available through this R package: syntax analysis and part-of-speech tagging, entity analysis, sentiment analysis, and language identification. |
Authors: | Brian Weinstien [aut, cre] |
Maintainer: | Brian Weinstien <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-26 03:09:58 UTC |
Source: | https://github.com/brianweinstein/googlenlp |
Send a request, and retrieve the entities
and language
responses.
This function retrieves the results from the analyzeEntities method.
analyze_entities(text_body, flatten = TRUE)
analyze_entities(text_body, flatten = TRUE)
text_body |
The text string to send to the API. |
flatten |
If |
A list containing two elements: entities
and language
.
If flatten
is TRUE
, then the entities
element is converted to a data frame.
## Not run: sample_entities <- analyze_entities(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_entities$entities sample_entities$language ## End(Not run)
## Not run: sample_entities <- analyze_entities(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_entities$entities sample_entities$language ## End(Not run)
Send a request, and retrieve the documentSentiment
and language
responses.
This function retrieves the results from the analyzeSentiment method.
analyze_sentiment(text_body, flatten = TRUE)
analyze_sentiment(text_body, flatten = TRUE)
text_body |
The text string to send to the API. |
flatten |
If |
A list containing two elements: documentSentiment
and language
.
If flatten
is TRUE
, then the documentSentiment
element is converted to a data frame.
## Not run: sample_sentiment <- analyze_sentiment(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_sentiment$documentSentiment sample_sentiment$language ## End(Not run)
## Not run: sample_sentiment <- analyze_sentiment(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_sentiment$documentSentiment sample_sentiment$language ## End(Not run)
Send a request, and retrieve the sentences
, tokens
, and language
responses.
This function retrieves the results from the analyzeSyntax method.
analyze_syntax(text_body, flatten = TRUE)
analyze_syntax(text_body, flatten = TRUE)
text_body |
The text string to send to the API. |
flatten |
If |
A list containing three elements: sentences
, tokens
, and language
.
If flatten
is TRUE
, then the sentences
and tokens
elements are each converted to data frames.
## Not run: sample_syntax <- analyze_syntax(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_syntax$sentences sample_syntax$tokens sample_syntax$language ## End(Not run)
## Not run: sample_syntax <- analyze_syntax(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_syntax$sentences sample_syntax$tokens sample_syntax$language ## End(Not run)
Send a request, and retrieve the sentences
, tokens
, entities
, documentSentiment
, and language
responses.
This function calls the annotateText method, which performs the analyzeSyntax, analyzeEntities, and analyzeSentiment methods all within one API call.
annotate_text(text_body, flatten = TRUE)
annotate_text(text_body, flatten = TRUE)
text_body |
The text string to send to the API. |
flatten |
If |
A list containing five elements: sentences
, tokens
, entities
, documentSentiment
, and language
.
If flatten
is TRUE
, then the sentences
, tokens
, entities
, and documentSentiment
elements are each converted to data frames.
## Not run: sample_annotate <- annotate_text(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_annotate$sentences sample_annotate$tokens sample_annotate$entities sample_annotate$documentSentiment sample_annotate$language ## End(Not run)
## Not run: sample_annotate <- annotate_text(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", flatten = TRUE) sample_annotate$sentences sample_annotate$tokens sample_annotate$entities sample_annotate$documentSentiment sample_annotate$language ## End(Not run)
Creates variables in your .Renviron file for use by other googlenlp functions.
This will edit your .Renviron file only if you call this function directly. If you prefer not to change your .Renviron file, use the set_api_key
function instead.
configure_googlenlp()
configure_googlenlp()
None
## Not run: configure_googlenlp() ## End(Not run)
## Not run: configure_googlenlp() ## End(Not run)
Convert the JSON/list entities
response into a flattened data frame.
flatten_entities(entities_list)
flatten_entities(entities_list)
entities_list |
The |
A flattened data frame.
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_entities(entities_list = sample_post$content$entities) ## End(Not run)
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_entities(entities_list = sample_post$content$entities) ## End(Not run)
Convert the JSON/list sentences
response into a flattened data frame.
flatten_sentences(sentences_list)
flatten_sentences(sentences_list)
sentences_list |
The |
A flattened data frame.
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_sentences(sentences_list = sample_post$content$sentences) ## End(Not run)
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_sentences(sentences_list = sample_post$content$sentences) ## End(Not run)
Convert the JSON/list sentiment
response into a flattened data frame.
flatten_sentiment(sentiment_list)
flatten_sentiment(sentiment_list)
sentiment_list |
The |
A flattened data frame.
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_sentiment(sentiment_list = sample_post$content$sentiment) ## End(Not run)
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_sentiment(sentiment_list = sample_post$content$sentiment) ## End(Not run)
Convert the JSON/list tokens
response into a flattened data frame.
flatten_tokens(tokens_list)
flatten_tokens(tokens_list)
tokens_list |
The |
A flattened data frame.
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_tokens(tokens_list = sample_post$content$tokens) ## End(Not run)
## Not run: sample_post <- gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) flatten_tokens(tokens_list = sample_post$content$tokens) ## End(Not run)
Retrieve API key
gcnlp_key()
gcnlp_key()
Your API key
## Not run: gcnlp_key() ## End(Not run)
## Not run: gcnlp_key() ## End(Not run)
Send a POST request to the Google Cloud Natural Language API and retrieve the results.
gcnlp_post(text_body, extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE)
gcnlp_post(text_body, extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE)
text_body |
The text string to send to the API. |
extract_syntax |
Behavior for the analyzeSyntax method. Defaults to |
extract_entities |
Behavior for the analyzeEntities method. Defaults to |
extract_document_sentiment |
Behavior for the analyzeSentiment method. Defaults to |
A list containing two elements: [1] content
includes the parsed response, and contains the sentences
, tokens
, entities
, documentSentiment
, language
results specified in the request. [2] raw_response
contains the raw response from the API.
## Not run: gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) ## End(Not run)
## Not run: gcnlp_post(text_body = "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", extract_syntax = TRUE, extract_entities = TRUE, extract_document_sentiment = TRUE) ## End(Not run)
get_config_file()
gets the value of config_file
get_config_file()
get_config_file()
The path to the user's config_file
## Not run: get_config_file() ## End(Not run)
## Not run: get_config_file() ## End(Not run)
Manually define an API key. Only use this function if you haven't run configure_googlenlp()
set_api_key(api_key)
set_api_key(api_key)
api_key |
Your API key, from https://console.cloud.google.com/apis/credentials |
None
## Not run: set_api_key("YOUR_API_KEY") ## End(Not run)
## Not run: set_api_key("YOUR_API_KEY") ## End(Not run)