Example #1
0
  public void loadDataTest(String path) {

    testUsers = new LinkedList<User>();

    User user = null;
    TreeMap<Integer, Integer> track_rating = null;
    List<Integer> tracksInTest = null;

    List<String> data = loadData(path);
    for (String str : data) {
      if (str.contains("|")) {
        if (track_rating != null) {
          user.setTracks(track_rating);
          user.setTracksInTest(tracksInTest);
          testUsers.add(user);
        }
        user = new User();
        track_rating = new TreeMap<Integer, Integer>();
        tracksInTest = new LinkedList<Integer>();
        String[] strArray = str.split("\\|");
        user.setId(Integer.parseInt(strArray[0]));
      } else {
        track_rating.put(Integer.parseInt(str), 0); // Initialize the rating 0
        tracksInTest.add(Integer.parseInt(str));
      }
    }

    user.setTracks(track_rating);
    user.setTracksInTest(tracksInTest);
    testUsers.add(user);
  }
Example #2
0
  public void loadDataTrain(String path) {

    trainUsers = new HashMap<Integer, User>();

    User user = null;
    TreeMap<Integer, Integer> track_rating = null;
    Map<Integer, Integer> album_rating = null;
    Map<Integer, Integer> artist_rating = null;
    Map<Integer, Integer> genre_rating = null;

    List<String> data = loadData(path);
    for (String str : data) {
      if (str.contains("|")) {
        if (track_rating != null) {
          user.setTracks(track_rating);
          user.setAlbums(album_rating);
          user.setArtists(artist_rating);
          user.setGeners(genre_rating);
          trainUsers.put(user.getId(), user);
        }
        user = new User();
        track_rating = new TreeMap<Integer, Integer>();
        album_rating = new HashMap<Integer, Integer>();
        artist_rating = new HashMap<Integer, Integer>();
        genre_rating = new HashMap<Integer, Integer>();
        String[] strArray = str.split("\\|");
        user.setId(Integer.parseInt(strArray[0]));
      } else {
        String[] trackRating = str.split("\t");
        int id = Integer.parseInt(trackRating[0]);
        int rating = Integer.parseInt(trackRating[1]);
        if (allAlbums.containsKey(id)) {
          album_rating.put(id, rating);
        } else if (allArtists.containsKey(id)) {
          artist_rating.put(id, rating);
        } else if (allGenres.containsKey(id)) {
          genre_rating.put(id, rating);
        } else {
          track_rating.put(Integer.parseInt(trackRating[0]), rating);
        }
      }
    }
  }