Esempio n. 1
0
  /** Overriden method from SQLMultiSource */
  public Rating next() {
    if (!hasNext()) return null;

    Rating l = new Rating(instances);
    Attribute[] attributes = getAttributes();
    SparseInstance d = new SparseInstance(attributes.length - 2);
    Long start;
    try {
      l.setUserId(Utils.objectToInteger(records.getObject(1)));
      l.setObjectId(Utils.objectToInteger(records.getObject(2)));
      int flixId = Integer.parseInt(records.getObject(2).toString());
      int i = 0;
      for (; i < this.attributes.length; i++) {
        start = System.currentTimeMillis();
        if (attributes[i].isNominal()) d.setValue(i, records.getObject(i + 3).toString());
        else d.setValue(i, Utils.objectToDouble(records.getObject(i + 3)));
        Oracle += System.currentTimeMillis() - start;
      }
      SparseInstance movie = imdb.getMovie(flixId);
      d = (SparseInstance) d.mergeInstance(movie);
      d.setDataset(instances);

      start = System.currentTimeMillis();
      records.next();
      Oracle += System.currentTimeMillis() - start;
    } catch (SQLException e) {
      e.printStackTrace();
      return null;
    }
    l.setRecord(d);
    return l;
  }
 public void useUserRatingsForContent(int userId) {
   // Use the user's ratings
   // Integer userIdDataset;
   // int current = content.getCurrentUser();
   /// content.restartUserId();
   // while( (userIdDataset= content.userId())!=null){
   //	content.setFixedUserId(userIdDataset);
   content.restart();
   // if (!content.hasNext())
   //	continue;
   Rating rec;
   while ((rec = (Rating) content.next()) != null) {
     // int userId = rec.getUserId();
     int objectId = rec.getObjectId();
     rec.setRating(usersRatings.get(userId).get(objectId));
   }
   // }
   // content.setFixedUserId(current);
 }
  public void usePredictedRatingsForContent(Method m, int userId) {
    // Store the original ratings in the map.
    Rating rec;
    content.setFixedUserId(userId);
    content.restart();
    while ((rec = (Rating) content.next()) != null) {
      int objectId = rec.getObjectId();
      double rating = rec.getRating();

      if (!usersRatings.containsKey(userId))
        usersRatings.put(userId, new HashMap<Integer, Double>());

      usersRatings.get(userId).put(objectId, rating);
    }
    // Use the ratings from the behaviour method
    content.restart();
    while ((rec = (Rating) content.next()) != null) {
      Double r = (Double) m.classifyRecord(rec);
      if (r != null) rec.setRating(r);
    }
  }