<commit_before>package Examples.VHuman;

import Core.BaseMessage;
import Core.MessagingGateway;
import Core.VHMessage;
import Core.Config.ServiceConfiguration;
import edu.usc.ict.vhmsg.VHMsg;

/**
 * This class is the internal service that will route received virtual human
 * messages to vhmsg.  It will also attempt to convert non-VHuman messages  into VHuman messages.
 * 
 * @author auerbach
 *
 */

public class GIFTVHumanBridge extends MessagingGateway {
	
	public static final String BROKER_HOST_PARAM_KEY = "brokerHost";
	public static final String BROKER_PORT_PARAM_KEY = "brokerPort";
	
	
	protected VHMsg vhmsg;
	
	public GIFTVHumanBridge(ServiceConfiguration config)
	{
		super(config.getId(), null, null, null, null);
		
		
		String brokerHost = (String)config.getParams().get(BROKER_HOST_PARAM_KEY);
		int brokerPort = (int)config.getParams().get(BROKER_PORT_PARAM_KEY);
		
		
		this.vhmsg = new VHMsg(brokerHost, Integer.toString(brokerPort), "DEFAULT_SCOPE");
		this.vhmsg.openConnection();


		
	}
	
	
	public GIFTVHumanBridge(String brokerURL) {
		super("GIFT_VHUMAN_BRIDGE", null, null, null, null);


		String brokerHost = brokerURL.split(":")[1].split("//")[1];
		String brokerPort = brokerURL.split(":")[2];

		this.vhmsg = new VHMsg(brokerHost, brokerPort, "DEFAULT_SCOPE");
		this.vhmsg.openConnection();
	}

	@Override
	public void receiveMessage(BaseMessage msg) {
		super.receiveMessage(msg);

		// attempt to convert the recieved message to a vhuman message.
		BaseMessage convertedMessage = super.convertMessages(msg, VHMessage.class);

		if (convertedMessage != null && convertedMessage instanceof VHMessage) {
			VHMessage convertedVHMessage = (VHMessage) convertedMessage;

			// send out the message if it was successfully converted.
			vhmsg.sendMessage(convertedVHMessage.getFirstWord(), convertedVHMessage.getBody());
		}
	}

	public void disconnect() {
		vhmsg.closeConnection();
	}
}<commit_msg>added code to launch virtual human demo through gift.<commit_after>package Examples.VHuman;

import java.io.FileNotFoundException;
import java.io.IOException;

import Core.BaseMessage;
import Core.GIFTMessage;
import Core.MessagingGateway;
import Core.VHMessage;
import Core.Config.ServiceConfiguration;
import edu.usc.ict.vhmsg.MessageEvent;
import edu.usc.ict.vhmsg.MessageListener;
import edu.usc.ict.vhmsg.VHMsg;

/**
 * This class is the internal service that will route received virtual human
 * messages to vhmsg. It will also attempt to convert non-VHuman messages into
 * VHuman messages.
 * 
 * @author auerbach
 *
 */

public class GIFTVHumanBridge extends MessagingGateway {

	public static final String BROKER_HOST_PARAM_KEY = "brokerHost";
	public static final String BROKER_PORT_PARAM_KEY = "brokerPort";

	protected VHMsg vhmsg;

	public GIFTVHumanBridge(ServiceConfiguration config) {
		super(config.getId(), null, null, null, null);

		String brokerHost = (String) config.getParams().get(BROKER_HOST_PARAM_KEY);
		int brokerPort = (int) config.getParams().get(BROKER_PORT_PARAM_KEY);

		this.vhmsg = new VHMsg(brokerHost, Integer.toString(brokerPort), "DEFAULT_SCOPE");
		this.vhmsg.openConnection();

	}

	public GIFTVHumanBridge(String brokerURL) {
		super("GIFT_VHUMAN_BRIDGE", null, null, null, null);

		String brokerHost = brokerURL.split(":")[1].split("//")[1];
		String brokerPort = brokerURL.split(":")[2];

		this.vhmsg = new VHMsg(brokerHost, brokerPort, "DEFAULT_SCOPE");
		this.vhmsg.openConnection();
	}

	@Override
	public void receiveMessage(BaseMessage msg) {
		super.receiveMessage(msg);

		if (msg instanceof GIFTMessage) {

			// attempt to convert the recieved message to a vhuman message.
			BaseMessage convertedMessage = super.convertMessages(msg, VHMessage.class);

			if (convertedMessage != null && convertedMessage instanceof VHMessage) {
				VHMessage convertedVHMessage = (VHMessage) convertedMessage;

				// send out the message if it was successfully converted.
				vhmsg.sendMessage(convertedVHMessage.getFirstWord(), convertedVHMessage.getBody());
			}
		} else if (msg instanceof VHMessage) {
			BaseMessage convertedMessage = super.convertMessages(msg, GIFTMessage.class);

			if (convertedMessage != null && convertedMessage instanceof GIFTMessage) {
				this.sendMessage(convertedMessage);
			}

			startVHuman((VHMessage) msg);
		}
	}

	// Special code to handle the startup of the virtual human
	private void startVHuman(VHMessage vhMessage) {
		Runtime rt = Runtime.getRuntime();

		try {
			if (vhMessage.getFirstWord().equals("vrComponent") && vhMessage.getBody().equals("nvb parser")) {
				rt.exec("../VHuman/gift/02a-launch-unity-house.bat");
			}
			if (vhMessage.getFirstWord().equals("vrSpeech") && vhMessage.getBody().equals("interp user0001 1 1.0 normal THEREMIN NOSFERATU THERMOCOUPLE PATRONUS"))
				rt.exec("../VHuman/gift/03b-spawn-brad.bat");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void disconnect() {
		vhmsg.closeConnection();
	}
}
{'fraction_non_alphanumeric': 0.1110223642172524, 'fraction_numerical': 0.0033945686900958465, 'mean_word_length': 4.858479532163742, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6193408', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1556, 'n_words': 375}