All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bdi.tutorial.EnglishGermanTranslationPlanG1 Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

There is a newer version: 2.4
Show newest version
package jadex.bdi.tutorial;

import jadex.bdi.runtime.IExpression;
import jadex.bdi.runtime.Plan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;


/**
 *  An english german translation plan can translate
 *  english words to german and is instantiated on demand.
 */
public class EnglishGermanTranslationPlanG1 extends Plan
{
	//-------- attributes --------

	/** Query the tuples for a word. */
	protected IExpression	queryword;

	//-------- constructors --------

	/**
	 *  Create a new plan.
	 */
	public EnglishGermanTranslationPlanG1()
	{
		getLogger().info("Created:"+this);
		this.queryword	= getExpression("query_egword");
	}

	//-------- methods --------

	/**
	 *  The plan body.
	 */
	public void body()
	{
		Socket client = (Socket)getParameter("client").getValue();

		try
		{
			BufferedReader	in	= new BufferedReader(new InputStreamReader(client.getInputStream()));
			String	request	= in.readLine();
			int	slash	= request.indexOf("/");
			int	space	= request.indexOf(" ", slash);
			String	eword	= request.substring(slash+1, space);
			String	gword	= (String)queryword.execute("$eword", eword);
			System.out.println(request);
//			while(request!=null)
//				System.out.println(request	= in.readLine());
			
			PrintStream	out	= new PrintStream(client.getOutputStream());
			out.print("HTTP/1.0 200 OK\r\n");
			out.print("Content-type: text/html\r\n");
			out.println("\r\n");
			out.println("TranslationM1 - "+eword+"");
			out.println("

Translated from english to german: "+eword+" = "+gword+"."); out.println("

"); out.flush(); client.close(); } catch(IOException e) { throw new RuntimeException(e.getMessage()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy