LabelBuilder { public Label[] buildLabel(Map<String, Object> obj, String path) { Strings strings = new Strings(); List<String> rawLabels = new ArrayList<>(); if (obj.containsKey(config.getLabelField())) { rawLabels.add(obj.get(config.getLabelField()).toString()); } rawLabels.addAll(config.labelsForPath(path)); return rawLabels.stream().map(label -> Label.label(capitalizeFully(label, '_', ' ') .replaceAll("_", "") .replaceAll(" ", ""))) .toArray(Label[]::new); } LabelBuilder(GraphsConfig config); Label[] buildLabel(Map<String, Object> obj, String path);  }
@Test public void firstLetterOfWordCapitalised() { Map<String, Object> conf = new HashMap<>(); conf.put("mappings", MapUtil.map("$", "keyPhrase{!text,@metadata}")); LabelBuilder labelBuilder = new LabelBuilder(new GraphsConfig(conf)); Label[] labels = labelBuilder.buildLabel(new HashMap<>(), "$"); assertThat(labels, Matchers.arrayContaining(Label.label("Keyphrase"))); }
@Test public void firstLetterOfAllCapsWordCapitalised() { Map<String, Object> conf = new HashMap<>(); conf.put("mappings", MapUtil.map("$", "COMMERCIAL_ITEM{!text,@metadata}")); LabelBuilder labelBuilder = new LabelBuilder(new GraphsConfig(conf)); Label[] labels = labelBuilder.buildLabel(new HashMap<>(), "$"); assertThat(labels, Matchers.arrayContaining(Label.label("CommercialItem"))); }
@Test public void removeUnderscores() { Map<String, Object> conf = new HashMap<>(); conf.put("mappings", MapUtil.map("$", "Key_Phrase{!text,@metadata}")); LabelBuilder labelBuilder = new LabelBuilder(new GraphsConfig(conf)); Label[] labels = labelBuilder.buildLabel(new HashMap<>(), "$"); assertThat(labels, Matchers.arrayContaining(Label.label("KeyPhrase"))); }
@Test public void firstLetterOfWordsCapitalised() { Map<String, Object> conf = new HashMap< >(); conf.put("mappings", MapUtil.map("$", "KeyPhrase{!text,@metadata}")); LabelBuilder labelBuilder = new LabelBuilder(new GraphsConfig(conf)); Label[] labels = labelBuilder.buildLabel(new HashMap<>(), "$"); assertThat(labels, Matchers.arrayContaining(Label.label("Keyphrase"))); }