Tutorial
1. Introduction
Language Grid Playground (hereafter called the Playground) is a website developed and maintained by the
Laboratory for Global Information Network, Kyoto University. The goal of the Playground is to enable anyone to easily access the Language Grid, and to enable them to use various language resources and language services.
The Playground source codes will be made public in the future to assist nonprofit organizations and academic institutions with the research and development of the Language Grid applications. This tutorial describes how to build a new language service based on the Playground source codes.
Prior to using the source codes, please read the terms and conditions stated in chapter 2. This tutorial will deal with the following contents: chapter 3 describes operating environment for running the source codes; chapter 4 describes the Playground’s overall system architecture; chapters 5, 6, and 7 describe the steps to building a basic service, an intermediate service, and an advanced application using the source.
2. Terms and Conditions (Use of Source Code)
The Playground source code is released to public so as to provide Language Grid users, who are developing new language services and tools, a set of sample codes that they can refer to. However, when using the Playground source codes, the source code user must abide by the following terms:
Each webpage in the Playground displays Kyoto University’s copyright notice along with the “all rights reserved” clause. This indicates that the webpage generated from the Playground source code must not be made public as is; therefore, the look and feel of the webpage must be changed.
The Playground realizes a simple user authentication capability using the Language Grid User ID with the help of the Language Grid Operation Center. However, the Language Grid User ID is not disclosed to the general Language Grid users. Therefore, if a third party developer develops a new language service based on the Playground source code, and decides to provide the new language service to the general public, the developer must implement his or her own user authentication capability.
The release of the Playground source code is intended to support the creation and testing of new language services by universities and research institutes; It is not intended to allow similar or identical sites to be maintained at different locations.
3. Operating Environment
To operate the Playground, an HTTP server with PHP environment and a file containing the ID and password for using the Language Grid services are needed besides the Playground source codes. The operating environment required to operate the Playground consists of HTTP server, PHP environment, and Web service environment. So far, the following two environments have been tested to work.
- Linux Environment
- OS: Linux(Fedora Core 8)
- HTTP Server: Apache HTTP Server 2.2.6
- PHP: PHP 5.2.4 which includes SOAP module below
- PEAR::SOAP0.11.0 (Beta)
- Character encoding is set to UTF-8
- Windows Environment
- OS: Windows XP / Vista
- HTTP Server: Apache HTTP Server 2.2.8
- PHP: PHP 5.2.5 which includes SOAP module below
- PEAR::SOAP0.11.0 (Beta)
- Character encoding is set to UTF-8
Other than the source codes, a PHP file containing the ID and password for using the Language Grid services must be created. Please create a matching.php file containing the codes provided below, and insert the path to this file in the php/config/player.php which will be described in chapter 5. You can also insert proxy settings in the player.php.
matching.php
php/config/player.php
4. Playground Architecture
Figure 1 shows the overall architecture of the Playground. The Playground is divided into two parts: a part dealing with the interface and another part where the Language Grid web services are invoked and the web service results are processed.
The interface is mainly defined using HTML and JavaScript. Since the interface is uniquely defined according to the system, this tutorial does not give details on how to define interfaces. The transaction between the interface and the part dealing with web service invocation and result processing, however, is vital to the system, so it will be discussed in chapter 5.3.
Meanwhile, the part which invokes the Language Grid web services is realized mainly using PHP. In this tutorial, we will describe how to build a new system using PHP.
We now describe the file structure of the Playground using a translation service example. The file structure of the Playground is given in Figure 2. Note that all image files are omitted in this figure.
The css directory retains the css files used in the Playground.
The js directory retains the JavaScript files which constitute the interface, and they are divided into three subdirectories: component, lib, and util. The component directory retains component files that define translation area, language resource selection, and so forth of the Playground. The lib directory retains JavaScript libraries such as YUI (http://developer.yahoo.com/yui/) and prototype.js (http://www.prototypejs.org/). The util directory retains other scripts useful to the Playground.
The php directory retains PHP files for invoking and processing web services. The directory is divided into four subdirectories: the ajax directory retains PHP files that exchange data between JavaScript, and JavaScript describes processes by specifying these PHP files; the admin directory contains PHP file required for the authentications unique to the Playground. When creating a new system, you don’t need to modify the content of the admin directory; the config directory retains PHP file describing the system settings, and by updating the path to the matching.php described in chapter 2, the Language Grid can be accessed. Moreover, in resource.php the language resource and the resource ID pairs are listed. And the language-resources directory includes codes describing the process that invokes language resources on the Language Grid. By using the methods provided in this directory, you can write codes without worrying too much about how to handle web services. Lastly, the language-services directory stores language service components that are used in the Playground. By writing processes using the components defined in this directory, you can easily use advanced language services such as cross-searches and multiple-language translations. The language-services directory is divided into four sub-directories: resource-adaptation directory stores components that handle input and output matching; combination directory stores components that define composite language services; application directory stores components specialized to specific application domains; and user-adaptation directory stores user-specific components.
|
Figure 1. Playground construction
Figure 2. File construction
|
5. Developing a basic service (e.g. a simple translation service)
This chapter will describe how to build a simple translation service by writing JavaScript and HTML, and using the Playground PHP.
5.1 Preparation
You can view the Playground source codes by clicking the “Source Code” button located at the top-right hand corner of the
Playground-in-test site.
First, copy and paste all source codes in the Translation Service, place the copied source codes below the HTTP server under the same file name and file structure as the source codes. In Figure 3, playground folder is created under the document root, and the copied source code files are placed under the playground folder.

Figure 3. Reproducing the code placement
Next, disable authentication function. The Playground has a unique authentication function, so default authentication function needs to be disabled by modifying the following two files:
Changing the value of AUTHENTICATION to 'false' (php/ajax/authentication.php)
Changing the value of AUTHENTICATION to 'false' (php/admin/service-monitor.php)
Modifying the value of AUTHENTICATION
From here on, the source codes will be created, and after the source codes are placed inside appropriate folders, you will be required to start Apache to check if the source codes are correct by checking, for example, http://localhost/playground/XXX.html. Note that the source codes cannot be checked simply by opening the HTML file; you need to have Apache running.
5.2 Creating HTML
We will write the actual source codes starting now. First, create an HTML file containing two text areas and one translation button. Please refer to other HTML references on how to write HTML files. When writing the HTML file, please be careful with the specifying of JavaScript files and prototype.js, and the assignment of ID to each text area. The screen shot of the HTML file will look like Figure 4.

Figure 4. HTML viewed with an internet browser
playground/lecture1.html
5.3 Creating JavaScript
We will now write the JavaScript file. First, we will write the code that displays the characters obtained from the upper text area to the lower text area. In this code, the input string, which is obtained using the upper text area id, is displayed on the lower text area using the lower text area id. This procedure is executed when the button is pushed. Figure 5 displays a screenshot of the program behavior.

Figure 5. HTML page in action
playground/js/lecture1-translation.js
Next, we write a procedure that assigns the input sentence to PHP, and displays translation result. How to write a request using prototype.js is given below:
We now write a procedure that creates a query and invokes the translation service using the PHP file that was previously copied. Here, “#3” is assigned as the id since J-Server is used for translation. The ids of the language resources are listed in resource.php. Figure 6 displays a screenshot of the program behavior.

Figure 6. A simple translation service in action
playground/js/lecture1-translation.js
In this chapter, we explained how to build a simple translation service using the PHP in the Playground. In the next chapter, we will describe how to build a more complex system by extending the PHP.
6. Developing an intermediate service (e.g. extending PHP)
This chapter describes how to build a new system by extending the PHP in the Playground. We will describe how to build a back translation service as an example.
6.1 Preparation
Prepare matching.php along with the source codes for translation service as described in chapter 5.1.
6.2 Creating HTML
First, create an HTML file containing three text areas (input area, output area that displays translated sentences, and another output area that displays back translation result) and one translation button. The screen shot of the HTML file will look like Figure 7.

Figure 7. HTML viewed with an internet browser
playground/lecture2.html
6.3 Creating JavaScript
Write a code that defines the procedure which sends input sentence to PHP, and displays translation and back translation results onto the screen. This time, the process is defined in PHP (unlike the in the previous chapter where language resource and language are indicated in the JavaScript file).
playground/js/lecture2-translation.js
6.4 Creating PHP
Next, the Playground’s PHP file is extended to realize back translation. First, create a new back-translate.php file. Inside the PHP file, $translator->multilingualTranslation is invoked twice to enable back translation. Figure 8 displays a screenshot of the program behavior.

Figure 8. HTML page in action
playground/php/ajax/translation/back-translate.php
7. Developing a system using dynamic binding (e.g. advanced application)
This chapter describes how to implement dynamic binding of the Language Grid composite web services. We will describe how to build a back translation system that incorporates Multilingual Dictionary for Kyoto Tourism as an example. Finally, we will embed a simple user dictionary, which can be edited, into machine translation.
7.1 Preparation
When using the language services of the Language Grid directly or use them in dynamic binding, the services must be selected from the available language services. To select the language resources, we first access the Language Grid Service Manager (http://langrid.org/operation/service_manager/). By clicking the “View of Language Grid” menu on the left, and then the submenu “Language Services,” you can obtain a list of language services provided on the Language Grid. In this chapter, we will use two language services, the UserDictionary Translation Service with Life Science Dictionary and Multilingual Dictionary for Kyoto Tourism Service with Extraction Function, so you need to obtain the WSDL and service IDs of these services. *
Note 1
7.2 Creating HTML
First, one text area for inputting text, two text areas for displaying translation result and back translation result, and two text areas for creating user dictionary should be created. This time, a checkbox asking whether Multilingual Dictionary for Kyoto Tourism should be imbedded is also created. The screen shot of the HTML file will look like Figure 9.

Figure 9. HTML viewed with an internet browser
playground/lecture3.html
7.3 Creating JavaScript
This time, the procedure for sending not only the sentences to be translated, but also information about user dictionary and whether or not to use Multilingual Dictionary for Kyoto Tourism to the PHP is written. The user dictionary is designed so that Japanese and English word are input in left and right text area respectively with each word listed on a new line. The JavaScript describes the procedure for creating an array of those words and sending them to the PHP.
playground/js/lecture3-translation.js
7.4 Creating PHP
Here, two PHP files are created. One PHP file that is called from the JavaScript contains the procedure for invoking the translation service; when this procedure is executed, Lecture3Translator Class which is defined in the other PHP file (lecture3-translator.php) is used.
playground/php/ajax/transation/lecture3-translate.php
Next a lecture3-translator.php is created which describes procedures for dynamic binding and user dictionary-embedded translation. This PHP file is created by inheriting the Service Class defined in service.php.
Dynamic binding is a method that switches the web services to be invoked in the composite web service during execution. Through this method, one can dynamically change the web services to be used. For example, if there is a back translation service that uses a machine translation service called NICTJServer, the machine translation service can be changed to KyotoUJServer using dynamic binding.
In order to perform dynamic binding, three items must be defined in the SOAP header: the binding method, initial service ID, and new service ID. These are defined when the SOAP_Client of the Playground is created.
The workflow that is used in this chapter performs translation by giving translated sentence, language pairs, and words in the user dictionary as arguments, and using the user dictionary and Lsd. This time, a dynamic binding between the machine translator and large scale dictionary used in the workflow is described. The original workflow uses MultilingualTranslationNictJServer. We first modify this so that KyotoUJServer is used. Moreover, modify the code so that LocalDbKyotoTourismDictionary is used instead of LocalDbLsd. Figure 10 displays a screenshot of the program behavior.

Figure 10. HTML page in action
playground/php/services/lecture3-translator.php
- * Note 1
- This tutorial gives an example that uses UserDictionary Translation Service, but the service cannot be used as is since there is a bug in the UserDictionary Translation Servic’s WSDL file. To remedy this, place the correct WSDL file in the local directory, and refer this directory to execute the web service. Please use this WSDL file (UserDictionaryTranslation.wsdl). (2008/05/14)