Ejemplo n.º 1
0
  @Test
  public void resultsSerializationTest() {
    ArrayList<String> categories = new ArrayList<String>();
    categories.add("category1");
    categories.add("category2");

    MemoryJobStorage js = new MemoryJobStorage();
    IResults<String, DatumResult, WorkerResult> results =
        js.getNominalResults("testid", categories);
    LObject<String> obj = new LObject<String>("obj");
    obj.setEvaluationLabel("category2");
    DatumResult dr = results.getOrCreateDatumResult(obj);
    Map<String, Double> categoryProb = new HashMap<String, Double>();
    categoryProb.put("category1", 0.3);
    categoryProb.put("category2", 0.7);
    dr.setCategoryProbabilites(categoryProb);
    results.addDatumResult(obj, dr);
    String serialized = gson.toJson(results);
    LObject<String> imaginaryObj = new LObject<String>("ImaginaryObj");
    Worker imaginaryWorker = new Worker("ImaginaryWorker");

    InMemoryResults<String, DatumResult, WorkerResult> deserialized =
        gson.fromJson(
            serialized,
            new TypeToken<InMemoryResults<String, DatumResult, WorkerResult>>() {}.getType());
    //		Assert.assertEquals(deserialized.getOrCreateDatumResult(imaginaryObj).getClass(),
    //				results.getOrCreateDatumResult(imaginaryObj).getClass());
    //		Assert.assertEquals(deserialized.getOrCreateWorkerResult(imaginaryWorker).getClass(),
    //				results.getOrCreateWorkerResult(imaginaryWorker).getClass());
    // ^^^ above doesn't work - it works when jsoned at job level
    Assert.assertNotNull(deserialized.getDatumResult(obj));
    DatumResult ddr = deserialized.getDatumResult(obj);
    Assert.assertEquals(ddr.getCategoryProbabilites(), dr.getCategoryProbabilites());
    Assert.assertEquals(gson.toJson(deserialized), serialized);
  }
 public static NominalProject setUpNominalProject() {
   IncrementalMV imv = new IncrementalMV();
   MemoryJobStorage js = new MemoryJobStorage();
   Collection<String> categories = Arrays.asList(new String[] {"A", "B", "C"});
   NominalProject project =
       new NominalProject(
           imv, js.getNominalData("testId"), js.getNominalResults("testId", categories));
   project.initializeCategories(categories, null, null);
   project.getData().addNewUpdatableAlgorithm(imv);
   return project;
 }