Skip to main content

Building a Lotus Sametime bot for language translation

Kulvir Singh Bhogal (kbhogal@us.ibm.com), Consultant, Software Services for WebSphere, IBM
Kulvir Singh Bhogal works as a consultant for IBM Software Services for WebSphere, devising and implementing J2EE solutions at customer sites across the U.S. You can reach Kulvir at kbhogal@us.ibm.com.
Mark Talbot (talbotm@us.ibm.com), Developer, Industry Solutions, IBM
Mark Talbot works for IBM as a developer for Industry Solutions. You can reach Mark at talbotm@us.ibm.com.

Summary:  Build an IBM Lotus Sametime bot that works with IBM WebSphere Translation Server to translate text strings on-the-fly. Use the Lotus Sametime Java toolkit, the WebSphere Translation Server Java API, IBM's public Sametime server, and the IBM Community Tools client for development and testing.

Date:  25 Apr 2006
Level:  Intermediate
Activity:  2041 views

The Internet has opened up much opportunity for enterprises, but at the same time, it has unearthed many challenges. A global enterprise must now transcend language barriers to be successful because it typically has a customer base that is scattered across the globe. Furthermore, many enterprises have their employee base spread across different countries, and contrary to popular belief, the language of e-business is not English. It is not an anomaly nowadays to see a workflow that involves English-speaking customers in the United States contacting Spanish-speaking suppliers in Mexico, who in turn interact with Korean-speaking manufacturers in South Korea. Such linguistic diversity makes it difficult to interact with employees, distributors, customers, and other parties to keep your e-business's wheels churning.

You can opt for the translation services of a human being to act as a mediator between you and those with whom you interact. However, as you might imagine, a human-based translation service can be quite costly and quite slow.

Enter machine translation: the science of automatic translation of human language by computers, which offers an affordable and expeditious alternative to human-based language translation. In this article, you learn about IBM's machine translation product, IBM WebSphere Translation Server for Multiplatforms v5.0. Specifically, you see how to easily fit together WebSphere Translation Server with an IBM Lotus Sametime bot. The end result of this study is a translation service, available 24x7x365 by means of instant messaging, that provides on demand, on-the-fly language translation services.

This article shows you how to create a Sametime bot that interacts with the WebSphere Translation Server to provide translation services when you need them. It assumes that you have experience developing bots for Lotus Sametime and are familiar with the Lotus Sametime Java toolkit.

You can download the sample Sametime bot for this article. See the Download section below.

IBM Lotus Sametime Java Toolkit overview

The Lotus Sametime Java Toolkit allows you to access core Sametime services such as awareness, instant messaging, and screen sharing by means of the Java programming language. For this article, you tap into the Lotus Sametime Java Toolkit's ability to interact programmatically with Lotus Sametime's instant messaging services. This article is in no way intended to be a tutorial on the Lotus Sametime Java Toolkit. If you are unfamiliar with the toolkit, refer to the documentation located in the ST70JavaToolkit\docs subdirectory.


Sametime bots preview

A Sametime bot is a chat robot that runs in the context of Lotus Sametime. Just like a human user, the bot logs into Lotus Sametime with a user name and password and appears as an online person in your contact list. Users can send text messages to the bot and, in response, the bot can perform a function and respond to the sender in the form of a text message. Sametime bots are written with the Lotus Sametime toolkits.

As mentioned earlier, this article shows you how to build a Sametime bot that performs translation. You ask the Sametime bot what the translation string is for a given input string and interact with the Sametime bot you create. As shown in figure 1, the Sametime bot is asked through an instant message to translate a string ("My cat likes milk") from English to Spanish (specified by the string enes). In response, the Sametime bot contacts WebSphere Translation Server through a programmatic call through the server's Java API. WebSphere Translation Server returns our translation string in the requested target language to the bot. The bot then passes the translated string back to the requesting client.


Figure 1. Preview of our Sametime bot
Preview of our Sametime bot

Though we cover some of the Sametime bot API, we do not delve too deeply into the intricacies of bot programming. To learn more about Sametime bot programming, refer to the Resources section.


IBM WebSphere Translation Server overview

IBM WebSphere Translation Server is machine translation software that addresses the linguistic challenge of providing language translation services for an enterprise in an expeditious and economical fashion. Specifically, WebSphere Translation Server can translate at speeds from 200 to 500 words per second. Also, it's extensible by means of its User Dictionary Manager tools that allow you to add slang or domain-specific phrases and terms to its translation engines, and it can handle complex, idiomatic expressions as well.

