SelectTop200_2.java

SelectTop200_2.java输出文件final_example1.txt,排除原先因为相似度很像,而cat不同而没有排除的商品,即找到该搭配组合中一个商品跟被预测商品很像,但是它们的cat不同

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_2 {

       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[5484];
            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[23001];
            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[23001];
            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 String[] getStrings3() {
            FileInputStream fis4;
            InputStreamReader isr4;
            BufferedReader br4 = null;
            try {
                fis4 = new FileInputStream("/public/home/dsj/Public/sundujing/fpgrowth/simila_place.txt");
                isr4 = new InputStreamReader(fis4, "UTF-8");
                br4 = new BufferedReader(isr4);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String[] strings = new String[5484];
            int i=0;
            String str;
            try {
                while ((str = br4.readLine()) != null) {

                    strings[i] = str;
                    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中的每行记录,需要去除同类产品
         String[] strings3=getStrings3();//记录每行的每个最相似的位置
         //     for(int i=0;i<5484;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/line0.6_10.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行数
                {
                    //strings3[count] 1记录对应位置
                    String[] str1 = str.split(" ");
                    String[] str4=strings3[count].split(" ");//str1.length==str4.length
                    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(",");
                            for(int j=0;j<str2.length;j++)
                            {
                                if(strings[count].trim().equals(str2[j])==false&&str2[j].equals(str2[Integer.parseInt(str4[k])])==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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<select id="getdatatypeconfig" parameterType="java.util.HashMap" resultType="java.util.HashMap"> SELECT [datatypeconfig_colname] ,[datatypeconfig_strtype] ,[datatypeconfig_strlen] ,[datatypeconfig_strdecimal] ,[datatypeconfig_order] ,[datatypeconfig_remark] ,b.datavalue_colvalue AS datavalue FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datatypeconfig] a LEFT JOIN [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datavalue] b ON a.datatype_id=b.datatype_id AND a.datatypeconfig_id=b.datatypeconfig_id WHERE b.datafile_id=(SELECT TOP (1) [datafile_id] FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id=9 ORDER BY datafile_id DESC) AND b.datatype_id=(SELECT TOP (1) datatype_id FROM [JxBivAppUserDB].[dbo].[jxbivtob_settlement_datafile] WHERE datatype_id=9 ORDER BY datafile_id DESC) </select> <insert id="insert_fundsettlementdays" parameterType="java.util.HashMap"> INSERT INTO [JxBivAppUserDB].[dbo].[jxbivtob_settlement_fundsettlementdays] (${columnNames}) VALUES (${columnValues}) </insert>public Map<String,Object> insert_fundsettlementdays(HttpServletRequest request, HttpServletResponse response){ response.setCharacterEncoding("UTF-8"); Map<String,Object> map =new HashMap<>(); List<HashMap> datatypeList=userDao.selectList("basessm.mapper.fundsettlementdays.getdatatypeconfig"); if (datatypeList == null || datatypeList.isEmpty()) { // 处理查询结果为空的情况 map.put("info", "No data available"); return map; } HashMap hashMap =new HashMap(); userDao.insert("basessm.mapper.fundsettlementdays.insert_fundsettlementdays",hashMap); map.put("info", "success"); return map; }根据我的SQL语句和方法来完成需求
最新发布
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值