Based on the title, looks like we will be having a boring lesson...
But don't be sad too fast.
Probably when we learn along the way, you will find some interests~
The Cloud Natural Language API lets us extract entities from text, perform sentiment and syntactic analysis, and classify text into categories.
Open Google Cloud Platform ( follow the step in A Tour of Qwiklabs and Google Cloud )
Activate Cloud Shell
Like what we did in the previous lesson.
Create an API Key
Like what we did in the previous lesson.
Make an Entity Analysis Request
This analyzeEntities method can extract entities (like people, places, and events) from text.
4-1. Create a request.json file and add the following code:
{
"document":{
"type":"PLAIN_TEXT",
"content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Potter fantasy series."
},
"encodingType":"UTF8"
}
This API supports type values are PLAINTEXT or HTML.
4-2. Call analyzeEntities method:
curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" \
-s -X POST -H "Content-Type: application/json" --data-binary @request.json > result.json
The result will be something like this:
Salience -> a number in the [0,1] range that refers to the centrality of the entity to the text as a whole.
5-1. Replace the content with the following code in request.json
{
"document":{
"type":"PLAIN_TEXT",
"content":"Harry Potter is the best book. I think everyone should read it."
},
"encodingType": "UTF8"
}
5-2. Run analyzeSentiment method:
curl "https://language.googleapis.com/v1/documents:analyzeSentiment?key=${API_KEY}" \
-s -X POST -H "Content-Type: application/json" --data-binary @request.json
The result will be like this:
A dependency parse tree for the sentence above would look like this:
6-1. Modify the code in request.json with a sentence in Japanese:
{
"document":{
"type":"PLAIN_TEXT",
"content":"日本のグーグルのオフィスは、東京の六本木ヒルズにあります"
}
}
Notice that you didn't tell the API which language the text is, it can automatically detect it!
6-2. Run analyzeEntities method:
curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" \
-s -X POST -H "Content-Type: application/json" --data-binary @request.json
The result is very cool:
Even cooler is the wikipedia URLs point to the Japanese Wikipedia pages!!!
What a smart text analysis!!!
Surprise! Today's lesson is over!
Didn't expect it's a short and sweet article this time right~
The natural language is so powerful!
It "speaks" our languages and even "understands" more language than we do!
Hope you enjoy today's sharing~