Search in sources :

Example 16 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MetadataMarcRecord method getTitle.

/**
 * get {@link Title} of record
 *
 * @return all 245abnp and 240abnp
 */
@Override
public List<Title> getTitle() {
    List<Title> result = new ArrayList<>();
    Long titleOrder = 0L;
    for (String key : TITLE_TAGS) {
        for (DataField df : underlayingMarc.getDataFields(key)) {
            String titleText = parseTitleValue(df, TITLE_SUBFIELDS);
            if (!titleText.isEmpty()) {
                result.add(Title.create(titleText, ++titleOrder, MetadataUtils.similarityEnabled(df, titleText)));
            }
        }
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList) Title(cz.mzk.recordmanager.server.model.Title) ShortTitle(cz.mzk.recordmanager.server.model.ShortTitle)

Example 17 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MetadataMarcRecord method getShortTitles.

/**
 * get {@link ShortTitle} of record
 *
 * @return all 245anp and 240anp, if not contains subfield 'b'
 */
@Override
public List<ShortTitle> getShortTitles() {
    List<ShortTitle> results = new ArrayList<>();
    Long shortTitleCounter = 0L;
    for (String tag : TITLE_TAGS) {
        for (DataField df : underlayingMarc.getDataFields(tag)) {
            if (df.getSubfield('b') == null)
                continue;
            String titleText = parseTitleValue(df, SHORT_TITLE_SUBFIELDS);
            if (!titleText.isEmpty()) {
                results.add(ShortTitle.create(titleText, ++shortTitleCounter, MetadataUtils.similarityEnabled(df, titleText)));
            }
        }
    }
    return results;
}
Also used : ShortTitle(cz.mzk.recordmanager.server.model.ShortTitle) DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList)

Example 18 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MetadataMarcRecord method getWeight.

@Override
public Long getWeight(Long baseWeight) {
    Long weight = 0L;
    if (baseWeight != null)
        weight = baseWeight;
    if (underlayingMarc.getDataFields("245").isEmpty()) {
        return 0L;
    }
    String ldr17 = Character.toString(underlayingMarc.getLeader().getImplDefined2()[0]);
    if (ldr17.equals("1"))
        weight -= 1;
    else if (WEIGHT_2_TO_4.matcher(ldr17).matches())
        weight -= 2;
    else if (WEIGHT_05_TO_9.matcher(ldr17).matches())
        weight -= 3;
    if (underlayingMarc.getControlField("008") == null)
        weight -= 1;
    if (underlayingMarc.getDataFields("300").isEmpty())
        weight -= 1;
    boolean exists1xx = false;
    for (String key : FIELDS1XX) {
        if (!underlayingMarc.getDataFields(key).isEmpty()) {
            exists1xx = true;
            break;
        }
    }
    boolean f245Ind1 = false;
    for (DataField dataField : underlayingMarc.getDataFields("245")) {
        if (dataField.getIndicator1() == 0)
            f245Ind1 = true;
    }
    if (!exists1xx && !f245Ind1) {
        weight -= 1;
    }
    if (!underlayingMarc.getDataFields("080").isEmpty() || !underlayingMarc.getDataFields("072").isEmpty()) {
        weight += 1;
    }
    if (!underlayingMarc.getDataFields("964").isEmpty())
        weight += 1;
    else {
        for (String key : FIELDS6XX) {
            if (!underlayingMarc.getDataFields(key).isEmpty()) {
                weight += 1;
                break;
            }
        }
    }
    if (!getISBNs().isEmpty() || !getISSNs().isEmpty() || !getCNBs().isEmpty()) {
        weight += 1;
    }
    boolean exist7in1xx = false;
    for (String key : FIELDS1XX) {
        if (underlayingMarc.getField(key, '7') != null) {
            weight += 1;
            exist7in1xx = true;
            break;
        }
    }
    if (!exist7in1xx) {
        for (String key : FIELDS7XX) {
            if (underlayingMarc.getField(key, '7') != null) {
                weight += 1;
                break;
            }
        }
    }
    for (String subfield : underlayingMarc.getFields("040", 'e')) {
        if (WEIGHT_RDA.matcher(subfield).matches()) {
            weight += 1;
            break;
        }
    }
    return weight;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 19 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MarcAlephStreamReader method parseLine.

private void parseLine(Record record) {
    if (line == null || line.isEmpty())
        return;
    Matcher matcher;
    if ((matcher = LDR_PATTERN.matcher(line)).matches()) {
        record.setLeader(factory.newLeader(matcher.group(1)));
    } else if ((matcher = CF_PATTERN.matcher(line)).matches()) {
        record.addVariableField(factory.newControlField(matcher.group(1), matcher.group(2)));
    } else if ((matcher = DF_PATTERN.matcher(line)).matches()) {
        DataField df = factory.newDataField(matcher.group(1), matcher.group(2).charAt(0), matcher.group(3).charAt(0));
        for (String data : matcher.group(4).split("\\$\\$")) {
            if (data.length() > 1) {
                // sf code (1 char) + text
                df.addSubfield(factory.newSubfield(data.charAt(0), data.substring(1)));
            }
        }
        record.addVariableField(df);
    }
}
Also used : DataField(org.marc4j.marc.DataField) Matcher(java.util.regex.Matcher)

Example 20 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MarcISO2709StreamReader method parseDataField.

private DataField parseDataField(String tag, byte[] field) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(field);
    char ind1 = (char) bais.read();
    char ind2 = (char) bais.read();
    DataField dataField = factory.newDataField();
    dataField.setTag(tag);
    dataField.setIndicator1(ind1);
    dataField.setIndicator2(ind2);
    int code;
    int size;
    int readByte;
    byte[] data;
    Subfield subfield;
    while (true) {
        readByte = bais.read();
        if (readByte < 0) {
            break;
        }
        switch(readByte) {
            case Constants.US:
                code = bais.read();
                if (code < 0) {
                    throw new IOException("unexpected end of data field");
                }
                if (code == Constants.FT) {
                    break;
                }
                size = getSubfieldLength(bais);
                data = new byte[size];
                bais.read(data);
                subfield = factory.newSubfield();
                subfield.setCode((char) code);
                subfield.setData(getDataAsString(data));
                dataField.addSubfield(subfield);
                break;
            case Constants.FT:
                break;
        }
    }
    return dataField;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Subfield(org.marc4j.marc.Subfield)

Aggregations

DataField (org.marc4j.marc.DataField)82 ArrayList (java.util.ArrayList)18 Subfield (org.marc4j.marc.Subfield)17 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 ControlField (org.marc4j.marc.ControlField)13 Record (org.marc4j.marc.Record)13 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 List (java.util.List)11 TreeSet (java.util.TreeSet)11 Matcher (java.util.regex.Matcher)11 MarcFactory (org.marc4j.marc.MarcFactory)8 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NoDataException (cz.mzk.recordmanager.server.util.identifier.NoDataException)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)2 ShortTitle (cz.mzk.recordmanager.server.model.ShortTitle)2