
jadex.bdi.tutorial.SearchTranslationOnlineB4 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.IMessageEvent;
import jadex.bdi.runtime.Plan;
import jadex.bridge.fipa.SFipa;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
/**
* Seach a translation of a word online.
*/
public class SearchTranslationOnlineB4 extends Plan
{
//-------- constructors --------
/**
* Create a new plan.
*/
public SearchTranslationOnlineB4()
{
// getLogger().info("Created: "+this);
System.out.println("Created: "+this);
}
//-------- methods --------
/**
* Execute the plan.
*/
public void body()
{
String eword = (String)((IMessageEvent)getReason()).getParameter(SFipa.CONTENT).getValue();
try
{
//URL dict = new URL("http://dict.leo.org/?search="+eword);
URL dict = new URL("http://wolfram.schneider.org/dict/dict.cgi?query="+eword);
System.out.println("Following translations were found online at: "+dict);
BufferedReader in = new BufferedReader(new InputStreamReader(dict.openStream()));
String inline;
while((inline = in.readLine())!=null)
{
if(inline.indexOf("")!=-1 && inline.indexOf(eword)!=-1)
{
try
{
int start = inline.indexOf(" ")+4;
int end = inline.indexOf(" ", start);
end = inline.indexOf("", "");
wordb = wordb.replaceAll("", "");
System.out.println(worda+" - "+wordb);
}
catch(Exception e)
{
System.out.println(inline);
}
}
}
in.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy