Skip to content

Commit

Permalink
Fix avram-unimarc.json; Trim UNIMARC records
Browse files Browse the repository at this point in the history
  • Loading branch information
gegic committed Jan 11, 2024
1 parent 6e43d02 commit 675e9b9
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 34,414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public String getDescriptionUrl() {

public boolean validate(String code) {
// Blanks should probably be identified somehow differently
// In the avram-unimarc schema, they are represented as a # character, but in the records they can also be ' ' or
// In the avram-unimarc schema, they are represented as a ' ' character, but in the records they can also be '#' or
// '-', or even '^' OR EVEN '|' for some reason

// The codes could also be validated case insensitively
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class UnimarcSchemaReader {
LABEL, 1,
CODES,1);

private static final String UNIMARC_EMPTY_CODE = "#";

private final JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627);
private final UnimarcSchemaManager schema = new UnimarcSchemaManager();

Expand Down Expand Up @@ -364,17 +362,6 @@ private List<EncodedValue> getCodes(JSONObject codesHolder, String objectKey) {
private void addCode(List<EncodedValue> encodedValues, String code, String codeLabel) {
EncodedValue encodedValue = new EncodedValue(code, codeLabel);
encodedValues.add(encodedValue);

// In case of an empty code, and the empty code isn't only a whitespace, then add whitespace as well
// This could potentially be done within one single EncodedValue
// check if code marches UNIMARC_EMPTY_CODE multiple times using regex
boolean isUnimarcEmptyCode = code.matches("^" + UNIMARC_EMPTY_CODE + "+$");
if (isUnimarcEmptyCode && !code.isBlank()) {
// Create a whitespace of that many spaces as the empty code has characters
String whitespace = " ".repeat(code.length());
EncodedValue emptyCode = new EncodedValue(whitespace, codeLabel);
encodedValues.add(emptyCode);
}
}

/**
Expand Down
Loading

0 comments on commit 675e9b9

Please sign in to comment.