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();
}
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;
}
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;
}
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));
}
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;
}
Aggregations