How to build and run the CMU Olympus-Ravenclaw dialog system framework – 3

How the Olympus system works ? This is a summary after I read a bit of the code of Olympus.

1. How system started?

Open your SystemRun.bat, it will call this line:

START “” /DConfigurations\%RunTimeConfig% “%OLYMPUS_ROOT%\Agents\Pythia\dist\process_monitor.exe” %RunTimeStartList%.config

About the startlist.config file and Pythia’s process_monitor.exe (MITRE in old project) , you need to read this page:

http://wiki.speech.cs.cmu.edu/olympus/index.php/Pythia

http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/contrib/MITRE/tools/docs/process_monitor_tut.html
http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/docs/manual/index.html
Pythia is windows process manager that control many process start and stop. Written by pl and build as process_monitor.exe, it will read in the startlist.config file to control each process of system.

2. How each module started?

Pythia started many process and they communicate each other, each process has its ability as module in system, like ASR, TTS. They work together to make whole system work.

Example:
TTYRecongnitionServer is the module to interface with terminal in audio and keyboard input way. Pythia in fact will start this file : ttyserver_start.config to start this process. It will in fact run this cmd as one process:

$OLYMPUS_ROOT\bin\release\TTYRecognitionServer.exe 
--start - is to let Pythia start it
--input_line - is to let Pythia open a input box for it on the GUI.

3. What is the HUB?

So how each process feature doing and how these processes communicate with each other is very important now. Each process will be called a server, so there is a HUB to link all the servers together:

http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/docs/manual/index.html
http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/docs/manual/reference/hub.html

So what is a server?
http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/docs/manual/reference/adding.html

5. So how hub and server exchange data?

There is pgm file defined all servers info, name port, and rules etc, hub just read this file  and then will link all servers to exchange data.
Rules in programs (like main) tell Galaxy what the Hub should do when it gets a certain message

http://wiki.speech.cs.cmu.edu/olympus/index.php/How_does_the_hub_work

http://communicator.sourceforge.net/sites/MITRE/distributions/GalaxyCommunicator/docs/manual/tutorial/how_it_works.html

Now you have basic structure of the whole system.

http://wiki.speech.cs.cmu.edu/olympus/index.php/How_The_CMU_Communicator_Architecture_Works

 

5. So how task is organized as dialog system (ravenclaw) ?

ravenclaw use tree to define the task relations, like example here:

 

Sub node under a task is a sub task, to finish a task you need to go through from left to right to do each task. And they define a set of macro in C and developer need to use these set of macro to define this task tree:

example like this:

http://trac.speech.cs.cmu.edu/repos/olympus/tutorials/Tutorial1/branches/2.5/Agents/RavenClawDM/DialogTask.cpp

 

Advertisements

How to create doc for C++/JAVA code in eclipse

The common tools that we used in the eclipse is deoxygen

http://www.stack.nl/~dimitri/doxygen/manual/install.html

The good point for this one is that it can be used in both JAVA and C/C++ project. So for misc projects, this one maybe the best choice. In fact, it is really hard to find a workable free UML tool in Eclipse C++ to turn your code into the class hierarchy diagram. But this one can give this feature plus the auto index the docs.

Usage for it also is very easy.

1. Just install it in my ubuntu.

sudo apt-get install doxygen

2. And then in the eclipse install one plugin for doxygen: Eclox

3. Under the eclipse project create a folder of doc.

4. New -> other file-> others….. to create a doxyfile under this folder. Then you can use context menu to edit this file and make your selection for configuration for doxygen.

5: Common configurations summary here:

Input of source files folder (h, cpp, java etc.)

output folder

HTML with search and frame selected

Diagrams: use dot tool from the GraphViz….

Extraction mode: all entities and with crosss reference source-code…

6. Just use context menu “build documentation”, then you will get html/latex/rtf etc version docs for your code.

7. Then find the index.html in the created doc html folder to read the docs.

 

 

 

 

 

How to build and run the CMU Olympus-Ravenclaw dialog system framework – 2 ?

After olympus is compiled, it is a platform that will let other application can run. so we can get some examples from this SVN:
http://trac.speech.cs.cmu.edu/svn/olympus/example-systems/

And ravenclaw has wiki page to teach two tutorials at here:
http://wiki.speech.cs.cmu.edu/olympus/index.php/Documentation
http://trac.speech.cs.cmu.edu/repos/olympus/tutorials/

So let us take a look how to run applications.

1. After go through the example-systems codes, in all branch folders we can see the 2.0, 2.1, 2.5. 2.6 etc. These folders in fact are different application matches to the version of the olympus version. So as our olympus compiled is 2.6.1, so we only need to look for the 2.6 folders. Only two are in the examples:
Madeleine
MeetingLine

2. Let us try the MeetingLine as example, build it first:
cd .\MeetingLine\branches\2.6
perl Systembuild.pl

