Пример #1
0
  public Result onLabel() {
    long millis = System.currentTimeMillis() % 1000;
    long result = millis - currentTimestamp;
    currentTimestamp = System.currentTimeMillis() % 1000;

    String label = request().getQueryString("action");
    String id = request().getQueryString("id");
    String reason =
        request()
            .getQueryString(
                "reason"); // remove the cluster header from Tweets and add it to labelled at the
                           // end.
    String databaseName = request().getQueryString("databaseName");
    String timestamp = Long.toString(result);

    DataAccess.labelTweet(databaseName, id, label, timestamp);

    TweetDTO tweetDTO = DataAccess.getNextTweet(databaseName);
    return ok(labelling.render(tweetDTO, databaseName));
  }
Пример #2
0
  public Result upload() {
    String databaseName = "";
    System.out.println("upload function call");

    MultipartFormData body = request().body().asMultipartFormData();
    FilePart filePart1 = body.getFile("filePart1");
    String[] searchTag = body.asFormUrlEncoded().get("db");
    String[] uploadDBName = body.asFormUrlEncoded().get("db_upload");

    databaseName = uploadDBName[0];
    System.out.println("FILE SEND!!");
    if (filePart1 != null) {
      // System.out.println("ifin ici");

    }
    File newFile1 = filePart1.getFile();
    InputStream isFile1;
    try {
      isFile1 = new FileInputStream(newFile1);
    } catch (FileNotFoundException e1) {
      isFile1 = null;
    }

    byte[] byteFile1;

    try {
      byteFile1 = IOUtils.toByteArray(isFile1);
    } catch (IOException e2) {
      byteFile1 = null;
    }
    BufferedReader reader;
    String line;
    StringBuilder stringBuilder;
    String ls;
    try {
      reader = new BufferedReader(new FileReader(newFile1));
      line = null;
      stringBuilder = new StringBuilder();
      ls = System.getProperty("line.separator");
    } catch (FileNotFoundException e1) {
      reader = null;
      line = null;
      stringBuilder = null;
      ls = null;
    }
    // System.out.println(reader);
    String[] parts;
    try {
      while ((line = reader.readLine()) != null) {
        String[] a_line_list = line.split("\t");
        String tweet = a_line_list[2];
        String id = a_line_list[0];
        String owner = a_line_list[1];
        String label = "-2";
        DataAccess.addDocument(databaseName, "tweets_unlabelled", id, owner, tweet, label, "0");
      }
    } catch (IOException e) {

    }
    try {
      FileUtils.writeByteArrayToFile(newFile1, byteFile1);
      isFile1.close();
    } catch (IOException e3) {

    }
    try {
      Thread.sleep(1000); // thread sleep for concurrent operations on ES
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    TweetDTO tweet = DataAccess.getNextTweet(databaseName);
    System.out.println(tweet.getId() + " " + tweet.getOwner() + " " + tweet.getLabel());
    return ok(labelling.render(tweet, databaseName));
  }