Commit 5ad4b274 authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

DEICH-3084 add language from controlfield 008 to work if not found in 041h

parent 9215789d
......@@ -53,7 +53,7 @@ public abstract class MarcXML2JsonLDConverter implements Function<List<Record>,
for (Record r : list) {
model.newRecord();
for (Entry<String, String> ctrl : r.controlFieldEntries()) {
handleControlField(model, ctrl.getKey(), ctrl.getValue());
handleControlField(model, r, ctrl.getKey(), ctrl.getValue());
}
for (Entry<String, DataField> data : r.dataFieldEntries()) {
handleDataField(model, r, data.getKey(), data.getValue());
......@@ -62,7 +62,7 @@ public abstract class MarcXML2JsonLDConverter implements Function<List<Record>,
return model;
}
private static void handleControlField(DeichModel model, String tag, String value) {
private static void handleControlField(DeichModel model, Record record, String tag, String value) {
switch (tag) {
case "001":
model.addToPublication(Ontology.HASIDENTIFIERINPRIMARYCATALOGUINGSOURCE, value);
......@@ -74,6 +74,10 @@ public abstract class MarcXML2JsonLDConverter implements Function<List<Record>,
.ifPresent(fnf -> model.addToWork(Ontology.FICTIONNONFICTION, fnf));
Biography.fromMarc("" + value.charAt(34)).ifPresent(bio -> model.addToWork(Ontology.BIOGRAPHY, bio));
model.addToPublication(Ontology.LANGUAGE, value.substring(35, 38), MUL_LANG_CONVERT);
if (!record.hasDataFieldWithSubfield("041", "h")) {
// DEICH-3084 add language to work as well, if not found in 041$h
model.addToWork(Ontology.LANGUAGE, value.substring(35, 38), MUL_LANG_CONVERT);
}
break;
default:
log.debug("Ignored controlfield: {}", tag);
......@@ -158,13 +162,8 @@ public abstract class MarcXML2JsonLDConverter implements Function<List<Record>,
.ifPresent(lang -> addTripleCharGroupToPublication(model, lang, Ontology.LANGUAGE, LANG_CONVERT));
field.getSubField("b").ifPresent(
subt -> addTripleCharGroupToPublication(model, subt, Ontology.HASSUBTITLES, LANG_CONVERT));
field.getSubField("h").ifPresentOrElse(
lang -> addTripleCharGroupToWork(model, lang, Ontology.LANGUAGE, LANG_CONVERT), () -> {
field.getSubField("a").ifPresent(
lang -> addTripleCharGroupToWork(model, lang, Ontology.LANGUAGE, LANG_CONVERT));
record.getControlField("008").ifPresent(
lang -> model.addToWork(Ontology.LANGUAGE, lang.substring(35, 38), MUL_LANG_CONVERT));
});
field.getSubField("h").ifPresent(
lang -> addTripleCharGroupToWork(model, lang, Ontology.LANGUAGE, LANG_CONVERT));
break;
case "082":
field.getSubField("a").ifPresent(classNum -> createClassification(model, field, classNum));
......
......@@ -132,6 +132,17 @@ public class MarcXMLParser extends DefaultHandler implements Function<InputStrea
return false;
}
public boolean hasDataFieldWithSubfield(String tag, String subfield) {
for (Entry<String, DataField> ent : dataFields) {
if (tag.equals(ent.getKey())) {
if (ent.getValue().getSubField(subfield).isPresent()) {
return true;
}
}
}
return false;
}
public Set<Entry<String, String>> controlFieldEntries() {
return controlFields.entrySet();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment