plzz help me in my small project due 23/5???????????????? In this project, you w
ID: 3842542 • Letter: P
Question
plzz help me in my small project due 23/5????????????????
In this project, you will be implementing a simple recommender system for online market application. In online shops, a recommender system is an Artificial Intelligence (AI) technique that helps on suggesting certain products (items) to a customer once he/she logs in to the online shop. There are many techniques used to recommend items to customers, however, we will use one technique only which is based on the frequency of purchasing certain items. For example, Customer A bought hair spray twice, eye lenses four times and a hair brush one time. Then the recommender system should recommend (show on screen or send offer) eye lenses to customer A because it is the most frequent item bought by customer A. If the system recommends more than one item, then the recommended items should be ordered discerningly (from top down) according to its frequencies (i.e., most frequent first then least frequent last). In the previous example, the system would recommend the items in the following order: eye lenses, hair spray and then hair brush.
Given data You are given a text file that includes historical transactions of 50 customers called “Transactions.txt”. Each line represents one transaction by one customer. Each line contains (i) a transaction #, (ii) a customer username, and (iii) a list of purchased items (identified by item IDs) by that customer. A customer can buy multiple items and can have multiple transactions. Transactions.txt file includes: - 80 transactions - 50 customers - 20 items (ItemIDs from 1 to 20) Note: You are given a java code to read and process the data in the “Transactions.txt” file. Your task Your task is to design and implement the recommender system explained above given historical records of customers’ transactions. You can divide the task into the following two main sub-tasks: 1. Given the transactions file, read and process the data such that you can identify the list of items purchased by each customer with each item’s frequency value (i.e., the number of times an item is purchased by a specific customer). 2. Write a test file to test the recommender system. The application should ask for a customer username, to simulate a login procedure, then it should output the recommended items to the logged-in customer in descending order. Moreover, the application should show the three most popular items in general (i.e., the most purchased items from all customers) in descending order.
Hints When processing the data, select a data structure that makes searching fast for finding similar items and locating customers. You may also sort the frequencies of items as you process the data or keep the sorting for later; in either ways you have to justify your design and data structures selections. Example Transactions file username itemID1 itemID2 Sara 01 02 Ahmad 08 Ali 03 Dalal 05 01 Sara 02 05 Ali 03 05 Ahmad 02 08 Sara 02 01 Note: In this example there are at most two items purchased by each customer. In the given transactions file there might be more than two items. Processed data showing each customer and its list of purchased items in terms of pairs Sara: <01, 2>, <02, 3>, <05, 1> Ahmad: <08, 2>, <02, 1> Ali: <03, 2>, <05, 1> Dalal: <05, 1>, <01, 1> Frequency of items in general: 01: purchased 3 times 02: purchased 4 times 03: purchased 2 times 05: purchased 3 times 08: purchased 2 times
The Test file sample output:
Enter the file name: Transactions.txt
Most popular 3 items:02, 01, 05
Please enter a username or -1 to quit:
Sara Recommended items for Sara: 02, 01, 05
Please enter a username or -1 to quit:
Ali Recommended items for Ali: 03, 05
Please enter a username or -1 to quit: -1
Good bye…
[show running time results of your program execution here…]
Note: In the sample output above, the green text is an input and the blue text is a variable output.
Explanation / Answer
import java.io.*;
import javax.servlet.*;
import java.sql.*;
import javax.servlet.http.*;
public class addcart extends HttpServlet
{ PrintWriter pw;
char myflag='y';
public void doPost (HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
Connection con=null;
pw=res.getWriter();
Statement stmt=null;
ResultSet rr=null;
ResultSetMetaData rsmd;
res.setContentType("text/html");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:sri","scott","tiger");
stmt=con.createStatement();
String inm="'"+req.getParameter("txtinm")+"'";
String q="'"+req.getParameter("txtq")+"'";
String t=req.getParameter("txtr");
char type=t.charAt(0);
System.out.println((char)type);
pw.println("Item name "+inm);
pw.println("Quantity "+q);
pw.println("Item Type "+t);
pw.println((char)type);
String qry1=null;
switch(type)
{
case 'H':
case 'h':
qry1="select rate,iname from hware where iname="+inm;
pw.println(qry1);
// rr=stmt.executeQuery("select rate from hware where iname="+inm);
rr=stmt.executeQuery(qry1);
pw.println("Query is Executed...");
break;
case 'S':
case 's': qry1="select rate,iname from sware where iname="+inm;
pw.println(qry1);
break;
case 'M':
case 'm': rr=stmt.executeQuery("select rate,title from music where title="+inm);
break;
case 'B':
case 'b': rr=stmt.executeQuery("select rate,title from books where title="+inm);
break;
default:
{
pw.println("Invalid choice");
myflag='n';
}
}
pw.println("Concerned Statement Prepared and Executed...");
pw.println((char)type+" Valid item type "+myflag);
/*rsmd=rr.getMetaData();
int col=rsmd.getColumnCount();
pw.println("The Above Query has fetched "+col+ " Columns");*/
String name="";
while(rr.next())
{
String rate=rr.getString(1);
int amount=Integer.parseInt(rate);
name=rr.getString(2);
System.out.println(" "+rate+" "+name);
pw.println(" "+amount+" "+name);
pw.println(" "+myflag);
System.out.println("Valid item name "+rr.getString(2)+" "+myflag);
}
pw.println(" "+myflag);
if(myflag=='y')
{
pw.println(" OK");
pw.println("Valid item name "+name+" "+myflag);
if(rr==null)
{
pw.println("Not a valid item");
myflag='n';
}
pw.println("Valid item name "+name+" "+myflag);
if(myflag=='y')
{
pw.println(" "+inm+" "+q);
rr=stmt.executeQuery("select * from reges where flag='y'");
if(rr==null)
{
pw.println(" Sign in first");
//System.exit(0);
myflag='n';
}
pw.println("Signed in "+rr.getString(1)+" "+myflag);
if(myflag=='y')
{
String data="'"+rr.getString(1)+"'";
String qry="insert into cart values("+inm+","+q+","+data+")";
pw.println("Query is "+qry);
int rs=stmt.executeUpdate(qry);
pw.println("1 row inserted");
}
}
}
}
catch(ClassNotFoundException e){}
catch(SQLException e){}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.