It will use the code of olympus and tools there to build this application.

3. After MeetingLine is built, let us make sure our speaker and micro working fine. and then we can just run it:
.\SystemRun.bat
or SystemRun-JavaTTY.bat (This one runs through TTY, no sound I think.)

4. MeetingLine will open a GUI dashboard should come up, and all modules should be green.

Click “TTYRecognitionServer” and then type init_session into the input box.

The system should greet you by voice. and then you can then either type into the input box or speak into a connected microphone.

5. Tutorial1 and Tutorial2 both can run in same way, but they do not have 2.6 version folder in the branch folder.
So I use trunk folder version code to compile for 2.6 and it can compiled.
So you can try out each example by trunck version code to see if they are latest version is for 2.6 version or not.

=============================================================================================
Some notes about the Visual Studio versions and where is the MSBuild.exe location :
OlympusBuild.pm need these knowledge to debug.
=============================================================================================
What is Visual Studio version means

http://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History – Visual Studio
Visual Studio 6.0 (1998)
Visual Studio .NET (2002) = version 7
Visual Studio .NET 2003 = version 7.1
Visual Studio 2005 = version 8
Visual Studio 2008 = version 9
Visual Studio 2010 = version 10
Visual Studio 2012 = version 11
Visual Studio 2013 = version 12
Visual Studio 2015 = version 14
Visual Studio 2017 = version 15

=============================================================================================

MSBuild in the previous versions of .NET Framework was installed with it but, they decided to install it with Visual Studio or with the package BuildTools_Full.exe.

The path for .NET framework installation is C:\Windows\Microsoft.NET\Framework[64 or empty][framework_version] The path when Visual Studio is installed is C:\Program Files (x86)\MSBuild[version]\Bin for x86 and, C:\Program Files (x86)\MSBuild[version]\Bin\amd64 for x64.

The path when BuildTools_Full.exe is installed is the same as when MSBuild is installed with Visual Studio.

 

As of 2013 msbuild ships with Visual Studio:
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe

 

Before that msbuild shipped with the .NET Framework, up to version 4.5.1:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

 

C:\Windows\Microsoft.Net\Framework\v2.0.50727\MSBuild.exe
C:\Windows\Microsoft.Net\Framework\v3.5\MSBuild.exe
C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.Net\Framework64\v2.0.50727\MSBuild.exe
C:\Windows\Microsoft.Net\Framework64\v3.5\MSBuild.exe
C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe

 

Just to add more information to the answer, in Windows 8.1, mine show up under
C:\Program Files (x86)\MSBuild\12.0\Bin
and
C:\Program Files (x86)\MSBuild\12.0\Bin\amd64

 

Don’t forget, older MSBuild versions are also updated when newer .NET frameworks are installed. For example, .NET Framework 4.5.1 also updates the .NET Framework 4.0 MSBuild version to 4.0.30319.18408

https://stackoverflow.com/questions/2709279/how-to-launch-correct-version-of-msbuild

How to build and run the CMU Olympus-Ravenclaw dialog system framework – 1 ?

CMU has developed many speech related projects and you can take a look from these two places:
http://www.speech.cs.cmu.edu/
http://wiki.speech.cs.cmu.edu/
Olympus is one of them.

Olympus dialog system is a speech system envoling from CMU Communictor in history. Current wiki page are at here:
http://wiki.speech.cs.cmu.edu/olympus/index.php/Olympus

From SVN and wiki, we can know Olympus ended around 2015. From SVN history log of the Olympus, most of the components in Olympus were done around 2000-2006. This project stop major work at 2010. From 2010, they almost do nothing anymore on project code level.

==============================================================================================================
To know about the Olympus, it is better to make it run and test it out, here I will note down how to to make the Olympus runs.

===============================================================================================================

0. Take some time reading the wiki pages to get some clues, but if you try it out by wiki instructions, you will faces many difficuties as wiki, code and enviroment are very outdate and mismatched, these will bring you many issues.

http://wiki.speech.cs.cmu.edu/olympus/index.php/Download
http://wiki.speech.cs.cmu.edu/olympus/index.php/Tutorials_Overview
https://blog.csdn.net/zhongkeli/article/details/9025043

1. Install a windows 7 computer, try to get an old computer having windows 7. it only can run at win 7 .

2. Download and install tortoisesvn, this one you can choose latest version:
https://osdn.net/projects/tortoisesvn/storage/1.10.0/Application/TortoiseSVN-1.10.0.28176-x64-svn-1.10.0.msi/

3. Get CMake https://cmake.org/files/ use the exe install for windows , I choose 3.4.0 version at here, do not choose latest version, it maybe cause issues.

4. Install ActivePerl from ActiveState – i choose 5.22 version
ActivePerl-5.22.4.2205-MSWin32-x64-403863.exe

