In previously published articles on this website, we discussed around developing cognitive applications using IBM Data Science Experience tool. As IBM has lot of examples on Github and their official websites intended for the developers; the reader factually need not to be machine learning expert to build scripts, programs, plugins which that can recognize objects in photographs or analyze emotion of text written by human. One such example usage is in WordPress Plugin to Analyze Emotion of posts. This Example of Using IBM Watson For Text Analysis with Google Docs Demands Not Much Knowledge of Coding and This Can Be Used to Analyze Common Text Articles.
For this guide, you’ll need :
- IBM Cloud/Bluemix trial or paid account
- Google Apps account to add scripts
Below are some resources, official working demo from IBM around the topic :
---
1 2 3 4 5 6 7 8 9 10 | ... https://console.bluemix.net/docs/services/visual-recognition/getting-started.html https://github.com/IBM-Cloud/watson-spreadsheet https://developer.ibm.com/code/patterns/ https://github.com/IBM/powerai-vision-object-detection https://www.ibm.com/in-en/marketplace/deep-learning-platform https://visual-recognition-demo.ng.bluemix.net/train # hardware for data center and/or server room https://www.ibm.com/it-infrastructure/power ... |
NOTE : We do not recommend to upload sensitive document on Google Cloud for avoiding breech of privacy. Google’s various services are blacklisted by Richard Stallman & Free Software community. IBM Watson definitely a proprietary service but IBM, at least till the time of publication of this article, not known to be associated with mass surveillance.
Using IBM Watson For Text Analysis : Needed Minimum Theory
IBM Watson For Text Analysis is example of Natural Language Processing (NLP) service by IBM. With the service, we are using machine learning to extract data and understand overall emotion of text. In one recent article, we discussed difference of AI and machine learning to the newbies.
Natural Language Processing (NLP) is the ability of a computer program to understand natural human language. Natural Language Processing (NLP) is a component of artificial intelligence (AI) like machine learning (ML) is.
Example of Using IBM Watson For Text Analysis with Google Docs
Obviously, you need to know how to add script in Google Docs. That documentation, how to is here :
1 2 3 4 | https://developers.google.com/apps-script/ https://developers.google.com/apps-script/guides/docs https://developers.google.com/apps-script/quickstart/docs https://developers.google.com/apps-script/guides/dashboard |
Next, you need to know about IBM’s that API :
1 | https://www.ibm.com/watson/developercloud/natural-language-understanding/api/v1/#introduction |
Here is similar type of guides on creating scripts for Google Apps :
1 | https://www.ibm.com/blogs/bluemix/2016/08/watson-services-and-google-docs/ |
I got a ready to use script from this post :
1 | https://www.labnol.org/internet/ibm-watson-google-docs-nlp/31481/ |
I ported that script with GNU GPL 3.0 License (you can also change credit, pop-up etc) for education :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | /* IBM Watson Demo for Google Docs ------------------------------- Contributed by Abhishek Ghosh Email: admin@thecustomizewindows.com Web: https://thecustomizewindows.com/ Twitter: @AbhishekCTRL */ function analyzeText_() { var text = getSelectedText_(); if (!text.length) { showMessage_("Please select some text in the document."); return; } var credentials = { "username": "b5e4783c-2646-4b24-86fb-d737f4b7b6d0", "password": "AcSJCy5squjb" }; var payload = { "text": text.join("\n"), "features": { "entities": { "emotion": false, "sentiment": false, "limit": 10 } } }; var url = "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27"; var response = UrlFetchApp.fetch(url, { "method": "POST", "contentType": "application/json", "payload": JSON.stringify(payload), "headers": { "Authorization" : "Basic " + Utilities.base64Encode(credentials.username + ":" + credentials.password) } }); var entities = JSON.parse(response).entities; var answers = entities.filter(function(entity) { return entity.relevance > .3 }).map(function(entity) { return [entity.text, entity.type].join(" - "); }); if (answers.length) { showMessage_(answers.join("\n")); } else { showMessage_("Sorry, no entities were found"); } } function about_() { showMessage_("This demo was contributed by Abhishek Ghosh\nEmail: admin@thecustomizewindows.com\nWebsite: https://thecustomizewindows.com/"); } function onOpen(e) { DocumentApp.getUi() .createMenu("★ IBM Watson") .addItem('Analyze Text', 'analyzeText_') .addItem('About', 'about_') .addToUi(); } function getSelectedText_() { var text = []; var selection = DocumentApp.getActiveDocument().getSelection(); if (selection) { var elements = selection.getSelectedElements(); for (var i = 0; i < elements.length; ++i) { if (elements[i].isPartial()) { var element = elements[i].getElement().asText(); var startIndex = elements[i].getStartOffset(); var endIndex = elements[i].getEndOffsetInclusive(); text.push(element.getText().substring(startIndex, endIndex + 1)); } else { var element = elements[i].getElement(); if (element.editAsText) { var elementText = element.asText().getText(); if (elementText) { text.push(elementText); } } } } } return text; } function showMessage_(e) { DocumentApp.getUi().alert(e); } /** * @OnlyCurrentDoc */ |
That :
1 2 3 | var credentials = { "username": "b5e4783c-2646-4b24-86fb-d737f4b7b6d0", "password": "AcSJCy5squjb" |
should be changed to yours one till he blocks or change it! That above credential is of original poet who written the script (if he changes credential, you can click open his link, go to Tools menu, then click Script Editor option menu to find the script and get the new credential). I also kept the thing as GitHub repo.
How to use it?
- On Google Docs of Google Apps open any text document.
- Go to Tools menu, then click Script Editor option menu.
- A new window from
https://script.google.com/a/
will open. - Copy-paste the above snippet and save it.
- Reload the Google Docs of Google Apps window with your text document.
- You’ll notice that a new button named
★ IBM Watson
appeared beside Help menu of Google docs. - Now select text, click that
★ IBM Watson
option to bring down option menu, click selectAnalyze Text
. - IBM Watson will ask for permission, allow it.
- Then you’ll get the result as pop-up window.
- That’s it
Now, modify that script to add more creativity.
Tagged With complexyqi , example of text for watson analysis , IBM textAnalysis error , ibm watson text analysis entities , parsing error in ibm watson language using uipath , takeggp , tornoei , upuv6