⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getfullset.java

📁 数据挖掘算法(Apriori)--JAVA实现
💻 JAVA
字号:
//File Interface
//Get data source from a file
//package apriori;
import java.io.*;
import java.lang.*;

public class GetFullSet{
	FileReader file ; //获得原文件
	FastVector vector ; //goal container
	String fName ; //store source file name
	Item item ;

	//Methods
	public GetFullSet(String filename) throws FileNotFoundException{
		file  = new FileReader(filename) ;
		fName = filename ;
	}

	public void Reset() throws IOException,FileNotFoundException{ //reload source file
		file.close();
		file = new FileReader(fName) ;
	}

	public int NumOfSets() throws IOException,FileNotFoundException{ //return the number of sets
		int num = 0 ; 
		int data = 0;
		Reset();

		while(data != -1){
			data = file.read();
			if((data==13))
				num ++;
		}
		Reset();
		return num ;
	}

	public FastVector GetSet(int k) throws IOException{ //get the kth set,return it as a vector
		int n=0;                                         //begin from 0
		int data=0;
		FastVector vector = new FastVector();
		Reset();
		while(n != k){ //locate the kth set
			data = file.read();
			if(data == 13){ //end of last set
				n++ ;
			}				
		}
		while(data == 10){ //read until '@'
			data = file.read();
		}
		
		while((data=file.read())!=13){
			if((data!=32)&&(data!=10)){
				vector.addElement(new Item(data));				
			}			
		}
		return vector ;
	}
	
	public FastVector GetAll() throws IOException{ //return a vector including all sets
		int n = NumOfSets();
		FastVector vector = new FastVector();
		for(int i=0;i<n;i++){
			vector.addElement(GetSet(i));	
		}	
		
		file.close();
		return vector ;
	}
	
	public void Print(FastVector vector) //仅供测试
	{ //itemset
		int size1 = vector.size();
		Item item ;

		for(int i=0 ; i<size1 ; i++)
		{
			item = (Item)vector.elementAt(i);
			System.out.print((char)item.Key());
			System.out.print(' ');
		}
		System.out.println(' ');
	}

	public void PrintBig(FastVector vector) //仅供测试
	{ //big
		System.out.println("size:"+vector.size());
		for(int i=0 ; i<vector.size() ; i++)
		{
			Print((FastVector)vector.elementAt(i));
			System.out.println(" ");
		}
	}
	

	public static void main(String arg[])throws IOException,FileNotFoundException{
		int num;
		System.out.println("------开始--------");
		FastVector vector;
		GetFullSet src = new GetFullSet("input.txt");
		vector=src.GetAll();
		src.PrintBig(vector);
        System.out.println("-------结束----------");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -