示例#1
0
  @Test
  public void testBecause() throws Exception {

    ServerRecommender client = getRecommender();
    List<IDValue> because = client.recommendedBecause("1", "321", 3);

    assertNotNull(because);
    assertEquals(3, because.size());

    log.info("{}", because);

    assertEquals("269", because.get(0).getID());
    assertEquals("116", because.get(1).getID());
    assertEquals("242", because.get(2).getID());

    try {
      client.recommendedBecause("0", "222", 3);
      fail();
    } catch (NoSuchUserException nsue) {
      // good
    }
    try {
      client.recommendedBecause("1", "0", 3);
      fail();
    } catch (NoSuchItemException nsie) {
      // good
    }
  }
示例#2
0
  @Test
  public void testRecommend() throws Exception {

    ServerRecommender client = getRecommender();
    List<IDValue> recs = client.recommend("1", 3);

    assertNotNull(recs);
    assertEquals(3, recs.size());

    log.info("{}", recs);

    assertEquals("475", recs.get(0).getID());
    assertEquals("582", recs.get(1).getID());
    assertEquals("403", recs.get(2).getID());

    try {
      client.recommend("0", 3);
      fail();
    } catch (NoSuchUserException nsue) {
      // good
    }

    recs = client.recommend("1", 3, true, null);

    assertNotNull(recs);
    assertEquals(3, recs.size());

    log.info("{}", recs);

    assertEquals("179", recs.get(0).getID());
    assertEquals("475", recs.get(1).getID());
    assertEquals("135", recs.get(2).getID());
  }
示例#3
0
 @Test
 public void testRecommendVersusToMany2() throws Exception {
   ServerRecommender client = getRecommender();
   List<IDValue> recs = client.recommendToMany(new String[] {"4", "2"}, 3, true, null);
   List<IDValue> recs2 = client.recommendToMany(new String[] {"2", "4"}, 3, true, null);
   assertEquals(recs, recs2);
 }
示例#4
0
  @Test
  public void testGetAllItemIDs() throws Exception {
    ServerRecommender client = getRecommender();

    Collection<String> itemIDs = client.getAllItemIDs();
    assertEquals(1682, itemIDs.size());
    for (int i = 1; i <= 1682; i++) {
      assertTrue(itemIDs.contains(Integer.toString(i)));
    }
  }
示例#5
0
  @Test
  public void testIngest() throws Exception {
    Reader reader = new StringReader("0,1\n0,2,3.0\n");

    ServerRecommender client = getRecommender();
    client.ingest(reader);

    List<IDValue> recs = client.recommend("0", 3);
    log.info("{}", recs);
    assertEquals("117", recs.get(0).getID());
  }
示例#6
0
 @Test
 public void testPopularRepresentative() throws Exception {
   ServerRecommender client = getRecommender();
   List<String> representative = client.popularRepresentativeItems();
   log.info("{}", representative);
   assertNotNull(representative);
   assertEquals(30, representative.size());
   List<String> expected =
       Arrays.asList(
           "648", "276", "1171", "408", "629", "250", "211", "403", "923", "763", "477", "171",
           "213", "421", "637", "325", "46", "214", "313", "503", "167", "515", "326", "606",
           "166", "347", "258", "713", "924", "863");
   assertEquals(expected, representative);
 }
示例#7
0
  @Test
  public void testRecommendToMany2() throws Exception {
    ServerRecommender client = getRecommender();
    List<IDValue> recs =
        client.recommendToMany(new String[] {"3", "4", "5", "6", "7"}, 3, true, null);

    assertNotNull(recs);
    assertEquals(3, recs.size());

    log.info("{}", recs);

    assertEquals("50", recs.get(0).getID());
    assertEquals("258", recs.get(1).getID());
    assertEquals("288", recs.get(2).getID());
  }
示例#8
0
  @Test
  public void testRecommendToMany() throws Exception {

    ServerRecommender client = getRecommender();
    // Adding non-existent item to make sure it is ignored
    List<IDValue> recs = client.recommendToMany(new String[] {"1", "3", "ABC"}, 3, false, null);

    assertNotNull(recs);
    assertEquals(3, recs.size());

    log.info("{}", recs);

    assertEquals("286", recs.get(0).getID());
    assertEquals("288", recs.get(1).getID());
    assertEquals("302", recs.get(2).getID());
  }
示例#9
0
  @Test
  public void testMostSimilar() throws Exception {

    ServerRecommender client = getRecommender();
    // Adding non-existent item to make sure it is ignored
    List<IDValue> similar = client.mostSimilarItems(new String[] {"449", "ABC"}, 3);

    assertNotNull(similar);
    assertEquals(3, similar.size());

    log.info("{}", similar);

    assertEquals("229", similar.get(0).getID());
    assertEquals("450", similar.get(1).getID());
    assertEquals("227", similar.get(2).getID());
  }
示例#10
0
  @Test
  public void testMostSurprising() throws Exception {
    ServerRecommender client = getRecommender();
    List<IDValue> surprising = client.mostSurprising("229", 3);

    assertNotNull(surprising);
    assertEquals(3, surprising.size());

    log.info("{}", surprising);

    assertEquals("875", surprising.get(0).getID());
    assertEquals("937", surprising.get(1).getID());
    assertEquals("358", surprising.get(2).getID());
    assertEquals(0.918288f, surprising.get(0).getValue());
    assertEquals(0.7711351f, surprising.get(1).getValue());
    assertEquals(0.7579555f, surprising.get(2).getValue());
  }
示例#11
0
  @Test
  public void testMostPopular() throws Exception {

    ServerRecommender client = getRecommender();
    List<IDValue> popular = client.mostPopularItems(3);

    assertNotNull(popular);
    assertEquals(3, popular.size());

    log.info("{}", popular);

    assertEquals("50", popular.get(0).getID());
    assertEquals("258", popular.get(1).getID());
    assertEquals("100", popular.get(2).getID());
    assertEquals(583.0f, popular.get(0).getValue());
    assertEquals(509.0f, popular.get(1).getValue());
    assertEquals(508.0f, popular.get(2).getValue());
  }
示例#12
0
  @Test
  public void testEstimate() throws Exception {

    ServerRecommender client = getRecommender();
    float[] estimates = client.estimatePreferences("10", "90", "91", "92");

    assertNotNull(estimates);
    assertEquals(3, estimates.length);

    log.info("{}", Arrays.toString(estimates));

    assertEquals(0.3006489f, estimates[0]);
    assertEquals(0.42647615f, estimates[1]);
    assertEquals(0.66089016f, estimates[2]);

    // Non-existent
    assertEquals(0.0f, client.estimatePreference("0", "90"));
    assertEquals(0.0f, client.estimatePreference("10", "0"));
  }
示例#13
0
  @Test
  public void testAnonymous2() throws Exception {

    ServerRecommender client = getRecommender();
    List<IDValue> recs = client.recommendToAnonymous(new String[] {"190"}, new float[] {1.0f}, 3);

    assertNotNull(recs);
    assertEquals(3, recs.size());

    log.info("{}", recs);

    assertEquals("83", recs.get(0).getID());
    assertEquals("213", recs.get(1).getID());
    assertEquals("86", recs.get(2).getID());

    try {
      client.recommendToAnonymous(new String[] {"0"}, 3);
      fail();
    } catch (NoSuchItemException nsie) {
      // good
    }
  }
示例#14
0
  @Test
  public void testSet() throws Exception {
    ServerRecommender client = getRecommender();

    client.setPreference("0", "1");
    List<IDValue> recs = client.recommend("0", 1);
    assertEquals("50", recs.get(0).getID());

    client.setPreference("0", "2", 3.0f);
    recs = client.recommend("0", 1);
    assertEquals("117", recs.get(0).getID());

    client.setPreference("0", "2", -3.0f);
    recs = client.recommend("0", 1);
    assertEquals("117", recs.get(0).getID());

    client.setPreference("0", "1", -1.0f);
    // Don't really know/care what will be recommend at this point; the feature vec is nearly 0
    assertEquals(1, client.recommend("0", 1).size());
  }
示例#15
0
  @Test
  public void testSetRemove() throws Exception {
    ServerRecommender client = getRecommender();

    client.setPreference("0", "1");
    List<IDValue> recs = client.recommend("0", 1);
    assertEquals("50", recs.get(0).getID());

    client.setPreference("0", "2", 1.0f);
    recs = client.recommend("0", 1);
    assertEquals("50", recs.get(0).getID());

    client.removePreference("0", "2");
    recs = client.recommend("0", 1);
    assertEquals("50", recs.get(0).getID());

    client.removePreference("0", "1");
    try {
      client.recommend("0", 1);
      fail();
    } catch (NoSuchUserException nsue) {
      // good
    }
  }
示例#16
0
 @Test
 public void testEstimateForAnonymous() throws Exception {
   ServerRecommender client = getRecommender();
   float estimate = client.estimateForAnonymous("10", new String[] {"90", "91", "92"});
   assertEquals(-0.005063545f, estimate);
 }