Skip to content

Commit

Permalink
update extractVocabLabelsFromThemes
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyengit committed Oct 15, 2024
1 parent 30b009d commit 2059293
Showing 1 changed file with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,58 +88,59 @@ this method for analysing the vocabularies of a record aka bottom-level vocabs (
*/
public List<String> extractVocabLabelsFromThemes(List<ThemesModel> themes, String vocabType) throws IOException {
List<String> results = new ArrayList<>();
if (vocabType.equals(AppConstants.AODN_ORGANISATION_VOCABS)) {
// TODO: the logics for mapping record's organisation vocabs are heavily customised for a manual approach, AI now or later?
return results;
} else {
// Iterate over the top-level vocabularies
List<JsonNode> vocabs = switch (vocabType) {
case AppConstants.AODN_DISCOVERY_PARAMETER_VOCABS -> self.getParameterVocabs();
case AppConstants.AODN_PLATFORM_VOCABS -> self.getPlatformVocabs();
default -> new ArrayList<>();
};
if (!vocabs.isEmpty() && !themes.isEmpty()) {
vocabs.stream().filter(Objects::nonNull).forEach(topLevelVocab -> {
if (topLevelVocab.has("narrower") && !topLevelVocab.get("narrower").isEmpty()) {
for (JsonNode secondLevelVocab : topLevelVocab.get("narrower")) {
if (secondLevelVocab != null && secondLevelVocab.has("label") && secondLevelVocab.has("about")) {
String secondLevelVocabLabel = secondLevelVocab.get("label").asText().toLowerCase();
themes.stream().filter(Objects::nonNull).forEach(theme -> {
ConceptModel secondLevelVocabAsConcept = ConceptModel.builder()
.id(secondLevelVocab.get("label").asText())
.url(secondLevelVocab.get("about").asText())
.build();

// if the record's theme is already second-level vocab, no need to further check
if (themeMatchConcept(theme, secondLevelVocabAsConcept) && !results.contains(secondLevelVocabLabel)) {
results.add(secondLevelVocabLabel);
}
// Iterate over the top-level vocabularies
List<JsonNode> vocabs = switch (vocabType) {
case AppConstants.AODN_DISCOVERY_PARAMETER_VOCABS -> self.getParameterVocabs();
case AppConstants.AODN_PLATFORM_VOCABS -> self.getPlatformVocabs();
case AppConstants.AODN_ORGANISATION_VOCABS -> self.getOrganisationVocabs();
default -> new ArrayList<>();
};

// if the record's theme is leaf-node (bottom-level vocab)
if (secondLevelVocab.has("narrower") && !secondLevelVocab.get("narrower").isEmpty()) {
for (JsonNode bottomLevelVocab : secondLevelVocab.get("narrower")) {
if (bottomLevelVocab != null && bottomLevelVocab.has("label") && bottomLevelVocab.has("about")) {
// map the original values to a ConceptModel object for doing comparison
ConceptModel leafVocabAsConcept = ConceptModel.builder()
.id(bottomLevelVocab.get("label").asText())
.url(bottomLevelVocab.get("about").asText())
.build();

// Compare with themes' concepts
if (themeMatchConcept(theme, leafVocabAsConcept) && !results.contains(secondLevelVocabLabel)) {
if (!vocabs.isEmpty() && !themes.isEmpty()) {
vocabs.stream().filter(Objects::nonNull).forEach(topLevelVocab -> {
if (topLevelVocab.has("narrower") && !topLevelVocab.get("narrower").isEmpty()) {
for (JsonNode secondLevelVocab : topLevelVocab.get("narrower")) {
if (secondLevelVocab != null && secondLevelVocab.has("label") && secondLevelVocab.has("about")) {
String secondLevelVocabLabel = secondLevelVocab.get("label").asText().toLowerCase();
themes.stream().filter(Objects::nonNull).forEach(theme -> {
ConceptModel secondLevelVocabAsConcept = ConceptModel.builder()
.id(secondLevelVocab.get("label").asText())
.url(secondLevelVocab.get("about").asText())
.build();

// if the record's theme is already second-level vocab, no need to further check
if (themeMatchConcept(theme, secondLevelVocabAsConcept) && !results.contains(secondLevelVocabLabel)) {
results.add(secondLevelVocabLabel);
}

// if the record's theme is leaf-node (bottom-level vocab)
if (secondLevelVocab.has("narrower") && !secondLevelVocab.get("narrower").isEmpty()) {
for (JsonNode bottomLevelVocab : secondLevelVocab.get("narrower")) {
if (bottomLevelVocab != null && bottomLevelVocab.has("label") && bottomLevelVocab.has("about")) {
// map the original values to a ConceptModel object for doing comparison
ConceptModel leafVocabAsConcept = ConceptModel.builder()
.id(bottomLevelVocab.get("label").asText())
.url(bottomLevelVocab.get("about").asText())
.build();

// Compare with themes' concepts
if (themeMatchConcept(theme, leafVocabAsConcept) && !results.contains(secondLevelVocabLabel)) {
if (vocabType.equals(AppConstants.AODN_ORGANISATION_VOCABS)) {
// TODO: the logics for mapping record's organisation vocabs are heavily customised for a manual approach, AI now or later?
} else {
results.add(secondLevelVocabLabel);
// just checking 1 leaf-node of each second-level vocab is enough, because we only care second-level vocabs.
break;
}
// just checking 1 leaf-node of each second-level vocab is enough, because we only care second-level vocabs.
break;
}
}
}
});
}
}
});
}
}
});
}
}
});
}
return results;
}
Expand Down

0 comments on commit 2059293

Please sign in to comment.