Skip to content

Commit

Permalink
issue #174: PICA FRBR functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Oct 5, 2022
1 parent db64588 commit 6f8712d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FunctionalAnalysis(String[] args) throws ParseException {
parameters = new CompletenessParameters(args);
options = parameters.getOptions();
readyToProcess = true;
frbrFunctionLister = new FrbrFunctionLister(parameters.getMarcVersion());
frbrFunctionLister = new FrbrFunctionLister(parameters.getSchemaType(), parameters.getMarcVersion());

logger.info(frbrFunctionLister.getBaseline().toString());
}
Expand Down Expand Up @@ -212,7 +212,7 @@ else if (parameters.getSchemaType().equals(SchemaType.PICA))
writer.write("frbrfunction" + separator + "count" + separator + "fields\n");
for (FRBRFunction function : FRBRFunction.values()) {
if (function.getParent() != null) {
List<String> paths = functions.get(function);
List<String> paths = functions.getOrDefault(function, new ArrayList<>());
List<Object> cells = new ArrayList<>();
cells.add(function.toString());
cells.add(paths.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.gwdg.metadataqa.marc.Utils;
import de.gwdg.metadataqa.marc.definition.*;
import de.gwdg.metadataqa.marc.definition.bibliographic.SchemaType;
import de.gwdg.metadataqa.marc.definition.structure.ControlFieldDefinition;
import de.gwdg.metadataqa.marc.definition.structure.ControlfieldPositionDefinition;
import de.gwdg.metadataqa.marc.definition.structure.DataFieldDefinition;
Expand All @@ -25,10 +26,11 @@
public class FrbrFunctionLister {

private static final Logger logger = Logger.getLogger(FrbrFunctionLister.class.getCanonicalName());
private SchemaType schemaType; // = SchemaType.MARC21;
private MarcVersion marcVersion; // = MarcVersion.MARC21;

private Counter<FRBRFunction> baselineCounter = new Counter<>();
private int elementsWithoutFunctions;
private MarcVersion marcVersion;

private Map<FRBRFunction, FunctionValue> collector;
private Map<FRBRFunction, Counter<FunctionValue>> histogram;
Expand All @@ -38,14 +40,23 @@ public class FrbrFunctionLister {
private AppendableHashMap<FRBRFunction, String> marcPathByFunction;
private Map<FRBRFunction, List<String>> picaPathByFunction;

public FrbrFunctionLister(MarcVersion marcVersion) {
this.marcVersion = marcVersion;
public FrbrFunctionLister(SchemaType schemaType, MarcVersion marcVersion) {
this.schemaType = schemaType == null ? SchemaType.MARC21 : schemaType;
this.marcVersion = marcVersion == null ? MarcVersion.MARC21 : marcVersion;

prepareBaseline();
prepareCollector();
prepareHistogram();
}

public FrbrFunctionLister(MarcVersion marcVersion) {
this(SchemaType.MARC21, marcVersion);
}

public FrbrFunctionLister(SchemaType schemaType) {
this(schemaType, MarcVersion.MARC21);
}

public Map<FRBRFunction, Counter<FunctionValue>> getHistogram() {
return histogram;
}
Expand All @@ -55,6 +66,23 @@ public void prepareBaseline() {
functionByMarcPath = new TreeMap<>();
marcPathByFunction = new AppendableHashMap<>();

if (schemaType.equals(SchemaType.MARC21)) {
prepareBaselineForMarc21();
} else if (schemaType.equals(SchemaType.PICA)) {
prepareBaselineForMarc21();
initializePica();
functionByMarcPath = new TreeMap<>();
marcPathByFunction = new AppendableHashMap<>();
prepareBaselineForPica();
}
}

private void prepareBaselineForPica() {
for (Map.Entry<String, List<FRBRFunction>> entry : functionByPicaPath.entrySet())
registerFunctions(entry.getValue(), entry.getKey());
}

private void prepareBaselineForMarc21() {
for (ControlfieldPositionDefinition subfield : MarcDefinition.getLeaderPositions())
registerFunctions(subfield.getFrbrFunctions(), subfield.getPath(false));

Expand Down

0 comments on commit 6f8712d

Please sign in to comment.