5. Install Python 2.7
python-2.7.13.amd64.msi

6. Install java 8 with netbeans IDE (must with netbean!), MUST install it under default folder, as later olympus script can only looking for ant of netbean under the default folders:
C:\Program Files…..

jdk-8u171-nb-8_2-windows-x64.exe

7. Install Visual Studio – this is a bit troublesome, I tested VS 2010, it must have the SP1 to work with CMake :

en_visual_studio_2010_professional_x86_dvd_509727.iso
mu_visual_studio_2010_sp1_x86_dvd_651704.iso

VS 2012 version should be better. later you will know reason.

8. Intall TTS Flite – this step I do not think it is useful, as olympus has the flite in already. Maybe very very old version use this step.
http://www.speech.cs.cmu.edu/flite/doc/index.html

9. Now, all software are ready, we need to config system environment:

Set the windows ENV for these:
OLYMPUS_ROOT = C:\CMU\olympus\2.6.1
LOGIOS_ROOT = C:\CMU\olympus\2.6.1\Tools\logios

Second LOGIOS_ROOT maybe no need anymore.

10. So, now we cna check out code to C:\CMU\olympus\2.6.1
SVN URL – http://trac.speech.cs.cmu.edu/svn/olympus/tags/2.6.1

I alos check out the example and tutorials to some folders
http://trac.speech.cs.cmu.edu/svn/olympus/example-systems/
http://trac.speech.cs.cmu.edu/repos/olympus/tutorials/

 

11. I before start build there are some perl module need be installed:
ppm install Win32::RunAsAdmin
ppm install Win32::Env

12. Enter the powershell, try to build the source:

cd C:\CMU\olympus\2.6.1
.\OlympusRebuild.bat

OlympusBuild.bat has a bug on source, you should change its content to this:
perl Build\OlympusBuild.pl
So I just use OlympusRebuild.bat to build it.

12. If you are lucky, then your build could be success. But most of chance you will get some errors. As this system is very old and it is very sensitive to software versoins.

=======================
Build SUMMARY
Appears successful…

13. As I use the VS 2010 (10.0), so I need to open the OlympusBuild.pm file to change some text there.

$self->{‘BuildSysExe’} = $msbuildpath.’v4.0.30319/’.’MSBuild.exe’; # v 11.0
$vers = ‘10.0’; // here change 11 to 10 to match my VS version

MSBuild.exe location is at v4.0.30319/ folder for both VS 11 and 10, so I need to change $vers in this script to match with my VS version 10. This in fact a bug in this file.

14. OK now we have the Olympus compiled and installed, and next step to to run some examples to see how it works.

=============================================================================================

How to create a Async http call in Spring Boot

Use case in this example:

1. Client makes call to server side, returned immediately, but already start a asynchrony process in server side.

2. When the process is still running, client need to call http call to get the processing status from time to time.

3.  This example shows a processing status shared by the whole container context, as the Bean and controller scope in Spring is Singleton. You can also try to make controller and bean into session, request level if needed.Or use the session/Model to handle shared data.

4.  @Async can not be used in the controller , I test it. Callable maybe it the way for controller method.

 

– Let us take a look code.  Create one service bean and make it expose the status by a getter.

@Service
public class TestService {

private static final Logger logger = LoggerFactory.getLogger(TestService.class);

private String status = "Not start";

@Async("processExecutor")
 public void process() {
 logger.info("Received request to process in ProcessServiceImpl.process()");
 status = "in Process";
 try {
 Thread.sleep(15 * 1000);
 logger.info("Processing complete");
 } catch (InterruptedException ie) {
 logger.error("Error in ProcessServiceImpl.process(): {}", ie.getMessage());
 }
 
 status = "Done";
 
 }

public String getStatus() {
 return status;
 }
}

 

Then config the application to make it support the @EnableAsync and define the tread pool for Async calls.

@EnableAsync
public class MyDemoApplication {
...........................................................// for Async test code
 @Bean(name = "processExecutor")
 public TaskExecutor workExecutor() {
 ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
 threadPoolTaskExecutor.setThreadNamePrefix("Async-");
 threadPoolTaskExecutor.setCorePoolSize(3);
 threadPoolTaskExecutor.setMaxPoolSize(3);
 threadPoolTaskExecutor.setQueueCapacity(600);
 threadPoolTaskExecutor.afterPropertiesSet();
 logger.info("ThreadPoolTaskExecutor set");
 return threadPoolTaskExecutor;
 }

 

Then at spring mvc controller create two method for http , start process and check process status:

 

@Autowired
 private TestService processService;
....
@GetMapping("/startAsync")
 public Result startAsync() {
 processService.process();
 statusData = processService.getStatus();
 Result rt = new Result(true, statusData);
 return rt;
 }

@GetMapping("/getAsyncStatus")
 public Result getAsyncStatus() {
 statusData = processService.getStatus();
 Result rt = new Result(true, statusData);
 return rt;
 }

Then server side is done!

Let me create a client code to test it how is works:

