Ejemplo n.º 1
0
 /**
  * Try to load the root
  *
  * @return
  */
 private static XMLElement getSettingsXMLRoot() {
   XMLElement e = new XMLElement();
   try {
     URL url = classLoaderInstance.getClass().getClassLoader().getResource("settings.xml");
     e.parseFromReader(new InputStreamReader(url.openConnection().getInputStream()));
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return e;
 }
 private static XMLElement loadXML(final String pAbsoluteFilePath) {
   final XMLElement mLocalXML = new XMLElement(new Hashtable(), false, false);
   try {
     mLocalXML.parseFromReader(
         new InputStreamReader(werkzeug.Util.getInputStream(pAbsoluteFilePath)));
   } catch (IOException ex) {
     System.err.println("### ERROR / couldn t read XML file." + ex);
   }
   return mLocalXML;
 }
  public HadoopInputDirGenerator(String propFileName, int noDataSet, boolean debug)
      throws Exception {
    this.propFileName = propFileName;
    this.debug = debug;

    Properties properties = new Properties();
    try {
      properties.load(new FileInputStream(this.propFileName));

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      System.out.println("here");
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      System.out.println("here2");
      e.printStackTrace();
    }

    XMLParser xmlParser = new XMLParser();
    // Getting the path of the Dataset
    String graphsPath = properties.getProperty("path");
    // parsing the test set
    String testGraphsListPath = properties.getProperty("source");
    // parsing the training set
    String trainingGraphsListPath = properties.getProperty("target");

    XMLElement testXML = new XMLElement();
    FileReader testReader = new FileReader(testGraphsListPath);
    testXML.parseFromReader(testReader);
    Vector testListchildren = testXML.getChildren();
    XMLElement testRoot = (XMLElement) testListchildren.get(0);
    Enumeration testEnumerator = testRoot.enumerateChildren();
    String testGraphFileName = "";
    String testGraphClass = "";

    XMLElement trainingXML = new XMLElement();
    FileReader trainingReader = new FileReader(trainingGraphsListPath);
    trainingXML.parseFromReader(trainingReader);
    Vector trainingListchildren = trainingXML.getChildren();
    XMLElement trainingRoot = (XMLElement) trainingListchildren.get(0);

    String trainingGraphFileName = "";
    String trainingGraphClass = "";
    // Preparing the txt file ...
    PrintStream ps;

    File theDir = new File(properties.getProperty("path") + "inputs");

    // if the directory does not exist, create it
    if (!theDir.exists()) {
      System.out.println("creating directory: ");
      boolean result = theDir.mkdir();
      if (result) {
        System.out.println("DIR created");
      }
    }

    while (testEnumerator.hasMoreElements()) {
      XMLElement testChild = (XMLElement) testEnumerator.nextElement();
      testGraphFileName = (String) testChild.getAttribute("file", null);
      testGraphClass = (String) testChild.getAttribute("class", "NO_CLASS");
      Enumeration trainingEnumerator = trainingRoot.enumerateChildren();

      while (trainingEnumerator.hasMoreElements()) {
        XMLElement trainingChild = (XMLElement) trainingEnumerator.nextElement();
        trainingGraphFileName = (String) trainingChild.getAttribute("file", null);
        trainingGraphClass = (String) trainingChild.getAttribute("class", "NO_CLASS");
        ps =
            new PrintStream(
                properties.getProperty("path")
                    + "inputs/"
                    + testGraphFileName
                    + "-"
                    + trainingGraphFileName
                    + ".txt");
        System.out.println(
            noDataSet
                + "	"
                + testGraphFileName
                + "	"
                + trainingGraphFileName
                + "	"
                + testGraphClass
                + "	"
                + trainingGraphClass);
        ps.println(
            noDataSet
                + "	"
                + testGraphFileName
                + "	"
                + trainingGraphFileName
                + "	"
                + testGraphClass
                + "	"
                + trainingGraphClass);
        ps.close();
      }
    }
  }