WebSphere Translation Server version 5 is available as a stand-alone product on a number of platforms, including Sun Solaris, Microsoft Windows 2000 and NT, IBM AIX, and Linux. For this study of WebSphere Translation Server and Sametime bots, it is assumed you are using the Windows environment.

WebSphere Translation Server 5.0 supports translation to and from the following languages:

  • English-to-French, French-to-English
  • Engish-to-Italian, Italian-to-English
  • English-to-Spanish, Spanish-to-English
  • English-to-Chinese (simplified and traditional), Chinese (simplified and traditional)-to-English
  • English-to-Japanese, Japanese-to-English
  • English-to-Korean, Korean-to-English
  • English-to-Brazilian Portuguese, Brazilian Portuguese-to-English

Of particular interest here is the ability for you to interact programmatically with WebSphere Translation Server and tap into its translation services through the C and Java libraries that are included with the product. Specifically, you use the Java library to interface with WebSphere Translation Server. This Java library is housed in a single JAR file, wts.jar, that is installed when you install WebSphere Translation Server.


Gathering the necessary ingredients

For our study, it is assumed that you have installed the Lotus Sametime Java Toolkit version 7.0, which you can download free from the developerWorks Lotus Toolkits page. Installation of the toolkit is straightforward; the installer simply unzips its contents to a specified directory. You use only one JAR file, STComm.jar, from the unzipped directory. This JAR file is all that is needed from the Sametime Java Toolkit to create our Sametime bot that provides instant message-based translation services.

Also needed, of course, is WebSphere Translation Server for Multiplatforms 5.0, the installation of which is straightforward: Launch the installer, and when you are asked which options you want to install, choose the options for Gateway and InfoCenter (the InfoCenter provides documentation about WebSphere Translation Server that may be useful), and all the languages for which you want support. For the purposes of this article, select all the language combinations available.

Additional translation engines are installable from the second WebSphere Translation Server installation CD (as with the first CD, select all of them). When installing from the second CD, exclude the IBM WebSphere Translation Server Gateway V5.0 and IBM WebSphere Translation Server InfoCenter V5.0 options (you already installed them from the first CD).

To launch WebSphere Translation Server (assuming you are using Windows), from your Start menu, choose Programs - IBM WebSphere Translation Server - Translation Server. As shown in figure 2, you should see the Started Server log message.


Figure 2. Starting up WebSphere Translation Server
Starting up WebSphere Translation Server

A sandbox for our study… the IBM public Lotus Sametime server

For our article, we use IBM Community Tools (ICT) as our Sametime client, which you can download for free from the Downloads Web site. On this site, you can create an IBM user name and password that allows you to log onto a public IBM Lotus Sametime server. This server allows anyone with an IBM user name to communicate through Lotus Sametime. For testing purposes, you must create an IBM user name for your bot and a different IBM user name for your test client. Our Sametime bot uses the public Sametime server (messaging.ngi.ibm.com).

The WebSphere Translation Server Sametime bot

As mentioned at the beginning, our goal is to create a Sametime bot that performs language translations on-the-fly. To do this, you leverage both the Sametime Java toolkit as well as the WebSphere Translation Server Java API.

Though Java development without an Integrated Development Environment (IDE) is possible (as is mowing your lawn with scissors), it is not recommended. To develop a Sametime bot, you are not bound to a particular IDE; however, our tool of choice is IBM Rational Application Developer for WebSphere Software v6.0. If you have not used the tool before, IBM offers a free trial version of Rational Application Developer from developerWorks for both Windows and Linux.


Preparing your Rational Application Developer environment

