Пример #1
0
  public void addEntries(final Collection<Entry> batch) throws IOException {
    if (batch.size() == 0) {
      return;
    }
    final Entry entry0 = batch.getElementAt(0);
    final String table_name = this.sql_table_name;
    final List<String> keys = Collections.newList();
    final String stm = "INSERT INTO " + table_name + " " + this.paramString(entry0, keys, "(", ")");
    final MySQLConnection connection = this.db.obtainConnection();
    connection.checkIsOpen();
    try {
      final Connection mysql_connection = connection.getConnection();

      final PreparedStatement statement = mysql_connection.prepareStatement(stm);
      for (int b = 0; b < batch.size(); b++) {
        final Entry entry = batch.getElementAt(b);
        for (int i = 0; i < keys.size(); i++) {
          final String key = keys.getElementAt(i);
          // final String value = entry.getValue(key);
          final String value = entry.getValue(key);
          statement.setString(i + 1, value);
        }
        statement.addBatch();
      }
      statement.executeBatch();
    } catch (final SQLException e) {
      e.printStackTrace();
      throw new IOException(e);
    } finally {
      this.db.releaseConnection(connection);
    }
  }
Пример #2
0
  private Entry readEntry(final ResultSet result, final Collection<String> columns)
      throws SQLException {
    final Entry entry = this.newEntry();

    final int N = columns.size();
    for (int i = 0; i < N; i++) {
      final String key = columns.getElementAt(i);
      final String value = result.getString(i + 1);
      entry.set(this.schema, this.schema.indexOf(key), value);
    }
    return entry;
  }
  public static void main(final String[] args) throws IOException, URISyntaxException {
    DesktopSetup.deploy();
    Json.installComponent("com.jfixby.cmns.adopted.gdx.json.RedJson");

    final File words_folder = LocalFileSystem.ApplicationHome().child("words");
    final ChildrenList words_files = words_folder.listDirectChildren();
    final WordsSorter sorter = new WordsSorter(false);
    for (int i = 0; i < words_files.size(); i++) {
      final File file = words_files.getElementAt(i);
      final String file_name = file.getName();
      if (file_name.startsWith("#")) {
        continue;
      }
      L.d("reading", file_name);
      final String data = file.readToString();
      L.d("parsing", file_name);
      final WordCollectorFile content = Json.deserializeFromString(WordCollectorFile.class, data);

      final List<WordCollector> split = Collections.newList(content.values);
      L.d("   adding", split.size());
      sorter.addOthers(split);
    }
    sorter.filter(1);
    sorter.sort();

    // sorter.print();

    final Collection<WordCollector> terms_list = sorter.list();
    terms_list.print("terms_list", 0, 500);
    final Random random = new Random();

    final int EXTRACTIONS = 100;
    final int NUMBER_OF_TERMS = 8;

    for (int i = 0; ; i++) {
      final List<String> batch = Collections.newList();
      for (int k = 0; k < EXTRACTIONS; k++) {
        final String request = generateRequest(NUMBER_OF_TERMS, terms_list, random);
        batch.add(request);
      }
      batch.print("batch generated");
      for (int k = 0; k < batch.size(); k++) {
        final String request = batch.getElementAt(k);
        final String request_url = template + request.replaceAll(" ", "+");
        L.d(request, request_url);
        openUrl(request_url);
        Sys.sleep(10 * 1000);
      }
    }
  }
Пример #4
0
  private String paramString(
      final Entry entry,
      final List<String> keys,
      final String bracketLeft,
      final String bracketRight)
      throws IOException {
    final MySQLTableSchema schema = this.getSchema();
    final Collection<String> colums = schema.getColumns();

    for (int i = 0; i < colums.size(); i++) {
      final String key = colums.getElementAt(i);
      final String value = entry.getValue(key);
      if (value != null) {
        keys.add(key);
      }
    }
    final String schemaString = JUtils.wrapSequence(keys, keys.size(), bracketLeft, bracketRight);

    return schemaString + " VALUES " + JUtils.wrapSequence((i) -> "?", keys.size(), "(", ")");
  }
  private static String generateRequest(
      final int n, final Collection<WordCollector> terms_list, final Random random) {
    String result = "";

    final Set<String> stack = Collections.newSet();
    for (; stack.size() < n; ) {
      double d1 = random.nextDouble();
      d1 = FloatMath.power(d1, 1.0);
      int index = (int) (terms_list.size() * d1);
      index = (int) IntegerMath.limit(0, index, terms_list.size());
      final String term = terms_list.getElementAt(index).getWord();
      stack.addAll(JUtils.split(term, " "));
    }
    // stack.print("");
    for (int k = 0; k < stack.size(); k++) {
      result = result + " " + stack.getElementAt(k);
    }

    return result;
  }