Integrate AIML files in android studio - java

I'm trying to make a chatbot using android studio but i can't find a way to connect it to the AIML files correctly here is the code i tried
String request = s;
String response = chatSession.multisentenceRespond(request);
while (response.contains("<")) response = response.replace("<","<");
while (response.contains(">")) response = response.replace(">",">");
if(response.equals("Too much recursion in AIML"))
return "";
else
return response;

I think by 'integrate' you mean that you want the bot to scan the AIML file and give a response according to the input provided by you.
For this, you have to follow following steps:
First put your AIML files in assets folder in Android Studio file hierarchy.
Then you have to save those files to your phone memory.
Then you have to use an interpreter like Program AB to get appropriate response according to the data you enter.
You can refer this link to get you started with it.

Related

Is there a similar function like getSubTransfers for MultipleFileDownload? AWS Java SDK

I know that there is a function called getSubTransfers for the MultipleFileUpload, which I can use to retrieve the path of the file being uploaded to the AWS S3 bucket. I did my research and found nothing similar for the MultipleFileDownload. Here is the code that I used for Upload.
MultipleFileUpload upload = transferManager.uploadDirectory(bucket, cloudDir, localFolder, true);
Collection<? extends Upload> uploads = new ArrayList<Upload>();
uploads = upload.getSubTransfers();
for (Upload u : uploads)
{
System.out.println(u.getDescription());
}
Here is the code that I have for downloading the directory from S3:
MultipleFileDownload download = transferManager.downloadDirectory(bucket, cloudDir + "/", localFolder);
I am writing a client app in java that would print out the path of the current file being downloaded to the console. Any help on how to print the name of the current file being downloaded is appreciated.
Unfortunately it looks like this is not supported currently.
There is a github request for this exact feature - https://github.com/aws/aws-sdk-java/issues/785
The good news is that it is being worked on - https://github.com/aws/aws-sdk-java-v2/issues/37
The closest workaround I can think of using the SDK is to use Transfer.getProgress() which will give you a TransferProgress object. Which has some properties like percentTransfered and some others... https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferProgress.html

how to specify a path for a file in repository ( java ) , so that my automation test won't fail

I'm testing an API with rest assured, programming language is JAVA, I'm having little issue, the issue is , I have to send an image using rest assured, and it's being sent successfully locally, but when i push it to git , having problem with specifying the path, and all my tests are run on TeamCity , and I get my cucumber report, report as follows
java.io.FileNotFoundException: C:\Users\nameOfUser\Downloads\38250987.jpeg (The system cannot find the path specified)
I hope I have delivered the issue descriptive enough, in case if u have any questions,doubts please do ask your questions, hoping for your help and cooperation, thanks in advance!
the code as follows
public static Response SendAnImage(String prodID,Cookies cookies) {
File file = new File("C:\\Users\\userName\\Downloads\\38250987.jpeg");
System.out.println("is file found ----> "+file.exists());
Response response = given()
.multiPart("file", file, "image/jpeg")
.when()
.cookies(cookies)
.post("/api/product/"+prodID+"/file/false");
return response;
}
You can put your file in src/test/resources folder, then create a new File like this:
File file = new File("src/test/resources/38250987.jpeg");
You cannot refer to local files in your tests. You need to include the picture file to your Git repository, load them as a resource in the test and then use the method in REST-assured that accepts a byte array instead of a file:
multiPart(String controlName, String fileName, byte[] bytes)

Saving existent CSV file in Android with Processing

I am new in android programming and I am struggeling with saving an existent CSV file. I wrote the Code with Java in Processing. and it works on the PC but now I would like to switch to android Mode - but how can I Move the CSV file to my phone? and is there an easy way so i can use the Command:
table = loadTable("Vocstest.csv", "header");
I use Processing 3.37
The code you wrote will work just fine on an android phone. I have used the same code as yours in an app.
The difference may be that i do not try to override it (by saving) I am only accessing it to retrieve the data.
You have to add your file in the "data" directory in your project. If the "data" folder does not exist you can create it and put in your csv file.
example:
Table aQaK = loadTable("aQaK_ar.csv", "header");
TableRow myrow = aQaK.getRow(myversenum);
String myversetxt = myrow.getString("AyahText");
Hope this helps. Peace.

Android Studio Helper Object

In my new app I wanted to make an IO object that will help me access text files written in a raw folder located in the res folder.
The object is a java class that is written in the same location as all of the rest java files.
The goal of this object is that I can access files from all of the activities instead of writing them again and again.
But when I tried to do that I stumbled upon a few errors that I can't find a way to fix them.
While writing the code:
FileOutputStream fos = new FileOutputStream(R.raw.fName);
(fName is a Sting that the action receives)
Android studio marked the "raw" red and said it didn't recognize it.
From what I understand the R file doesn't recognize the raw folder.
The second problem is , when I write the code:
InputStream is = Context.this.getResources().openRawResource(R.raw.fName);
It still gives me an error at the raw and an error at "Context.this" , and asks me to split the deceleration or to surround it with a try block , which doesn't help. And at the headline there is a throws IOException so any errors with IO should be cleared.
And if there is an easier way to access actions in java files , a link or an explanation will help a lot.
P.S. a raw folder is a premade folder with premade text files , also an easier way to read and write in premade files will help.

Get image path in non-servlet

I have a scheduled task running in JBoss 5.1 on a daily basis for sending birthday wishes.
The mail content is HTML and I embed images in the mail.
Now I would like to get the path of that image for embedding, how would it be possible to get path of image in a non-servelt environment.
Ofcourse I could have placed the images at a static location and accessed them, for which I don't want to hardcode the path.
The image is at "WebContent/images/birthday.jpg" location.
How are you generating the email content? Are these also static html files?
If you are going to use simple static html files, you will have to hard code the image paths. There is no other way around it.
You could write a simple Java application, which runs as a standalone application (without any servers,servlets etc), which will create the email content.
The java code can send out the emails for you too if you want.
These are some of the things you can do, if you use java
Use property files to specify the location of images. These are files which hold simple key/value pairs.
You can easily create multiple email content to different users, with the same template.
You will be able to easily redesign the html content for multiple users.
An example of using property files.
Create a file ex: "email_template.properties"
Enter the following into the file and save it.
image_server=http://www.mywebsite.com
image_folder=/WebContent/images/
Create a jave program to create your html email, and use the property file to generate the image locations.
Properties properties = new Properties();
try
{
properties.load(new FileInputStream("C://email_template.properties")); //specify path here
String sServerLocation = properties.getProperty("image_server");
String sImageFolder = properties.getProperty("image_folder");
StringBuilder strEmail = new StringBuilder();
strEmail.append("<html><body> <img src=\"" + sServerLocation + sImageFolder +"birthday.jsp\""> </body> </html>" );
// Write code to generate complete email dynamically
// write code to send out the email or to save as html file to you machine, where you can send it manually.
} catch (IOException e)
{
//
}
You get the idea. using plain html you will have to hard code.
However if you use a simple java file you can get more flexibility.
If you need code to send out email from java, check this link out.
How can I send an email by Java application using GMail, Yahoo, or Hotmail?

Categories