First, you need to set up your development environment. (It is assumed that you have some familiarity with Rational Application Developer.) To do this, you must create a Java project and set up the necessary build classpath for the Sametime bot.

  1. To create a new Java project, choose File - New - Project. This brings up the New Project Wizard.
  2. Select Java Project from the list of wizards and click Next.
  3. In the subsequent Java Project wizard, name your Java project sametimebot and click Finish.
  4. By default, Rational Application Developer starts up in the J2EE perspective. If prompted whether or not you want to switch to the Java perspective, click Yes. If, after creating your Java project, you are not already in the Java perspective, switch to it by going to the Windows menu and selecting Open Perspective - Other. This brings up a dialog box that allows you to select the Java perspective (see figure 3).

    Figure 3. Dialog box for selecting the Java perspective manually
    Dialog box for selecting the Java perspective manually

    When you are in the Java perspective, you should see the Java project that you created earlier, sametimebot, in the Package Explorer view. You now need to create a source folder to contain your source code. Though a source folder is not mandatory for Java development, with larger projects, source folders provide a good way to organize your code.

  5. To create a source folder, right-click the sametimebot project and from the subsequent context menu, select New - Source Folder. This brings up a dialog box prompting you to name your source folder; name it src.

    Now that you've created a source folder, you are ready to add the Java classes. First, create a class that interacts with WebSphere Translation Server.

  6. Right-click your newly created source folder and choose New - Class. This brings up the New Java Class wizard (see figure 4).
  7. Name the class WTSUtilities and the housing package <com.devworks.example.wts.utilities>. WTSUtilities is the class that is responsible for communicating with WebSphere Translation Server.

    Figure 4. New Java Class wizard "WTSUtilities"
    New Java Class wizard WTSUtilities

  8. Additionally, you need to create a second class that interacts with the Sametime Java libraries. To do this, repeat the steps above, naming this class WTSBot and the package com.devworks.example.wts.lotus. Now that you have your two Java classes created, you are ready to set up the classpath.

Our Sametime bot is dependent both on Sametime's Java toolkit libraries and the WebSphere Translation Server Java API libraries. These Java libraries are housed in two JAR files, which you need to add to your project's build path following these steps:

  1. Right-click the sametimebot project and choose Properties from the menu.
  2. From the Properties screen for the sametimebot project, select Java Build Path from the left-hand pane (see figure 5).
  3. Select the Libraries tab in the right pane to bring up a list of the libraries on which the sametimebot project depends.
  4. Next, click the Add External JARs button.

    Figure 5. Add External JARs button in the properties for the sametimebot project
    Add External JARs button in the properties for the sametimebot project

  5. A window displays asking for the location of your external JAR file. Point to the location of your WebSphere Translation Server library (wts.jar) and click OK. By default, wts.jar is located in the C:\Program Files\IBMWTS directory.
  6. Similarly, add the external JAR for the Sametime Java library (STComm.jar) as an external JAR. STComm.jar is located in a subdirectory named ST70JavaToolkit\bin of the directory where you installed your Sametime toolkit.
  7. Click OK to accept the changes you just made to your project's build path.

Now that you have your Application Developer environment set up, you are ready to dig into the code.


Developing your Sametime bot

In this Sametime bot, you keep the Sametime function and the WebSphere Translation Server function separate. Earlier you created two classes, the WTSBot class and the WTSUtilities class. You are now ready to populate these classes with their required function. As mentioned earlier, the intricacies of Sametime bot development are not being covered here as some familiarity with the Sametime API is assumed (see the Resources section). You can download the finished product of our classes from the project zip file associated with this article in the Downloads section.

The Sametime bot class WTSBot implements four interfaces: Runnable, LoginListener, ImServiceListener, and ImListener. Let's first look at what the LoginListener does.

LoginListener

The LoginListener notifies the WTSBot class of login and logout events. When the Sametime bot logs into the Sametime server, the bot does an asynchronous login. Therefore, you do not know whether or not the login is successful until you receive a LoginEvent from the LoginListener. The LoginListener is set up inside our constructor, as follows:

public WTSBot(String serverName, String userId, String password) {
	try {
		wtsUtilities = new WTSUtilities();
		stsession = new STSession("WTSSession");
	} catch (DuplicateObjectException e) {
		e.printStackTrace();
		return;
	}
		
	stsession.loadSemanticComponents();
	stsession.start();
			
	commService = (CommunityService) stsession
		.getCompApi(CommunityService.COMP_NAME);
	commService.addLoginListener(this);
	commService.loginByPassword(serverName, userId, password);
}

As you see in the previous code, you log into the Sametime server, using the CommunityService object's loginByPassword method. You pass into the method the server name, the Sametime bot's userID, and the Sametime bot's password. You should modify the bot.properties file to reflect your bot's user name and password. Because the login process is asynchronous, your bot won't be logged in until you receive a LoginEvent, which is processed by the loggedIn implementation method below:

public void loggedIn(LoginEvent e) {
	imService = (InstantMessagingService) stsession
		.getCompApi(InstantMessagingService.COMP_NAME);
	imService.registerImType(ImTypes.IM_TYPE_CHAT);
	imService.addImServiceListener(this);
	confService = (ConfService) stsession.getCompApi(ConfService.COMP_NAME);
	System.out.println("The WTS sametime bot has logged on to sametime.");
}

IMServiceListener

In the previous code, upon successful login, register your IMServiceListener implementation (of which our WTSBot class also plays the role) to the STSession object's associated InstantMessagingService object. Subsequently, your WTSBot class is notified when another user opens a window to communicate with your Sametime bot. You receive such a notification by means of the imReceived(IMEvent e) method, a contractual method implemented in the WTSBot class because we implemented the IMServiceListener interface:

public void imReceived(ImEvent e) {
e.getIm().addImListener(this); }

IMListener

In the imReceived(ImEvent e) method earlier, you associate an IMListener implementation to the ImEvent's com.lotus.sametime.im.Im object. Your WTSBot class also plays the role of being your IMListener implementation. Subsequently, the WTSBot class is notified if it receives data or text. Because you are only concerned about text, you implement only the textReceived interface, which receives an incoming ImEvent object:

public void textReceived(ImEvent e) {
	boolean isError = false;
	Im im = e.getIm();
	String messageText = e.getText();
	String translatedText = "";
	if (messageText.equalsIgnoreCase(HELP_COMMNAD)) {
		translatedText = HELP_STRING;
	} else {
		try {
			translatedText = processTranslation(messageText);
		} catch (RemoteException e1) {
			translatedText = "The sametime bot is unable to 
			reach the WTS Server.";
			isError = true;
		} catch (Throwable e2) {
			translatedText = "The sametime bot is unable to 
			reach the WTS Server.";
			isError = true;
		}
	}
	im.sendText(false, translatedText);
	if (isError) {
		System.err.println("Message received from "
			+ e.getIm().getPartner().getName() + " message:" 
			+ messageText); System.err.println("Translated Text is " 
			+ translatedText);
	} else {
		System.out.println("Message received from "
			+ e.getIm().getPartner().getName() + " message:" 
			+ messageText); System.out.println("Translated Text is " 
			+ translatedText);
	}
}

Whenever text is received from a Sametime partner, we retrieve the text using the incoming ImEvent object's getText() method. We then call the processTranslation method, which is responsible for communicating with WebSphere Translation Server. The processTranslation method is shown below for our dissection:

private String processTranslation(String messageText)
throws RemoteException, Throwable {
	String translatedText = "";
	if (messageText != null) {
		int index = messageText.indexOf('>');
		if (index != -1) {
			String language = messageText.substring(0, index).trim();
			index++;
			String toTranslate = messageText.substring(index, 
			messageText.length());
				translatedText = wtsUtilities.getTranslation(language,
					toTranslate);
		} else {
			translatedText = "Invalid translation string. 
			The format should be language > text.  
			Type \"help\" for help";
		}
	}
	return translatedText;
}

The processTranslation(String) method uses the utility class WTSUtilities, discussed in detail in the next section, to get the translated string for the requested source string. The processTranslation(String) method also validates the string from the user before it sends it off to the translation utility.


Developing the WebSphere Translation Server utility

Calling WebSphere Translation Server to translate programmatically a source string into a different language may seem to be a daunting task. This is not the case, however, due to WebSphere Translation Server's simple Java API that you leverage in the getTranslation method below:

public String getTranslation(String language, String preTranslation) 
throws RemoteException, Throwable 
{
	String postTranslation = "";
	LTinterface service;
	service = serviceLocator(language);
	if (service!=null)
	postTranslation = translate(service, preTranslation);
	return postTranslation;
}

In the previous code, you start by looking up the com.ibm.lt.LTinterface implementation responsible for translation of a particular source language to your desired target language. You hand off the lookup of the implementation to a private method named serviceLocator. The source language to target language is specified by use of the String variable language, which you feed into the getTranslation method. This variable must take on a String abbreviation that WebSphere Translation Server understands.

