Package org.apache.mahout.cf.taste.model

Examples of org.apache.mahout.cf.taste.model.IDMigrator


  private static final String DUMMY_STRING = "Mahout";
  private static final long DUMMY_ID = -6311185995763544451L;

  public void testToLong() {
    IDMigrator migrator = new MemoryIDMigrator();
    long id = migrator.toLongID(DUMMY_STRING);
    assertEquals(DUMMY_ID, id);
  }
View Full Code Here


    long id = migrator.toLongID(DUMMY_STRING);
    assertEquals(DUMMY_ID, id);
  }

  public void testStore() throws Exception {
    IDMigrator migrator = new MemoryIDMigrator();
    long id = migrator.toLongID(DUMMY_STRING);
    assertNull(migrator.toStringID(id));
    migrator.storeMapping(id, DUMMY_STRING);
    assertEquals(DUMMY_STRING, migrator.toStringID(id));
  }
View Full Code Here

    migrator.storeMapping(id, DUMMY_STRING);
    assertEquals(DUMMY_STRING, migrator.toStringID(id));
  }

  public void testInitialize() throws Exception {
    IDMigrator migrator = new MemoryIDMigrator();
    long id = migrator.toLongID(DUMMY_STRING);
    assertNull(migrator.toStringID(id));
    migrator.initialize(Collections.singleton(DUMMY_STRING));
    assertEquals(DUMMY_STRING, migrator.toStringID(id));
  }
View Full Code Here

    writeLines(testFile, STRING_IDS);
  }

  @Test
  public void testLoadFromFile() throws Exception {
    IDMigrator migrator = new FileIDMigrator(testFile);
    long dogAsLong = migrator.toLongID("dog");
    long cowAsLong = migrator.toLongID("cow");
    long donkeyAsLong = migrator.toLongID("donkey");
    assertEquals("dog", migrator.toStringID(dogAsLong));
    assertEquals("cow", migrator.toStringID(cowAsLong));
    assertNull(migrator.toStringID(donkeyAsLong));
  }
View Full Code Here

    assertNull(migrator.toStringID(donkeyAsLong));
  }

  @Test
  public void testNoRefreshAfterFileUpdate() throws Exception {
    IDMigrator migrator = new FileIDMigrator(testFile, 0L);

    /* call a method to make sure the original file is loaded */
    long dogAsLong = migrator.toLongID("dog");
    migrator.toStringID(dogAsLong);

    /* change the underlying file,
     * we have to wait at least a second to see the change in the file's lastModified timestamp */
    Thread.sleep(2000L);
    writeLines(testFile, UPDATED_STRING_IDS);

    /* we shouldn't see any changes in the data as we have not yet refreshed */
    long cowAsLong = migrator.toLongID("cow");
    long donkeyAsLong = migrator.toLongID("donkey");
    assertEquals("dog", migrator.toStringID(dogAsLong));
    assertEquals("cow", migrator.toStringID(cowAsLong));
    assertNull(migrator.toStringID(donkeyAsLong));
  }
View Full Code Here

    assertNull(migrator.toStringID(donkeyAsLong));
  }

  @Test
  public void testRefreshAfterFileUpdate() throws Exception {
    IDMigrator migrator = new FileIDMigrator(testFile, 0L);

    /* call a method to make sure the original file is loaded */
    long dogAsLong = migrator.toLongID("dog");
    migrator.toStringID(dogAsLong);

    /* change the underlying file,
     * we have to wait at least a second to see the change in the file's lastModified timestamp */
    Thread.sleep(2000L);
    writeLines(testFile, UPDATED_STRING_IDS);

    migrator.refresh(null);

    long cowAsLong = migrator.toLongID("cow");
    long donkeyAsLong = migrator.toLongID("donkey");
    assertEquals("dog", migrator.toStringID(dogAsLong));
    assertEquals("cow", migrator.toStringID(cowAsLong));
    assertEquals("donkey", migrator.toStringID(donkeyAsLong));
  }
View Full Code Here

  private static final String DUMMY_STRING = "Mahout";
  private static final long DUMMY_ID = -6311185995763544451L;

  @Test
  public void testToLong() {
    IDMigrator migrator = new MemoryIDMigrator();
    long id = migrator.toLongID(DUMMY_STRING);
    assertEquals(DUMMY_ID, id);
  }
View Full Code Here

      log.info("No input files in {}", inputDir);
      return;
    }
    Arrays.sort(inputFiles, ByLastModifiedComparator.INSTANCE);

    IDMigrator hash = new OneWayMigrator();

    int lines = 0;
    int badLines = 0;
    for (File inputFile : inputFiles) {
      log.info("Reading {}", inputFile);
      for (String line : new FileLineIterable(inputFile)) {
       
        if (badLines > 100) { // Crude check
          throw new IOException("Too many bad lines; aborting");
        }
       
        lines++;
       
        if (line.isEmpty() || line.charAt(0) == '#') {
          continue;
        }
       
        Iterator<String> it = COMMA.split(line).iterator();

        long userID;
        boolean userIsTag;
        long itemID;
        boolean itemIsTag;
        float value;
        try {
         
          String userIDString = it.next();
          userIsTag = userIDString.startsWith("\"");
          if (userIsTag) {
            userID = hash.toLongID(userIDString.substring(1, userIDString.length() - 1));
          } else {
            userID = Long.parseLong(userIDString);
          }
         
          String itemIDString = it.next();
          itemIsTag = itemIDString.startsWith("\"");
          if (itemIsTag) {
            itemID = hash.toLongID(itemIDString.substring(1, itemIDString.length() - 1));
          } else {
            itemID = Long.parseLong(itemIDString);           
          }
         
          if (it.hasNext()) {
View Full Code Here

public final class OneWayMigratorTest extends MyrrixTest {

  @Test
  public void testForward() throws Exception {
    IDMigrator migrator = new OneWayMigrator();
    assertEquals(4060265690780417169L, migrator.toLongID("foobar"));
    assertEquals(-3162216497309240828L, migrator.toLongID(""));
  }
View Full Code Here

    assertEquals(-3162216497309240828L, migrator.toLongID(""));
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testBackward() throws Exception {
    IDMigrator migrator = new OneWayMigrator();
    migrator.toStringID(0L);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.model.IDMigrator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.