欢迎来到天天文库
浏览记录
ID:18204287
大小:45.00 KB
页数:12页
时间:2018-09-15
《aprior算法 c#语言 频繁项目集的生成》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Aprior算法C#语言频繁项目集的生成usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Collections;usingSystem.Text.RegularExpressions;namespaceaprior{classProgram{staticvoidMain(string[]args){Console.WriteLine(DateTim
2、e.Now);ArrayListD=getEventsFromDB();intmins=2;ListL=newList();L=apriorFrequent(mins,D);Console.WriteLine("数据库的频繁项目集如下:");for(inti=0;i3、emSet{publicstringItems{get;set;}publicintsup{get;set;}}staticDataSetexecuteCommandString(stringCommandString){//数据库的连接stringconnectionString="DataSource=.\SQLEXPRESS;AttachDbFilename='C:\ProgramFiles\MicrosoftSQLServer\MSSQL.1\MSSQL\Data\shop.mdf';IntegratedSecurity=True;Conne4、ctTimeout=30;UserInstance=True";SqlConnectioncon=newSqlConnection(connectionString);con.Open();//命令SqlCommandcmd=newSqlCommand();cmd.Connection=con;cmd.CommandText=CommandString;//创建适配器DataSetds=newDataSet();SqlDataAdapterda=newSqlDataAdapter(cmd);da.Fill(ds);//返回数据集returnds;//关闭连接con5、.Close();}//得到一项频繁项目候选集staticHashtablefind_frequent_1_item(){stringCommandString="selectnamefromgoods";DataSetds=executeCommandString(CommandString);intitem1Count=0;item1Count=ds.Tables[0].Rows.Count;ArrayListitem1=newArrayList();Hashtableht=newHashtable();for(inti=0;i6、{item1.Add(ds.Tables[0].Rows[i]["name"].ToString());//Console.WriteLine(item1[i]);//Regexr=newRegex(",");//string[]subItem=r.Split(item1[i].ToString());stringsubItem=item1[i].ToString();for(intj=0;j7、1;//强弱类型转换}elseht.Add(subItem[j],1);}/*foreach(DictionaryEntrydeinht){Console.WriteLine("key:{0},count:{1}",de.Key,de.Value);}*/}returnht;//Console.ReadLine();}//生成字符串的K项子集staticArrayListSubSet(intk,stringst){intlen=st.Length;ArrayListal=newArrayList();stringtemp="";for(inti=0;i8、Pow(2
3、emSet{publicstringItems{get;set;}publicintsup{get;set;}}staticDataSetexecuteCommandString(stringCommandString){//数据库的连接stringconnectionString="DataSource=.\SQLEXPRESS;AttachDbFilename='C:\ProgramFiles\MicrosoftSQLServer\MSSQL.1\MSSQL\Data\shop.mdf';IntegratedSecurity=True;Conne
4、ctTimeout=30;UserInstance=True";SqlConnectioncon=newSqlConnection(connectionString);con.Open();//命令SqlCommandcmd=newSqlCommand();cmd.Connection=con;cmd.CommandText=CommandString;//创建适配器DataSetds=newDataSet();SqlDataAdapterda=newSqlDataAdapter(cmd);da.Fill(ds);//返回数据集returnds;//关闭连接con
5、.Close();}//得到一项频繁项目候选集staticHashtablefind_frequent_1_item(){stringCommandString="selectnamefromgoods";DataSetds=executeCommandString(CommandString);intitem1Count=0;item1Count=ds.Tables[0].Rows.Count;ArrayListitem1=newArrayList();Hashtableht=newHashtable();for(inti=0;i6、{item1.Add(ds.Tables[0].Rows[i]["name"].ToString());//Console.WriteLine(item1[i]);//Regexr=newRegex(",");//string[]subItem=r.Split(item1[i].ToString());stringsubItem=item1[i].ToString();for(intj=0;j7、1;//强弱类型转换}elseht.Add(subItem[j],1);}/*foreach(DictionaryEntrydeinht){Console.WriteLine("key:{0},count:{1}",de.Key,de.Value);}*/}returnht;//Console.ReadLine();}//生成字符串的K项子集staticArrayListSubSet(intk,stringst){intlen=st.Length;ArrayListal=newArrayList();stringtemp="";for(inti=0;i8、Pow(2
6、{item1.Add(ds.Tables[0].Rows[i]["name"].ToString());//Console.WriteLine(item1[i]);//Regexr=newRegex(",");//string[]subItem=r.Split(item1[i].ToString());stringsubItem=item1[i].ToString();for(intj=0;j7、1;//强弱类型转换}elseht.Add(subItem[j],1);}/*foreach(DictionaryEntrydeinht){Console.WriteLine("key:{0},count:{1}",de.Key,de.Value);}*/}returnht;//Console.ReadLine();}//生成字符串的K项子集staticArrayListSubSet(intk,stringst){intlen=st.Length;ArrayListal=newArrayList();stringtemp="";for(inti=0;i8、Pow(2
7、1;//强弱类型转换}elseht.Add(subItem[j],1);}/*foreach(DictionaryEntrydeinht){Console.WriteLine("key:{0},count:{1}",de.Key,de.Value);}*/}returnht;//Console.ReadLine();}//生成字符串的K项子集staticArrayListSubSet(intk,stringst){intlen=st.Length;ArrayListal=newArrayList();stringtemp="";for(inti=0;i8、Pow(2
8、Pow(2
此文档下载收益归作者所有