 testStartAsyncCall();
 testAsyncStatusCall();
 try {
 TimeUnit.SECONDS.sleep(10);
 } catch (InterruptedException e) {
 e.printStackTrace();
 }
 testAsyncStatusCall();
 try {
 TimeUnit.SECONDS.sleep(10);
 } catch (InterruptedException e) {
 e.printStackTrace();
 }
 testAsyncStatusCall();

 

You can see the process take 15 seconds to finish, so client side try to get the status every 10 seconds after call to start the process. so we can see how status is changed in the whole process.

My example is modified from one example post, Please refer to this post:

http://softwaredevelopercentral.blogspot.com/2017/07/asynchronous-processing-async-in-spring.html

 

 

 

Exception Processing @RestControllerAdvice in Spring

A very useful class in the Spring 4 plus is the  @RestControllerAdvice, it combines the @ControllerAdvice inside. By defining a @RestControllerAdvice, when a controller thorw one exception, you can put all the exception handlers code into one class and you then can choose to use different @ExceptionHandler method to deal with different exceptions , or you even can deal all in one method to use the instance check up to decide what response msg you should send out in response;

So you have chance to reply user a friend msg of your runtime exception of your Restful API, and even with customized http status code too with ResponseEntity class.

Here I put a fake sample code to show how it works. you can do more study and use the handler in your way. Result is a class you defined Object your want to reply to client side.


@RestControllerAdvice
public class GlobalExceptionHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

@ExceptionHandler(value = { MyCustomizedException.class })
 @ResponseStatus(HttpStatus.BAD_REQUEST)
public Result myCustomizedExceptionHandler(MyCustomizedException ex) {
 // ..... what ever process
 return new Result(500, 0001, ex.getMessage());
 }


@SuppressWarnings("rawtypes")
 @ExceptionHandler(value = Exception.class)
 public ResponseEntity handle(Exception e) {
 e.printStackTrace();
 Result rt = new Result(e.getMessage());

if (e instanceof SoaException) {
 rt = ((SoaException) e).getBodyStatus();
 } else if (e instanceof MissingServletRequestParameterException) {
 rt = DataUtil.rt("0002");
 } else if (e instanceof HttpRequestMethodNotSupportedException) {
 rt = DataUtil.rt("0003");
 } else if (e instanceof HttpMediaTypeNotSupportedException) {
 rt = DataUtil.rt("0004");
 } else if (e instanceof HttpMessageNotReadableException) {
 rt = DataUtil.rt("0005");
 } else if (e instanceof BindException) {
 rt = DataUtil.rt("0006");
 } else if (e instanceof NumberFormatException) {
 rt = DataUtil.rt("0007");
 } else if (e instanceof DataIntegrityViolationException) {
 rt = DataUtil.rt("0008");
 } else {
 rt = DataUtil.rt(Constants.ERROR_CODE);
 }
 LOGGER.error(rt.getMessage() + e);
 return new ResponseEntity<>(rt, HttpStatus.OK);
 }

 

Spring Admin Server and UI for Spring Boot Application – 2

Now , let us add the security login for the spring admin server.

1. Add these into pom.xml

<dependency>
 <groupId>de.codecentric</groupId>
 <artifactId>spring-boot-admin-server-ui-login</artifactId>
 <version>1.5.7</version>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-security</artifactId>
 </dependency>

spring-boot-admin-server-ui-login will supply the login and logout page.

 

2. Create a web security config class like this:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
 protected void configure(HttpSecurity http) throws Exception {
 http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
 http.logout().logoutUrl("/logout");
 http.csrf().disable();
 http.authorizeRequests().antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**").permitAll();
 http.authorizeRequests().antMatchers("/**").authenticated();
 http.httpBasic();
 }
}

 

3. put this into the application.properties

management.security.enabled=true
security.user.name=admin
security.user.password=*******

Restart and now you need login to access the server UI.

Screenshot from 2018-04-27 15-37-57

 

But now, you will lost your client app in the UI. To let the client can access the server URL to exchange the data to server, we also need to change client configuration:

Just add this into client application.properties, the server can connect with client again:

management.security.enabled = false
spring.boot.admin.username=admin
spring.boot.admin.password=*******

management.security.enabled = false is to tell the server no need the security policy to access the client URL of actuator.   But client will use admin account to login to the server side to submit data…

 

Here I have done the demo for the single client and server admin UI login.  Next step you need to look at in the discovery  and eureka environment, how to link one server with more clients in cluster.

Please refer the doc of admin server for more details.

https://codecentric.github.io/spring-boot-admin/1.5.7/