package org.vufind.index; /** * Illustration indexing routines. * * Copyright (C) Villanova University 2017. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ import org.marc4j.marc.Record; import org.marc4j.marc.VariableField; import org.marc4j.marc.ControlField; import org.marc4j.marc.DataField; import org.marc4j.marc.Subfield; import java.util.List; /** * Illustration indexing routines. */ public class IllustrationTools { /** * Determine if a record is illustrated. * * @param record current MARC record * @return "Illustrated" or "Not Illustrated" */ public String isIllustrated(Record record) { String leader = record.getLeader().toString(); // Does the leader indicate this is a "language material" that might have extra // illustration details in the fixed fields? if (leader.charAt(6) == 'a') { String currentCode = ""; // for use in loops below // List of 008/18-21 codes that indicate illustrations: String illusCodes = "abcdefghijklmop"; // Check the illustration characters of the 008: ControlField fixedField = (ControlField) record.getVariableField("008"); if (fixedField != null) { String fixedFieldText = fixedField.getData().toLowerCase(); for (int i = 18; i <= 21; i++) { if (i < fixedFieldText.length()) { currentCode = fixedFieldText.substring(i, i + 1); if (illusCodes.contains(currentCode)) { return "Illustrated"; } } } } // Now check if any 006 fields apply: for (VariableField variableField : record.getVariableFields("006")) { fixedField = (ControlField) variableField; String fixedFieldText = fixedField.getData().toLowerCase(); for (int i = 1; i <= 4; i++) { if (i < fixedFieldText.length()) { currentCode = fixedFieldText.substring(i, i + 1); if (illusCodes.contains(currentCode)) { return "Illustrated"; } } } } } // Now check for interesting strings in 300 subfield b: for (VariableField variableField : record.getVariableFields("300")) { DataField physical = (DataField) variableField; List subfields = physical.getSubfields('b'); for (Subfield sf: subfields) { String desc = sf.getData().toLowerCase(); if (desc.contains("ill.") || desc.contains("illus.") || desc.contains("illustrations")) { return "Illustrated"; } } } // If we made it this far, we found no sign of illustrations: return "Not Illustrated"; } }