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