Skip to content

Instantly share code, notes, and snippets.

@patrick013
Created August 7, 2018 18:02
Show Gist options
  • Save patrick013/bb61d51a0e8ed066bc4ebdd63d3d1eb2 to your computer and use it in GitHub Desktop.
Save patrick013/bb61d51a0e8ed066bc4ebdd63d3d1eb2 to your computer and use it in GitHub Desktop.
Start Metamap mmserver in Java

Start Metamap Server in Java


Metamap is a tool to recognize UMLS concepts in text. Here is a short script of Java for starting Metamap server. For details of installation of Metamap Java Api, please check here.

import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;
 
public class ServerStart {
	
	public static void main(String args[]) throws IOException {
		new ServerStart();
	}
	
	public ServerStart() throws IOException {		
		//Check If the MetaMap server is running in the process
		String line;
		String pidInfo ="";

		Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");

		BufferedReader input =  new BufferedReader(new InputStreamReader(p.getInputStream()));

		while ((line = input.readLine()) != null) {
		    pidInfo+=line; 
		}

		input.close();

		//Start the MetaMap Server
		if(!pidInfo.contains("mmserver14"))
		{
		    Desktop.getDesktop().open(new File("R:\\Metamap\\public_mm\\bin\\skrmedpostctl_start.bat"));
		    Desktop.getDesktop().open(new File("R:\\Metamap\\public_mm\\bin\\wsdserverctl_start.bat"));
		    Desktop.getDesktop().open(new File("R:\\Metamap\\public_mm\\bin\\mmserver14.bat"));	
		}

	}
	public static void ServerCheck() throws IOException, InterruptedException {		
		//Check If the MetaMap server is running in the process
		String line;
		String pidInfo ="";

		Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");

		BufferedReader input =  new BufferedReader(new InputStreamReader(p.getInputStream()));

		while ((line = input.readLine()) != null) {
		    pidInfo+=line; 
		}

		input.close();

		//Start the MetaMap Server
		if(!pidInfo.contains("mmserver14"))
		{
		    Desktop.getDesktop().open(new File("R:\\Metamap\\public_mm\\bin\\mmserver14.bat"));	
		    TimeUnit.SECONDS.sleep(10);
		}

	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment