Ejemplo n.º 1
0
  @Test
  public void rateResourceTest() throws DBError, SQLException {

    String user = "******";
    env.proteus.userdb.register(user);
    Parameters p = env.proteus.userdb.login(user);
    Credentials cred = new Credentials(p);

    env.proteus.userdb.createCorpus("test corpus 1", "user");

    String res1 = "document1";
    Integer corpus1 = 1;
    Parameters rating = Parameters.create();
    rating.set("resource", res1);
    rating.set("rating", 2);
    rating.set("corpus", corpus1);
    rating.set("corpusName", "test corpus 1");
    Parameters c = cred.toJSON();
    rating.copyFrom(c);

    Parameters results = Parameters.create();
    try {
      RateResource rr = new RateResource(env.proteus);
      results = rr.handle(null, null, rating, null);
    } catch (HTTPError httpError) {
      fail(httpError.getMessage());
    }

    results = env.proteus.userdb.getResourceRatings(res1, corpus1);
    assertEquals(results.get("aveRating", -1), 2);
    assertEquals(results.getAsList("ratings").size(), 1);
  }
Ejemplo n.º 2
0
 @Override
 public void run(Parameters p, PrintStream output) throws Exception {
   String indexPath = p.getString("indexPath");
   String identifier = p.getString("identifier");
   run(new String[] {"", indexPath, identifier}, output);
 }
Ejemplo n.º 3
0
  @Override
  public void run(Parameters parameters, PrintStream out) throws Exception {
    if (!(parameters.containsKey("query") || parameters.containsKey("queries"))) {
      out.println(this.getHelpString());
      return;
    }

    // ensure we can print to a file instead of the commandline
    if (parameters.isString("outputFile")) {
      boolean append = parameters.get("appendFile", false);
      out =
          new PrintStream(
              new BufferedOutputStream(
                  new FileOutputStream(parameters.getString("outputFile"), append)));
    }

    // check if we can print to a file instead of the commandline (else use stderr, same as verbose)
    PrintStream times = System.err;
    if (parameters.isString("timesFile")) {
      boolean append = parameters.get("appendTimes", false);
      times =
          new PrintStream(
              new BufferedOutputStream(
                  new FileOutputStream(parameters.getString("timesFile"), append)));
    }

    // get queries
    List<Parameters> queries = JSONQueryFormat.collectQueries(parameters);

    // open index
    Retrieval retrieval = RetrievalFactory.create(parameters);

    // record results requested
    int requested = (int) parameters.get("requested", 1000);

    // And repeats
    int repeats = (int) parameters.get("repeats", 5);

    // timing variables
    long batchstarttime, batchendtime;
    long querystarttime, querymidtime, queryendtime;
    long[] batchTimes = new long[repeats];
    // keys should be in sorted order for ordered printing
    Map<String, long[]> queryTimes = new TreeMap();
    Map<String, long[]> queryExecTimes = new TreeMap();

    Random rnd = null;
    if (parameters.containsKey("seed")) {
      long seed = parameters.getLong("seed");
      rnd = new Random(seed);
    }

    for (int rep = 0; rep < repeats; rep++) {

      // randomize the query order:
      if (rnd != null) {
        Collections.shuffle(queries, rnd);
      }

      batchstarttime = System.currentTimeMillis();

      // for each query, run it, get the results, print in TREC format
      for (Parameters query : queries) {

        querystarttime = System.currentTimeMillis();

        String queryText = query.getString("text");
        String queryNumber = query.getString("number");

        query.setBackoff(parameters);
        query.set("requested", requested);

        // option to fold query cases -- note that some parameters may require upper case
        if (query.get("casefold", false)) {
          queryText = queryText.toLowerCase();
        }

        if (parameters.get("verbose", false)) {
          logger.info("RUNNING: " + queryNumber + " : " + queryText);
        }

        // parse and transform query into runnable form
        Node root = StructuredQuery.parse(queryText);
        Node transformed = retrieval.transformQuery(root, query);

        querymidtime = System.currentTimeMillis();

        if (parameters.get("verbose", false)) {
          logger.info("Transformed Query:\n" + transformed.toPrettyString());
        }

        // run query
        List<ScoredDocument> results = retrieval.executeQuery(transformed, query).scoredDocuments;

        queryendtime = System.currentTimeMillis();

        if (!queryTimes.containsKey(queryNumber)) {
          queryTimes.put(queryNumber, new long[repeats]);
          queryExecTimes.put(queryNumber, new long[repeats]);
        }
        queryTimes.get(queryNumber)[rep] = (queryendtime - querystarttime);
        queryExecTimes.get(queryNumber)[rep] = (queryendtime - querymidtime);

        // if we have some results -- print in to output stream
        if (rep == 0 && !results.isEmpty()) {
          for (ScoredDocument sd : results) {
            if (parameters.get("trec", false)) {
              out.println(sd.toTRECformat(queryNumber));
            } else {
              out.println(sd.toString(queryNumber));
            }
          }
        }
      }

      batchendtime = System.currentTimeMillis();
      batchTimes[rep] = (batchendtime - batchstarttime);
    }

    if (parameters.isString("outputFile")) {
      out.close();
    }

    printTimingData(times, batchTimes, queryTimes, queryExecTimes);

    if (parameters.isString("timesFile")) {
      times.close();
    }
  }