<commit_before>package de.unituebingen.ub.ubtools.solrmarcMixin;


import org.marc4j.marc.DataField;
import org.marc4j.marc.Record;
import org.marc4j.marc.Subfield;
import org.marc4j.marc.VariableField;
import org.solrmarc.index.SolrIndexer;
import org.solrmarc.index.SolrIndexerMixin;
import org.solrmarc.tools.Utils;

import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class TuelibMixin extends SolrIndexerMixin {
    private final static Logger logger = Logger.getLogger(TuelibMixin.class.getName());
    private Set<String> isils_cache = null;

    @Override
    public void perRecordInit(final Record record) {
        isils_cache = null;
    }

    /**
     * Determine Record Title
     *
     * @param record the record
     * @return String     nicely formatted title
     */
    public String getTitle(final Record record) {
        final DataField title = (DataField) record.getVariableField("245");
        if (title == null)
            return null;

        final String title_a = (title.getSubfield('a') == null) ? null : title.getSubfield('a').getData();
        final String title_b = (title.getSubfield('b') == null) ? null : title.getSubfield('b').getData();
        if (title_a == null && title_b == null)
            return null;

        final StringBuilder complete_title = new StringBuilder();
        if (title_a == null)
            complete_title.append(Utils.cleanData(title_b));
        else if (title_b == null)
            complete_title.append(Utils.cleanData(title_a));
        else { // Neither title_a nor title_b are null.
            complete_title.append(Utils.cleanData(title_a));
            complete_title.append(' ');
            complete_title.append(Utils.cleanData(title_b));
        }

        final String title_c = (title.getSubfield('c') == null) ? null : title.getSubfield('c').getData();
        if (title_c != null) {
            complete_title.append(' ');
            complete_title.append(Utils.cleanData(title_c));
        }

        final String title_n = (title.getSubfield('n') == null) ? null : title.getSubfield('n').getData();
        if (title_n != null) {
            complete_title.append(' ');
            complete_title.append(Utils.cleanData(title_n));
        }

        return complete_title.toString();
    }

    /**
     * Determine Record Title Subfield
     *
     * @param record        the record
     * @param subfield_code
     * @return String     nicely formatted title subfield
     */
    public String getTitleSubfield(final Record record, final String subfield_code) {
        final DataField title = (DataField) record.getVariableField("245");<commit_msg>Removed 245$c from the title we display.  The standard calls this "Statement of responsibility, etc." and Martin found that it can contain the name of the author.<commit_after>package de.unituebingen.ub.ubtools.solrmarcMixin;


import org.marc4j.marc.DataField;
import org.marc4j.marc.Record;
import org.marc4j.marc.Subfield;
import org.marc4j.marc.VariableField;
import org.solrmarc.index.SolrIndexer;
import org.solrmarc.index.SolrIndexerMixin;
import org.solrmarc.tools.Utils;

import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class TuelibMixin extends SolrIndexerMixin {
    private final static Logger logger = Logger.getLogger(TuelibMixin.class.getName());
    private Set<String> isils_cache = null;

    @Override
    public void perRecordInit(final Record record) {
        isils_cache = null;
    }

    /**
     * Determine Record Title
     *
     * @param record the record
     * @return String     nicely formatted title
     */
    public String getTitle(final Record record) {
        final DataField title = (DataField) record.getVariableField("245");
        if (title == null)
            return null;

        final String title_a = (title.getSubfield('a') == null) ? null : title.getSubfield('a').getData();
        final String title_b = (title.getSubfield('b') == null) ? null : title.getSubfield('b').getData();
        if (title_a == null && title_b == null)
            return null;

        final StringBuilder complete_title = new StringBuilder();
        if (title_a == null)
            complete_title.append(Utils.cleanData(title_b));
        else if (title_b == null)
            complete_title.append(Utils.cleanData(title_a));
        else { // Neither title_a nor title_b are null.
            complete_title.append(Utils.cleanData(title_a));
            complete_title.append(' ');
            complete_title.append(Utils.cleanData(title_b));
        }

        final String title_n = (title.getSubfield('n') == null) ? null : title.getSubfield('n').getData();
        if (title_n != null) {
            complete_title.append(' ');
            complete_title.append(Utils.cleanData(title_n));
        }

        return complete_title.toString();
    }

    /**
     * Determine Record Title Subfield
     *
     * @param record        the record
     * @param subfield_code
     * @return String     nicely formatted title subfield
     */
    public String getTitleSubfield(final Record record, final String subfield_code) {
        final DataField title = (DataField) record.getVariableField("245");
{'fraction_non_alphanumeric': 0.11161132995685613, 'fraction_numerical': 0.004314387544550741, 'mean_word_length': 2.8470418470418473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '261358', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1553, 'n_words': 361}