Skip to content

Commit

Permalink
issue #154: subject indexing analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Aug 17, 2022
1 parent 3c876bf commit 264aa0d
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public int process() {
total = processFieldsWithoutSource(total);
total = processFieldsWithScheme(total, MARC21_FIELD_WITH_SCHEMES);
} else if (marcRecord.getSchemaType().equals(SchemaType.PICA)) {
total = processFieldsWithScheme(total, PICA_FIELDS_WITH_SCHEME);
total = processFieldsWithSchemePica(total, PICA_FIELDS_WITH_SCHEME);
}

increaseCounters(total);
Expand Down Expand Up @@ -135,6 +135,15 @@ private int processFieldsWithScheme(int total, List<FieldWithScheme> fieldsWithS
return total;
}

private int processFieldsWithSchemePica(int total, List<FieldWithScheme> fieldsWithScheme) {
for (FieldWithScheme fieldWithScheme : fieldsWithScheme) {
var count = processFieldWithSchemePica(marcRecord, fieldWithScheme);
if (count > 0)
total += count;
}
return total;
}

private int processFieldsWithoutSource(int total) {
for (String tag : fieldsWithoutSource) {
var count = processFieldWithoutSource(marcRecord, tag);
Expand Down Expand Up @@ -213,6 +222,45 @@ private int processFieldWithScheme(MarcRecord marcRecord,
return count;
}

private int processFieldWithSchemePica(MarcRecord marcRecord,
FieldWithScheme fieldEntry) {
var count = 0;
final String tag = fieldEntry.getTag();
if (!marcRecord.hasDatafield(tag))
return count;

List<DataField> fields = marcRecord.getDatafield(tag);
List<Schema> schemas = new ArrayList<>();
for (DataField field : fields) {
String firstSubfield = null;
// String alt = null;
if (field.getSubfield("a") != null) {
firstSubfield = "$a";
} else {
for (MarcSubfield subfield : field.getSubfields()) {
String code = subfield.getCode();
if (!code.equals("A")) {
firstSubfield = "$" + code;
break;
}
}
}
if (firstSubfield != null) {
var scheme = fieldEntry.getSchemaName();
var currentSchema = new Schema(tag, firstSubfield, classificationSchemes.resolve(scheme), scheme);
schemas.add(currentSchema);
updateSchemaSubfieldStatistics(field, currentSchema);
count++;
} else {
logger.severe(String.format("undetected subfield in record %s %s", marcRecord.getId(), field.toString()));
}
}

registerSchemas(schemas);

return count;
}

private void registerSchemas(List<Schema> schemas) {
addSchemasToStatistics(statistics.getInstances(), schemas);

Expand Down

0 comments on commit 264aa0d

Please sign in to comment.