Search in sources :

Example 6 with DataField

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

the class MarcDSL method getSortableTitle.

/**
 * Get the title (245ab) from a record, without non-filing chars as
 * specified in 245 2nd indicator, and lowercased.
 * @param context - the marc record object
 * @return 245a and 245b values concatenated, with trailing punct removed,
 *         and with non-filing characters omitted. Null returned if no
 *         title can be found.
 *
 * @see SolrIndexer#getTitle
 */
public String getSortableTitle() {
    List<DataField> titleFields = record.getAllFields().get("245");
    if (titleFields == null || titleFields.isEmpty()) {
        return "";
    }
    DataField titleField = titleFields.get(0);
    if (titleField == null)
        return "";
    int nonFilingInt = getInd2AsInt(titleField);
    List<Title> titles = metadataRecord.getTitle();
    if (titles == null || titles.isEmpty())
        return null;
    String title = metadataRecord.getTitle().get(0).getTitleStr();
    title = title.replaceAll(END_PUNCTUATION, EMPTY_SEPARATOR);
    title = title.replaceAll(NUMBERS, "$1$2");
    title = title.toLowerCase();
    // Skip non-filing chars, if possible.
    if (title.length() > nonFilingInt) {
        title = title.substring(nonFilingInt);
    }
    if (title.length() == 0) {
        return null;
    }
    title = title.replaceAll(SUPPRESS, EMPTY_SEPARATOR);
    title = title.replaceAll(TO_BLANK, SPACE_SEPARATOR);
    title = title.replaceAll(LEAD_SPACE, EMPTY_SEPARATOR);
    title = title.replaceAll(PACK_SPACES, SPACE_SEPARATOR);
    return title.trim();
}
Also used : DataField(org.marc4j.marc.DataField) Title(cz.mzk.recordmanager.server.model.Title)

Example 7 with DataField

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

the class MarcDSL method getTitleSeries.

public Set<String> getTitleSeries() {
    Set<String> result = new HashSet<String>();
    result.addAll(getFieldsTrim("130adfgklnpst7:210a:222ab:240adklmprs:242ap:245abnp:246anp:247afp:" + "440a:490anp:700klmnoprst7:710klmnoprst7:711klmnoprst7:730adklmprs7:740anp:765ts9:" + "773kt:780st:785st:787st:800klmnoprst7:810klmnoprst7:811klmnoprst7:830aklmnoprst7"));
    for (DataField df : record.getDataFields("505")) {
        if (df.getIndicator2() == '0') {
            result.addAll(getFieldsTrim("505t"));
        }
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 8 with DataField

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

the class BoundingBoxMarcFunctions method parseBoundingBox.

protected double[] parseBoundingBox(MarcRecord record) {
    List<DataField> fields = record.getAllFields().get("034");
    if (fields == null || fields.isEmpty()) {
        return null;
    }
    DataField field = fields.get(0);
    String origWest = (field.getSubfield('d') == null) ? null : field.getSubfield('d').getData();
    String origEast = (field.getSubfield('e') == null) ? null : field.getSubfield('e').getData();
    String origNorth = (field.getSubfield('f') == null) ? null : field.getSubfield('f').getData();
    String origSouth = (field.getSubfield('g') == null) ? null : field.getSubfield('g').getData();
    double west = coordinateToDecimal(origWest);
    double east = coordinateToDecimal(origEast);
    double north = coordinateToDecimal(origNorth);
    double south = coordinateToDecimal(origSouth);
    double longitude = Double.NaN;
    double latitude = Double.NaN;
    if (!Double.isNaN(west) && !Double.isNaN(north)) {
        if (!Double.isNaN(east)) {
            longitude = (west + east) / 2.0;
        } else {
            longitude = west;
        }
        if (!Double.isNaN(south)) {
            latitude = (north + south) / 2;
        } else {
            latitude = north;
        }
        if ((longitude < -180 || longitude > 180) || (latitude < -90 || latitude > 90)) {
            logger.warn("Discarding invalid coordinates {}, {}  decoded from w={}, e={}, n={}, s={}", longitude, latitude, origWest, origEast, origNorth, origSouth);
        } else {
            if (Double.isNaN(north) || Double.isNaN(south) || Double.isNaN(east) || Double.isNaN(north)) {
                logger.warn("INVALID RECORD missig coordinate w={} e={} n={} s={}", origWest, origEast, origNorth, origSouth);
            } else {
                if (west < east && south < north) {
                    return new double[] { west, south, east, north };
                } else {
                    logger.warn("INVALID RECORD missig coordinate w={} e={} n={} s={}", origWest, origEast, origNorth, origSouth);
                }
            }
        }
    }
    return null;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 9 with DataField

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

the class CosmotronUpdate996Writer method updateMarc.

private void updateMarc(HarvestedRecord parentRec, List<Cosmotron996> childRecs) {
    Record record = marcXmlParser.parseUnderlyingRecord(parentRec.getRawRecord());
    Record newRecord = new RecordImpl();
    newRecord.setLeader(record.getLeader());
    for (ControlField cf : record.getControlFields()) {
        newRecord.addVariableField(cf);
    }
    for (DataField df : record.getDataFields()) {
        // remove old fields 996
        if (!df.getTag().equals("996")) {
            newRecord.addVariableField(df);
        }
    }
    for (Cosmotron996 new996 : childRecs) {
        if (new996.getDeleted() != null)
            continue;
        MarcRecord marcRecord996 = parseMarcRecord(new996.getRawRecord());
        for (DataField df : get996(marcRecord996)) {
            newRecord.addVariableField(df);
        }
    }
    parentRec.setRawRecord(new MarcRecordImpl(newRecord).export(IOFormat.XML_MARC).getBytes(StandardCharsets.UTF_8));
}
Also used : ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) Cosmotron996(cz.mzk.recordmanager.server.model.Cosmotron996) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) RecordImpl(cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)

Example 10 with DataField

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

the class PatentsXmlStreamReader method createField072.

private DataField createField072(String text) {
    String[] temp = text.split(" - ");
    DataField df = factory.newDataField("072", '7', ' ');
    df.addSubfield(factory.newSubfield('a', temp[0].split(" ")[1]));
    df.addSubfield(factory.newSubfield('x', temp[1]));
    df.addSubfield(factory.newSubfield('2', TEXT_0722));
    df.addSubfield(factory.newSubfield('9', temp[0].split(" ")[0]));
    return df;
}
Also used : DataField(org.marc4j.marc.DataField)

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