public void loadFileKosarakFormat(String filepath, int nblinetoread) throws IOException { String thisLine; BufferedReader myInput = null; try { FileInputStream fin = new FileInputStream(new File(filepath)); myInput = new BufferedReader(new InputStreamReader(fin)); int i = 0; while ((thisLine = myInput.readLine()) != null) { // ajoute une séquence String[] split = thisLine.split(" " i++; if (nblinetoread == i) { break; } Sequence sequence = new Sequence(); for (String value : split) { List<Integer> itemset = new ArrayList<Integer>(); Integer item = Integer.parseInt(value); itemset.add(item); sequence.addItemset(itemset.toArray()); } sequences.add(sequence); } } catch (Exception e) { e.printStackTrace(); } finally { if (myInput != null) { myInput.close(); } } }
public void loadFileWebViewFOrmat(String filepath, int nbLine) { String thisLine; BufferedReader myInput = null; try { FileInputStream fin = new FileInputStream(new File(filepath)); myInput = new BufferedReader(new InputStreamReader(fin)); int realID = 0; int lastId = 0; Sequence sequence = null; while ((thisLine = myInput.readLine()) != null) { // ajoute une séquence String[] split = thisLine.split(" " int id = Integer.parseInt(split[0]); int val = Integer.parseInt(split[1]); if(lastId != id){ if(lastId!=0 ){ //&& sequence.size() >=2 sequences.add(sequence); realID++; } sequence = new Sequence(); lastId = id; } List<Integer> itemset = new ArrayList<Integer>(); itemset.add(val); sequence.addItemset(itemset.toArray()); } } catch (Exception e) { e.printStackTrace(); } }
public void loadSnakeDataset(String filepath, int nbLine) { String thisLine; BufferedReader myInput = null; try { FileInputStream fin = new FileInputStream(new File(filepath)); myInput = new BufferedReader(new InputStreamReader(fin)); while ((thisLine = myInput.readLine()) != null) { if(thisLine.length() >= 50){ Sequence sequence = new Sequence(); for(int i=0; i< thisLine.length(); i++){ List<Integer> itemset = new ArrayList<Integer>(); int character = thisLine.toCharArray()[i ] - 65; System.out.println(thisLine.toCharArray()[i ] + " " + character); itemset.add(character); sequence.addItemset(itemset.toArray()); } sequences.add(sequence); } } } catch (Exception e) { e.printStackTrace(); } }
public void loadFileSignLanguage(String fileToPath, int i) { String thisLine; BufferedReader myInput = null; try { FileInputStream fin = new FileInputStream(new File(fileToPath)); myInput = new BufferedReader(new InputStreamReader(fin)); String oldUtterance = "-1"; Sequence sequence = null; while ((thisLine = myInput.readLine()) != null) { if(thisLine.length() >= 1 && thisLine.charAt(0) != '#'){ String []tokens = thisLine.split(" " String currentUtterance = tokens[0]; if(!currentUtterance.equals(oldUtterance)){ if(sequence != null){ sequences.add(sequence); } sequence = new Sequence(); oldUtterance = currentUtterance; } for(int j=1; j< tokens.length; j++){ int character = Integer.parseInt(tokens[j]); if(character == -11 || character == -12){ continue; } if(character >= maxItem){ maxItem = character; } if(character < minItem){ minItem = character; } sequence.addItemset(new Object[]{character}); } } } sequences.add(sequence); System.out.println(sequence.toString()); } catch (Exception e) { e.printStackTrace(); } }
public void loadFileMSNBCFormat(String filepath, int nblinetoread) throws IOException { String thisLine; BufferedReader myInput = null; try { FileInputStream fin = new FileInputStream(new File(filepath)); myInput = new BufferedReader(new InputStreamReader(fin)); int i = 0; while ((thisLine = myInput.readLine()) != null) { String[] split = thisLine.split(" " i++; if (nblinetoread == i) { break; } Sequence sequence = new Sequence(sequences.size()); for (String value : split) { Itemset itemset = new Itemset(); itemset.addItem(Integer.parseInt(value)); sequence.addItemset(itemset); } sequences.add(sequence); } } catch (Exception e) { e.printStackTrace(); } finally { if (myInput != null) { myInput.close(); } } }
public void loadFileBinaryFormat(String path) throws IOException { String thisLine; // BufferedReader myInput = null; DataInputStream myInput = null; try { FileInputStream fin = new FileInputStream(new File(path)); myInput = new DataInputStream(fin); Sequence sequence = new Sequence(sequences.size()); Itemset itemset = new Itemset(); while (myInput.available() != 0) { int value = INT_little_endian_TO_big_endian(myInput.readInt()); if (value == -1) { // indicate the end of an itemset sequence.addItemset(itemset); itemset = new Itemset(); } else if (value == -2) { // indicate the end of a sequence sequences.add(sequence); sequence = new Sequence(sequences.size()); } else { // extract the value for an item Item item = new Item(value); itemset.addItem(item); } } } catch (Exception e) { e.printStackTrace(); } } // This function was written by Anghel Leonard: int INT_little_endian_TO_big_endian(int i) { return ((i & 0xff) << 24) + ((i & 0xff00) << 8) + ((i & 0xff0000) >> 8) + ((i >> 24) & 0xff); }
public void loadFileBinaryFormat(String path) throws IOException { String thisLine; // BufferedReader myInput = null; DataInputStream myInput = null; try { FileInputStream fin = new FileInputStream(new File(path)); myInput = new DataInputStream(fin); Sequence sequence = new Sequence(sequences.size()); Itemset itemset = new Itemset(); while (myInput.available() != 0) { int value = INT_little_endian_TO_big_endian(myInput.readInt()); if (value == -1) { // indicate the end of an itemset sequence.addItemset(itemset); itemset = new Itemset(); } else if (value == -2) { // indicate the end of a sequence // check if the last "-1" was not included if (itemset.size() > 0) { sequence.addItemset(itemset); itemset = new Itemset(); } sequences.add(sequence); sequence = new Sequence(sequences.size()); } else { // extract the value for an item Item item = new Item(value); itemset.addItem(item); } } sequences.add(sequence); } catch (Exception e) { e.printStackTrace(); } } // 4-byte number this function was taken from the internet (by Anghel // Leonard) int INT_little_endian_TO_big_endian(int i) { return ((i & 0xff) << 24) + ((i & 0xff00) << 8) + ((i & 0xff0000) >> 8) + ((i >> 24) & 0xff); }
-ncust number_of_customers_in_000s (default: 100) -slen avg_trans_per_customer (default: 10) -tlen avg_items_per_transaction (default: 2.5) -nitems number_of_different_items_in_000s (default: 10) -rept repetition-level (default: 0) -seq.npats number_of_seq_patterns (default: 5000) -seq.patlen avg_length_of_maximal_pattern (default: 4) -seq.corr correlation_between_patterns (default: 0.25) -seq.conf avg_confidence_in_a_rule (default: 0.75) -lit.npats number_of_patterns (default: 25000) -lit.patlen avg_length_of_maximal_pattern (default: 1.25) -lit.corr correlation_between_patterns (default: 0.25) -lit.conf avg_confidence_in_a_rule (default: 0.75) -fname <filename> (write to filename.data and filename.pat) -ascii (Write data in ASCII format; default: False) -version (to print out version info)
HashMap<Integer, Integer> count = new HashMap<Integer, Integer>(); for each sequence... HashSet<Integer> alreadyCounted = new HashSet<Integer>(); for each itemset for each item if the item is not in alreadyCounted then increase the count of the item in the hashmap add the item to alreadyCounted.
public void assocation_Rule_Generation(){ try{ System.out.println("***************Assocations Rule Found *********************\n" for(int i=0;i<maximal.size();i++){ String first= maximal.get(i); double forFisrt = maximal_list.get(first);// this were we store all the items the stisfy the minsup in the file for(int x=0;x<maximal.size();x++){ String second = maximal.get(x); if(!first.equals(second)){ double forSecond = maximal_list.get(second); double fconfidenst =(forSecond/forFisrt)*100; if(fconfidenst >=conf){ System.out.printf("%-8s ==> %-8s conf %.2f",first,second,fconfidenst); System.out.print("%" System.out.println(); } } } } }catch(Exception e){ System.out.println(e); e.printStackTrace(); } }
String filepath = "kosarak.txt"; // replace this with the input file path String thisLine; BufferedReader myInput = null; try { int seqID = 0; FileInputStream fin = new FileInputStream(new File(filepath)); myInput = new BufferedReader(new InputStreamReader(fin)); while ((thisLine = myInput.readLine()) != null) { System.out.println("Sequence #" + seqID); // for each sequence String[] split = thisLine.split(" " ) ; for (String value : split) { Integer item = Integer.parseInt(value) ; System.out.print(item + " " ); } System.out.println(); seqID++; } } catch (Exception e) { e.printStackTrace() ; } finally { if (myInput != null) { myInput.close() ; } }