Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package computeBase; import static computeBase.Main.path1; import static computeBase.Main.path2; import java.io.*; import java.util.ArrayList; import org.jdom2.*; import org.jdom2.input.*; import java.util.List; import java.util.Iterator; import org.openscience.cdk.exception.CDKException; import org.openscience.cdk.interfaces.IAtomContainer; /** * * @author oxis */ public enum ParseDataset { INSTANCE; private final org.jdom2.Document document; private final Element drugs; private final List<IAtomContainer> ListDrug = new ArrayList<>(); private ParseDataset() { //On cre une instance de SAXBuilder /*File file; if(new File(path1 + "trainingset_uncomputed.xml").isFile()) { file = new File(path1 + "trainingset_uncomputed.xml"); } else { file = new File(path2 + "trainingset_uncomputed.xml"); }*/ File file; if (new File(path1 + "testingset_uncomputed.xml").isFile()) { file = new File(path1 + "testingset_uncomputed.xml"); } else { file = new File(path2 + "testingset_uncomputed.xml"); } SAXBuilder sxb = new SAXBuilder(); try { //On cre un nouveau document JDOM avec en argument le fichier XML //Le parsing est termin ;) document = sxb.build(file); } catch (IOException | JDOMException e) { throw new RuntimeException(e); } //On initialise un nouvel lment racine avec l'lment racine du document. drugs = document.getRootElement(); } public List<IAtomContainer> getStructs() { //On cre une List contenant tous les noeuds "etudiant" de l'Element racine List listDrugs = drugs.getChildren("drug"); float logp = 0; String smiles = ""; String name; String cas; DrugStruct tmpDrug; int good = 0; int bad = 0; //On cre un Iterator sur notre liste Iterator itDrug = listDrugs.iterator(); while (itDrug.hasNext()) { Element drug = (Element) itDrug.next(); name = drug.getChild("name").getText(); cas = drug.getChild("cas-number").getText(); List listExpProp = drug.getChild("experimental-properties").getChildren("property"); Iterator itExpProp = listExpProp.iterator(); while (itExpProp.hasNext()) { Element expProp = (Element) itExpProp.next(); if (expProp.getChild("kind").getText().equals("logP")) { logp = Float.parseFloat(expProp.getChild("value").getText()); } } List listCalcProp = drug.getChild("calculated-properties").getChildren("property"); Iterator itCalcProp = listCalcProp.iterator(); while (itCalcProp.hasNext()) { Element calcProp = (Element) itCalcProp.next(); if (calcProp.getChild("kind").getText().equals("SMILES")) { smiles = calcProp.getChild("value").getText(); } } try { tmpDrug = new DrugStruct(smiles, logp, name, cas); ListDrug.add(tmpDrug.drug); good++; } catch (CDKException e) { System.out.println("---BUG--- " + name + " -- " + cas + " -- " + smiles + " -- " + logp); bad++; } System.out.println(good + "/" + bad); } return ListDrug; } // ExecutorService executors = Executors.newFixedThreadPool(4); // Future<Object> future = executors.submit(new Callable<Object>(){ // public Object call() throws Exception { // .. // } // }); }