剔除同类产品
来源:互联网 发布: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
- 剔除同类产品
- 剔除
- ArcGIS与同类产品的
- ArcGIS与同类产品的
- 为什么 Dropbox 比同类产品更受欢迎?
- 剔除bug
- 剔除session
- 剔除字符
- myFAX网络传真服务器与同类产品比较的优势
- 在商品详细页,随机显示一定数量的同类产品
- Intel 图形性能分析器3.0版本及其与同类产品对比
- Excel 剔除重復數據
- 四叉树平面剔除
- 多边形的正反面,剔除
- 多边形背面剔除
- 视锥剔除优化
- 剔除行末回车
- Speedtree 剔除优化原理
- Ubuntu Vim复制内容到其他应用(Ctrl C + Ctrl V)
- h5页面和原生app页面的区别
- 资源文件的总结-----------(1)
- 加速你的py.test, pytest-dist
- centos Xmange pycharm 图形界面
- 剔除同类产品
- TabHost的实现过程中RadioButton的选中圆圈删除
- C++笔记
- TMD谁删我博客
- IDE FAQ
- cp 拷贝文件保持源文件的时间属性
- 自定义控件其实很简单 二
- hiho刷题日记——第二天Trie树