
jadex.bdi.tutorial.EnglishGermanTranslationPlanG1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The 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();
if(request==null)
{
throw new RuntimeException("No word received from client.");
}
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 - 2025 Weber Informatics LLC | Privacy Policy