Skip to content

Commit

Permalink
Add is_latest_label field
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyengit committed Oct 14, 2024
1 parent 2f0c921 commit b98b96d
Show file tree
Hide file tree
Showing 6 changed files with 5,085 additions and 2,344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class VocabModel {
protected List<String> hiddenLabels;
@JsonProperty("alt_labels")
protected List<String> altLabels;
@JsonProperty("is_latest_label")
protected Boolean isLatestLabel;
protected String definition;
protected String about;
protected List<VocabModel> broader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ArdcVocabServiceImpl implements ArdcVocabService {
protected RestTemplate restTemplate;
protected RetryTemplate retryTemplate;

protected Function<JsonNode, String> extractLabel(String key) {
protected Function<JsonNode, String> extractValueField(String key) {
return (node) -> {
JsonNode labelNode = node.get(key);
if (labelNode != null) {
Expand All @@ -43,7 +43,7 @@ protected Function<JsonNode, String> extractLabel(String key) {
return null;
};
}
protected Function<JsonNode, List<String>> extractLabels(String key) {
protected Function<JsonNode, List<String>> extractMultipleValueFields(String key) {
return (node) -> {
JsonNode labelNode = node.get(key);
if (labelNode != null && labelNode.isArray()) {
Expand All @@ -57,13 +57,13 @@ protected Function<JsonNode, List<String>> extractLabels(String key) {
}

// Reusing the utility methods for specific labels
protected Function<JsonNode, String> label = extractLabel("prefLabel");
protected Function<JsonNode, String> displayLabel = extractLabel("displayLabel");
protected Function<JsonNode, List<String>> hiddenLabels = extractLabels("hiddenLabel");
protected Function<JsonNode, List<String>> altLabels = extractLabels("altLabel");

protected Function<JsonNode, String> about = (node) -> node.has("_about") ? node.get("_about").asText() : null;
protected Function<JsonNode, String> definition = (node) -> node.has("definition") ? node.get("definition").asText() : null;
protected Function<JsonNode, String> label = extractValueField("prefLabel");
protected Function<JsonNode, String> displayLabel = extractValueField("displayLabel");
protected Function<JsonNode, List<String>> hiddenLabels = extractMultipleValueFields("hiddenLabel");
protected Function<JsonNode, List<String>> altLabels = extractMultipleValueFields("altLabel");
protected Function<JsonNode, String> about = extractValueField("_about");
protected Function<JsonNode, String> definition = extractValueField("definition");
protected Function<JsonNode, Boolean> isLatestLabel = (node) -> !(node.has("isReplacedBy") || (node.has("scopeNote") && extractValueField("scopeNote").apply(node).contains("no longer exists")));
protected BiFunction<JsonNode, String, Boolean> isNodeValid = (node, item) -> node != null && !node.isEmpty() && node.has(item) && !node.get(item).isEmpty();

public ArdcVocabServiceImpl(RestTemplate restTemplate, RetryTemplate retryTemplate) {
Expand All @@ -89,18 +89,12 @@ protected VocabModel buildVocabByResourceUri(String vocabUri, String vocabApiBas
.label(label.apply(target))
.definition(definition.apply(target))
.about(vocabUri)
.displayLabel(displayLabel.apply(target))
.hiddenLabels(hiddenLabels.apply(target))
.altLabels(altLabels.apply(target))
.isLatestLabel(isLatestLabel.apply(target))
.build();

if (displayLabel.apply(target) != null && !displayLabel.apply(target).isEmpty()) {
vocab.setDisplayLabel(displayLabel.apply(target));
}
if (hiddenLabels.apply(target) != null && !hiddenLabels.apply(target).isEmpty()) {
vocab.setHiddenLabels(hiddenLabels.apply(target));
}
if (altLabels.apply(target) != null && !altLabels.apply(target).isEmpty()) {
vocab.setAltLabels(altLabels.apply(target));
}

List<VocabModel> narrowerNodes = new ArrayList<>();
if (isNodeValid.apply(target, "narrower")) {
for (JsonNode j : target.get("narrower")) {
Expand Down Expand Up @@ -175,6 +169,10 @@ protected Map<String, List<VocabModel>> getVocabLeafNodes(String vocabApiBase, V
.label(label.apply(target))
.definition(definition.apply(target))
.about(about.apply(target))
.displayLabel(displayLabel.apply(target))
.hiddenLabels(hiddenLabels.apply(target))
.altLabels(altLabels.apply(target))
.isLatestLabel(isLatestLabel.apply(target))
.build();

List<VocabModel> vocabNarrower = new ArrayList<>();
Expand Down
Loading

0 comments on commit b98b96d

Please sign in to comment.