Creating a Cloud App With Bluemix, a NoSQL DB, and Watson
See how this web app combines IBM Bluemix, Cloudant, and Watson's translation services to create a scalable multilingual experience for users.
Join the DZone community and get the full member experience.Join For Free
I created for the above application to solve the problem as follows:
World-renowned Chef Gabriel is one of the most famous chefs on the planet. His recipes are highly sought after by everyone from every part of the world.
The demand for his amazing recipes is very high, and because of this, he would like to able to share them with everyone on Warth regardless of the language that they speak. Furthermore, Chef Gabriel constantly changes and updates his recipes as new ideas come to him. Chef Gabriel then approached IBM looking for a solution to his problem.
IBM Architect Gabriel proposes that Chef Gabriel can store all his recipes in the SoftLayer Cloud using Cloudant — a NoSQL DB (the exact details of the DB were not shared with the chef, as chefs wouldn’t understand technical terms).
Chef Gabriel’s website can also be hosted within Bluemix (SoftLayer). The website will connect to the DB that houses all of his recipes. Since visitors to his site speak different languages, we will make use of the Watson Language Translator service. This will enable all the visitors to choose the language that they want to view the recipe in. The website application will then retrieve the language from the DB, then translate the text into the language that the visitor has chosen. The visitor to the website can then view the recipe in their preferred language.
The web application will retrieve the list of languages from Watson Language Translator and the list of stored recipes in Cloudant DB. This will then appear on the screen, and the visitor can select the recipe and the language they want. The web application will retrieve that recipe and then have it translated into the relevant language.
My end result is a website that stores recipes. You can request a recipe in a language of your choice as long as that language is offered by Watson Language Translator.
There was one workaround I had to implement. Cloudant DB did not seem to allow one to, via the Java SDK, write the ids for the documents in the database. It only allowed them to be auto-generated. Hence, I had to retrieve all the recipe documents in order to get the name of a particular recipe. This would be processor-intensive and affect performance for large-scale systems. Fortunately, this is a demo. However, please note I am aware of this facet.
The technologies I used were:
- REST-based HTTP/HTTPS calls
- JQuery- for the webpage
- Gson for JSON
- CSS for stylesheets
- Java for the backend
- Cloudant NoSQL for the database
- Watson Language translator for the language translation
I'll include a diagram of the UML that shows the relationship between the RecipeRequest and Recipe and Language objects. Note the RecipeRequest is really an association class that connects a recipe to a language that is to be translated. This is because a Recipe cannot have a property of language. A recipe is purely a method. In theory, even a drawing or a picture could be a recipe. A language is a concept in its own right. Hence, I used an association RecipeRequest to connect the Recipe to a Language.
The website URL is https://gabrieljcampbell.mybluemix.net/. Please try it out. The code resides on my GitHub. You can clone the repository. Remember, you need to use the Cloud Foundry commands to deploy to the Bluemix runtime. Below are screenshots of the website.
When we change the language, the recipe is translated:
That ends my post, which can also be found here.
Published at DZone with permission of Gabriel Campbell, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.