Ejemplo n.º 1
0
  public void run(ArgParser ap, Logger logger) {
    String[] files = ap.gets("manual");
    if (files != null)
      for (String f : files) {
        Document d = new Elsevier("test", f, null).next();
        if (d != null) System.out.println(d.toString());
        System.out.println();
      }

    String inTable = ap.get("inTable");
    String outTable = ap.get("outTable");

    try {
      Connection inputConn = SQL.connectMySQL(ap, logger, ap.get("inDB", "articles"));
      Statement stmt =
          inputConn.createStatement(
              java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
      stmt.setFetchSize(Integer.MIN_VALUE);
      ResultSet rs = stmt.executeQuery("SELECT doi, xml from " + inTable);
      EProblemIterator epi = new EProblemIterator(rs);
      IteratorBasedMaster<Document> master =
          new IteratorBasedMaster<Document>(epi, ap.getInt("threads", 1), 1000);
      master.startThread();

      Connection outputConn = SQL.connectMySQL(ap, logger, ap.get("outDB", "articles"));
      PreparedStatement pstmt = Document.prepareInsertStatements(outputConn, outTable);

      int report = ap.getInt("report", -1);
      int c = 0;
      int c_null = 0;

      for (Document d : master) {
        if (d != null) d.saveToDB(pstmt);
        else c_null++;

        if (report != -1 && ++c % report == 0)
          logger.info("%t: Processed " + c + " documents (" + c_null + " errors)\n");
      }

    } catch (Exception e) {
      System.err.println(e);
      e.printStackTrace();
      System.exit(-1);
    }
  }
  /** @param args */
  public static void main(String[] args) {
    ArgParser ap = ArgParser.getParser(args);
    Logger logger = Loggers.getDefaultLogger(ap);

    java.sql.Connection conn = SQL.connectMySQL(ap, logger, "farzin");
    String where = ap.get("where");
    String limit = ap.get("limit");

    Map<Integer, UniqueEvent> data = null;

    if (ap.containsKey("collapse")) {
      System.out.println("Collapsing universe data... ");
      data = collapseData(conn, where, limit);
      System.out.println("Done. Read data for " + data.size() + " hashes.");
    }

    if (ap.containsKey("load")) {
      System.out.println("Loading... ");
      data = load(conn, ap.get("load"), where, limit);
      System.out.println("Done. Read data for " + data.size() + " hashes.");
    }

    if (ap.containsKey("store")) {
      System.out.println("Storing... ");
      store(data, conn, ap.get("store"));
      System.out.println("Done. Stored data for " + data.size() + " hashes.");
    }

    if (ap.containsKey("contradictions")) {
      System.out.println("Calculating contradictions...");
      List<Pair<Integer>> contradictions = contradictions(data);
      System.out.println("Done. Detected " + contradictions.size() + " contradictions.");

      if (ap.containsKey("countTypes")) {
        System.out.println("Counting...");
        countTypes(contradictions, data);
      }

      if (ap.containsKey("sentences")) {
        System.out.println("Printing sentences...");
        printContradictorySentences(conn, ap.getInt("sentences"), contradictions, data);
      }

      if (ap.containsKey("dumpContradictions")) {
        System.out.println("Dumping...");
        dumpContradictions(contradictions, data, ap.getFile("dumpContradictions"));
      }
    }

    if (ap.containsKey("contrasts")) {
      //			contrasts(data, conn, ap.getInt("sentences",-1));
    }
  }