剔除同类产品

来源:互联网 发布:java偏移量是什么意思 编辑:程序博客网 时间:2024/03/29 14:08

SelectTop200_1.java根据行号找到相应的搭配套餐,剔除同类产品,将其搭配产品输出到文件(final_example.txt)

package test;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.util.Map;public class SelectTop200_1 {       public static void appendMethod(String fileName, String content) {           try {               //打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件               FileWriter writer = new FileWriter(fileName, true);               writer.write(content);               writer.close();           } catch (IOException e) {               e.printStackTrace();           }       }       public static String[] getStrings() {            FileInputStream fis;            InputStreamReader isr;            BufferedReader br = null;            try {                fis = new FileInputStream("/public/home/dsj/Public/sundujing/fpgrowth/ToCats.txt");//              fis = new FileInputStream("D://ToCats.txt");                isr = new InputStreamReader(fis, "UTF-8");                br = new BufferedReader(isr);            } catch (FileNotFoundException e) {                // TODO Auto-generated catch block                e.printStackTrace();            } catch (UnsupportedEncodingException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            String[] strings = new String[5462];            int i=0;            String str;            try {                while ((str = br.readLine()) != null) {                    strings[i] = str;                    i++;                }            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            return strings;        }       public static String[] getStrings1() {            FileInputStream fis1;            InputStreamReader isr1;            BufferedReader br1 = null;            try {                fis1 = new FileInputStream("/public/home/dsj/Public/sundujing/fpgrowth/ToCat.txt");//              fis1 = new FileInputStream("D://ToCat.txt");                isr1 = new InputStreamReader(fis1, "UTF-8");                br1 = new BufferedReader(isr1);            } catch (FileNotFoundException e) {                // TODO Auto-generated catch block                e.printStackTrace();            } catch (UnsupportedEncodingException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            String[] strings = new String[23105];            int i=0;            String str;            try {                while ((str = br1.readLine()) != null) {                    strings[i] = str;                    i++;                }            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            return strings;        }       public static String[] getStrings2() {            FileInputStream fis2;            InputStreamReader isr2;            BufferedReader br2 = null;            try {                fis2 = new FileInputStream("/public/home/dsj/Public/sundujing/fpgrowth/dim_fashion_matchsets.txt");                //fis2 = new FileInputStream("D://dim_fashion_matchsets.txt");                isr2 = new InputStreamReader(fis2, "UTF-8");                br2 = new BufferedReader(isr2);            } catch (FileNotFoundException e) {                // TODO Auto-generated catch block                e.printStackTrace();            } catch (UnsupportedEncodingException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            String[] strings = new String[23105];            int i=0;            String str;            try {                while ((str = br2.readLine()) != null) {                    String[] str1 = str.split(" ");                    //String[] str2 = str1[1].split(";");                    strings[i] = str1[1].replaceAll(";", ",");                    i++;                }            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }            return strings;        }    public static void main(String args[])    {         String[] strings = getStrings();//记录每行预测商品对应的类别cat         String[] strings1 = getStrings1();//记录对应match中每行对应的cat,用于甄别是否为同类产品         String[] strings2 = getStrings2();//每条对应match中的每行记录,需要去除同类产品//      for(int i=0;i<5462;i++)//      {            //strings[i]每行预测商品对应的类别cat,第一行对应399            String fileName = "/public/home/dsj/Public/sundujing/fpgrowth/final_example1.txt";            String content;            FileInputStream fis3;            InputStreamReader isr3;            BufferedReader br3 = null;            try {                       fis3 = new FileInputStream("/public/home/dsj/Public/sundujing/fpgrowth/line1.txt");                //fis3 = new FileInputStream("D://line.txt");                isr3 = new InputStreamReader(fis3, "UTF-8");                br3 = new BufferedReader(isr3);            } catch (FileNotFoundException e) {                e.printStackTrace();            } catch (UnsupportedEncodingException e) {                e.printStackTrace();            }                   String str;             int  count=0;            try {                while ((str = br3.readLine()) != null)//对应的为line.txt的每行即是为每行预测商品所准备的推荐搭配的前100行数                {                    String[] str1 = str.split(" ");                    for(int k=0;k<str1.length;k++)                        {                            int t=Integer.parseInt(str1[k]);//第一行对应为第一个数5735....                            //strings1[t]对应为ToCat第5735行,487 487 487 487 399 399 399 399 220 220 220 220 317 317 317 317,这条记录                            String[] str2 = strings1[t-1].split(" ");                            //strings2[t]对应的是dim_fashion_matchsets第5735行 :912534,932752,658698,519908,70341,3050430,300564,1071257,1590463,2240550,84524,3204531,3267304,3185197,1273818,1334655                            String[] str3 = strings2[t-1].split(",");                            int count1=0;//                          for(int t1=0;t1<str2.length;t1++)//                      {//                          //                          if(strings[count].trim().equals(str2[t1])==false)//                          {//                              count1++;//                          }//                          //                      }//                      if(count1==str2.length)//                      {//                          continue;//                      }                            for(int j=0;j<str2.length;j++)                            {                                if(strings[count].trim().equals(str2[j])==false)                                {//                                  boolean a=strings[count].equals(str2[j])//                                  content="";//                              }else{                                    content="";                                    //System.out.print(str3[j]+",");                                    content=str3[j]+",";//                                  boolean a=strings[count].trim().equals(str2[j]);//                                  content=a+"";                                    //content=str2[j];                                    appendMethod(fileName, content);                                }                            }                        }                    System.out.println("");                    appendMethod(fileName, "\n");                    count++;                }            } catch (IOException e) {                e.printStackTrace();            }    }}

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

0 0