/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package sarproject; import java.util.*; import java.io.*; /** * * @author kurodakazima */ public class Main { /** * @param args the command line arguments */ Dataset myDataSet = new Dataset(); int bilAttribute; int counter; public void preProcessing(String namaFile) throws FileNotFoundException, IOException { readFile(namaFile); setApprox(namaFile); } public void readFile(String namaFile) throws FileNotFoundException, IOException { String cat; Scanner scanner = new Scanner(new File(namaFile)); StringTokenizer st = new StringTokenizer(scanner.nextLine()); bilAttribute = st.countTokens(); myDataSet.setAttribute(bilAttribute); counter = 1; int h = 1; do { int c = 0; while (st.hasMoreTokens()) { cat = st.nextToken(); myDataSet.att[c].categorical.add(cat); c++; } if (!scanner.hasNext()) { h = 0; } else { st = new StringTokenizer(scanner.nextLine()); counter++; } } while (h == 1); } public void setApprox(String namaFile) throws FileNotFoundException, IOException { int sizeCategory; for (int i = 0; i < bilAttribute; i++) { sizeCategory = myDataSet.att[i].categorical.size(); //System.out.println(i + " Size Category:" + sizeCategory); myDataSet.att[i].setCategory(sizeCategory); int pos = 0; for (Iterator j = myDataSet.att[i].categorical.iterator(); j.hasNext(); pos++) { Object o = j.next(); myDataSet.att[i].cat[pos].setName(o.toString()); } } Scanner scanner = new Scanner(new File(namaFile)); int objectCount = 0; while (scanner.hasNext()) { StringTokenizer st = new StringTokenizer(scanner.nextLine()); objectCount++; int posAtt = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); for (int i = 0; i < myDataSet.att[posAtt].categorical.size(); i++) { if (myDataSet.att[posAtt].cat[i].getName().equals(token)) { myDataSet.att[posAtt].cat[i].approximation.add(objectCount); } } posAtt++; } } } } public static void main(String[] args) throws FileNotFoundException, IOException { //long startTime = System.currentTimeMillis(); String namaFile = args[0]; Main oMain = new Main(); oMain.preProcessing(namaFile); } } |
ahhh! very complicated huh!
No comments:
Post a Comment