当前位置: 代码迷 >> 综合 >> Java学习-如何读取序列数据
  详细解决方案

Java学习-如何读取序列数据

热度:38   发布时间:2024-01-29 14:33:22.0

在序列模式挖掘中,我们的应用为

<11> 1 -1 <18> 2 -1 <23> 3 -1 -2

<33> 1 -1 <55> 2 -1 <61> 3 -1 <68> 6 -1 <84> 9 -1 -2

<10> 1 -1 <16> 2 -1 <66> 6 -1 -2

<13> 1 -1 <44> 2 -1 <49> 3 -1 <55> 6 -1 -2

<16> 1 -1 -2

那么如何读取这种数据?

源代码大致如下

package temp;import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;/**
*@author YW
*@version 创建时间:Jul 17, 20205:04:33 PM
*代码作用说明:
*/
public class sequencefile {public void loadFile(String path, double minSupportAbsolute)throws IOException{String thisLine;BufferedReader myInput = null;try {FileInputStream fis = new FileInputStream(new File(path));myInput = new BufferedReader(new InputStreamReader(fis));while((thisLine = myInput.readerLine())!= null) {if(thisLine.charAt(0) != '#'&&thisLine.charAt(0)!='%'&& thisLine.charAt(0)!='@') {addSequence(thisLine.split(" "));}}}catch(Exception e) {}finally {if(myInput != null) {myInput.close();}}}public void addSequence(String[] integers) {long timestamp;String sequence;String itemset;int start = 0;for(int i = start;i<integers.length;i++) {if(integers[i].codePointAt(0) == '<') { //TimestampString value = integers[i].substring(1,integers[i].length()-1);timestamp = Long.parseLong(value);//itemset(timestamp);}else if(integers[i].codePointAt(0) == '(') {String value2 = integers[i].substring(1,integers[i].length()-1);}else if(integers[i].equals("-1")) {//表明是一个项集。}else if(integers[i].equals("-2")) {// 表明是一个序列}}}
}