ChoseFirst.java(输出结果ExampleToTerms2.txt)将ExampleToTerms1.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;
public class ChoseFirst {
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 void main(String[] args)
{
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/final_example.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(",");
content=str1[0];
// boolean a=strings[count].trim().equals(str2[j]);
// content=a+"";
//content=str2[j];
appendMethod(fileName, content);
appendMethod(fileName, "\n");
count++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}