@Test public void testCloudNormalization() { List<Tag> cloud = new ArrayList<>(); RelationTagService.normalizeCloud(cloud, 0, 0, true); cloud.add(new Tag("a", 3)); RelationTagService.normalizeCloud(cloud, 3, 3, true); assertEquals(100, cloud.get(0).getWeight()); cloud.add(new Tag("a", 3)); RelationTagService.normalizeCloud(cloud, 3, 3, false); assertEquals(100, cloud.get(0).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 5)); RelationTagService.normalizeCloud(cloud, 1, 5, true); assertEquals(0, cloud.get(0).getWeight()); assertEquals(100, cloud.get(1).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 5)); RelationTagService.normalizeCloud(cloud, 1, 5, false); assertEquals(0, cloud.get(0).getWeight()); assertEquals(100, cloud.get(1).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 2)); cloud.add(new Tag("c", 5)); RelationTagService.normalizeCloud(cloud, 1, 5, true); assertEquals(0, cloud.get(0).getWeight()); assertEquals(25, cloud.get(1).getWeight()); assertEquals(100, cloud.get(2).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 2)); cloud.add(new Tag("c", 5)); RelationTagService.normalizeCloud(cloud, 1, 5, false); assertEquals(0, cloud.get(0).getWeight()); assertEquals(43, cloud.get(1).getWeight()); assertEquals(100, cloud.get(2).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 2)); cloud.add(new Tag("c", 5)); cloud.add(new Tag("d", 12)); RelationTagService.normalizeCloud(cloud, 1, 12, true); assertEquals(0, cloud.get(0).getWeight()); assertEquals(9, cloud.get(1).getWeight()); assertEquals(36, cloud.get(2).getWeight()); assertEquals(100, cloud.get(3).getWeight()); cloud = new ArrayList<>(); cloud.add(new Tag("a", 1)); cloud.add(new Tag("b", 2)); cloud.add(new Tag("c", 5)); cloud.add(new Tag("d", 12)); RelationTagService.normalizeCloud(cloud, 1, 12, false); assertEquals(0, cloud.get(0).getWeight()); assertEquals(28, cloud.get(1).getWeight()); assertEquals(65, cloud.get(2).getWeight()); assertEquals(100, cloud.get(3).getWeight()); }
public static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear) { if (min == max) { for (Tag tag : cloud) { tag.setWeight(100); } return; } double nmin; double diff; if (linear) { nmin = min; diff = max - min; } else { nmin = Math.log(min); diff = Math.log(max) - nmin; } for (Tag tag : cloud) { long weight = tag.getWeight(); double norm; if (linear) { norm = (weight - nmin) / diff; } else { norm = (Math.log(weight) - nmin) / diff; } tag.setWeight(Math.round(100 * norm)); } }
RelationTagService extends AbstractTagService { public static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear) { if (min == max) { for (Tag tag : cloud) { tag.setWeight(100); } return; } double nmin; double diff; if (linear) { nmin = min; diff = max - min; } else { nmin = Math.log(min); diff = Math.log(max) - nmin; } for (Tag tag : cloud) { long weight = tag.getWeight(); double norm; if (linear) { norm = (weight - nmin) / diff; } else { norm = (Math.log(weight) - nmin) / diff; } tag.setWeight(Math.round(100 * norm)); } } }
RelationTagService extends AbstractTagService { public static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear) { if (min == max) { for (Tag tag : cloud) { tag.setWeight(100); } return; } double nmin; double diff; if (linear) { nmin = min; diff = max - min; } else { nmin = Math.log(min); diff = Math.log(max) - nmin; } for (Tag tag : cloud) { long weight = tag.getWeight(); double norm; if (linear) { norm = (weight - nmin) / diff; } else { norm = (Math.log(weight) - nmin) / diff; } tag.setWeight(Math.round(100 * norm)); } }  }
RelationTagService extends AbstractTagService { public static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear) { if (min == max) { for (Tag tag : cloud) { tag.setWeight(100); } return; } double nmin; double diff; if (linear) { nmin = min; diff = max - min; } else { nmin = Math.log(min); diff = Math.log(max) - nmin; } for (Tag tag : cloud) { long weight = tag.getWeight(); double norm; if (linear) { norm = (weight - nmin) / diff; } else { norm = (Math.log(weight) - nmin) / diff; } tag.setWeight(Math.round(100 * norm)); } }  @Override boolean hasFeature(Feature feature); @Override boolean supportsTag(CoreSession session, String docId); @Override void doTag(CoreSession session, String docId, String label, String username); @Override void doUntag(CoreSession session, String docId, String label); @Override Set<String> doGetTags(CoreSession session, String docId); @Override void doCopyTags(CoreSession session, String srcDocId, String dstDocId, boolean removeExistingTags); @Override List<String> doGetTagDocumentIds(CoreSession session, String label); @Override Set<String> doGetTagSuggestions(CoreSession session, String label); @Override boolean canUntag(CoreSession session, String docId, String label); @Override List<Tag> getTagCloud(CoreSession session, String docId, String username, Boolean normalize); static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear); }
RelationTagService extends AbstractTagService { public static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear) { if (min == max) { for (Tag tag : cloud) { tag.setWeight(100); } return; } double nmin; double diff; if (linear) { nmin = min; diff = max - min; } else { nmin = Math.log(min); diff = Math.log(max) - nmin; } for (Tag tag : cloud) { long weight = tag.getWeight(); double norm; if (linear) { norm = (weight - nmin) / diff; } else { norm = (Math.log(weight) - nmin) / diff; } tag.setWeight(Math.round(100 * norm)); } }  @Override boolean hasFeature(Feature feature); @Override boolean supportsTag(CoreSession session, String docId); @Override void doTag(CoreSession session, String docId, String label, String username); @Override void doUntag(CoreSession session, String docId, String label); @Override Set<String> doGetTags(CoreSession session, String docId); @Override void doCopyTags(CoreSession session, String srcDocId, String dstDocId, boolean removeExistingTags); @Override List<String> doGetTagDocumentIds(CoreSession session, String label); @Override Set<String> doGetTagSuggestions(CoreSession session, String label); @Override boolean canUntag(CoreSession session, String docId, String label); @Override List<Tag> getTagCloud(CoreSession session, String docId, String username, Boolean normalize); static void normalizeCloud(List<Tag> cloud, int min, int max, boolean linear);  }