WebSphere Translation Server uses abbreviations to specify the language translation methodology. For example, English to Portuguese is signified by the string abbreviation enep. Refer to the WebSphere Translation Server InfoCenter on the Web or the version installed with the product for a complete list of valid language abbreviations. For a particular language pair to be supported, the appropriate translation server engines must be installed when you first set up WebSphere Translation Server.

As mentioned earlier, the getTranslation method calls a private static method of the WTSUtilities class named serviceLocator. This serviceLocator method is responsible for interacting with WebSphere Translation Server. The method obtains an implementation of the com.ibm.lt.LTinterface, and it is through the LTinterface implementation that you make calls to WebSphere Translation Server:

private static LTinterface serviceLocator(String language) 
throws Throwable  {
	LTinterface service = null;
	
	service = (LTinterface) serviceHash.get(language);
	if (service == null){
		service = (LTinterface) LTengine.GetService(hostname, language);
		serviceHash.put(language, service);
	}

	return service;
}

The workload of performing the string translation from language to language is handled from the WTSUtilities class's getTranslation method to the class's static translate method:

private static String translate(LTinterface service, String preTranslation) 
throws RemoteException {

	Object transObj = service.jltBeginTranslation(options);
	
	String postTranslation = "";
	if (preTranslation != null)
		postTranslation = service.jltTranslate(transObj, preTranslation);
	return postTranslation;
}

The translate method above uses the LTinterface object handle with which it is provided to perform a translation of the incoming preTranslation String. The work of translation is performed by means of the WebSphere Translation Server API method call of jltTranslate. This method takes in our preTranslation String as well as a java.lang.Object that represents the desired options for our translation. For your purposes, you pull your options (*format=text) for translation from a properties file. WebSphere Translation Server allows for the specification of other options like returning HTML. The option value of text that you used returns text (as you may have speculated). For more information about valid options, refer to the WebSphere Translation Server InfoCenter


Putting it all together

Now that you have created your WTSBot class and your WTSUtilities class, you are ready to start testing your bot. Run the WTSBot class by right-clicking WTSBot.java in the Package Explorer view and choosing Run - Java Application from the context menu.

If the logon was successful, you should see "The WTS sametime bot has logged on to sametime" in the Console view (see figure 6).


Figure 6. The WTSBot shown successfully logged into the Sametime server
The WTSBot shown successfully logged into the Sametime server

After the Sametime bot is logged on, it is ready to receive translation requests from Sametime partners.

Test the bot by logging onto the same Sametime server that the bot is logged into (messaging.ngi.ibm.com) and sending a message to the Sametime address being used by your bot. The message should be of the form: language > TEXT, where language represents one of the abbreviations that WebSphere Translation Server understands. For example, enes represents English to Spanish. To translate "My cat likes milk." from English to Spanish, you send your bot the text

enes > My cat likes milk.

Making WTSBot user friendly

To make your Sametime bot user friendly, you can create online help that returns some insight about how to use the WTSBot as shown in figure 7.


Figure 7. WTSBot supports the Help command
WTSBot supports the Help command

Lost in translation?

It is important to note that the translation services provided by WebSphere Translation Server are not guaranteed to be accurate. The code we present in this article is meant to be used for demonstration purposes only. IBM cannot be held liable if you accidentally ask your distributor to send you a dozen blue chickens. Before using a translation provided by WebSphere Translation Server, it is probably a good business practice to verify that the translation actually parallels the source string.


Conclusion

In this article, you learned how to create a Sametime bot that performs language translation services on-the-fly. You created the bot, courtesy of the Sametime Java toolkit, and leveraged the WebSphere Translation Server Java API to have your bot programmatically interact with WebSphere Translation Server. The Sametime bot can help bridge language gaps that exists between you and your correspondents.



Download

DescriptionNameSizeDownload method
Sample Sametime Translation botsametime-translation-bot.zip15KB HTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the authors

Kulvir Singh Bhogal works as a consultant for IBM Software Services for WebSphere, devising and implementing J2EE solutions at customer sites across the U.S. You can reach Kulvir at kbhogal@us.ibm.com.

Mark Talbot works for IBM as a developer for Industry Solutions. You can reach Mark at talbotm@us.ibm.com.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Lotus, WebSphere
ArticleID=109238
ArticleTitle=Building a Lotus Sametime bot for language translation
publish-date=04252006
author1-email=kbhogal@us.ibm.com
author1-email-cc=
author2-email=talbotm@us.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers