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 6, 2022
1 parent 6f8712d commit 9c83f4a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ private void countDataFields(Map<FRBRFunction, FunctionValue> recordCounter,
if (subfield.getDefinition() != null && subfield.getDefinition().getFrbrFunctions() != null)
FrbrFunctionLister.countFunctions(subfield.getDefinition().getFrbrFunctions(), recordCounter);
} else if (schemaType.equals(SchemaType.PICA)) {
if (frbrFunctionLister.getFunctionByPicaPath().containsKey(dataField.getTag()))
FrbrFunctionLister.countFunctions(frbrFunctionLister.getFunctionByPicaPath().get(dataField.getTag()), recordCounter);
for (MarcSubfield subfield : dataField.getSubfields()) {
String key = dataField.getTag() + "$" + subfield.getCode();
if (frbrFunctionLister.getFunctionByPicaPath().containsKey(key))
FrbrFunctionLister.countFunctions(frbrFunctionLister.getFunctionByPicaPath().get(key), recordCounter);
}
}
}
}
Expand Down Expand Up @@ -205,7 +208,7 @@ private void saveMapping(String fileExtension,
if (parameters.getSchemaType().equals(SchemaType.MARC21))
functions = frbrFunctionLister.getMarcPathByFunction();
else if (parameters.getSchemaType().equals(SchemaType.PICA))
functions = frbrFunctionLister.getPicaPathByFunction();
functions = frbrFunctionLister.getPicaPathByFunctionConcensed();

var path = Paths.get(parameters.getOutputDir(), "functional-analysis-mapping" + fileExtension);
try (var writer = Files.newBufferedWriter(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class FrbrFunctionLister {
private Map<String, List<FRBRFunction>> functionByMarcPath;
private Map<String, List<FRBRFunction>> functionByPicaPath;
private AppendableHashMap<FRBRFunction, String> marcPathByFunction;
private Map<FRBRFunction, List<String>> picaPathByFunction;
private Map<FRBRFunction, List<String>> picaPathByFunctionCondensed;
private Map<FRBRFunction, Map<String, List<String>>> picaPathByFunction;

public FrbrFunctionLister(SchemaType schemaType, MarcVersion marcVersion) {
this.schemaType = schemaType == null ? SchemaType.MARC21 : schemaType;
Expand Down Expand Up @@ -194,7 +195,7 @@ public Map<FRBRFunction, List<String>> getMarcPathByFunction() {
return marcPathByFunction.getMap();
}

public Map<FRBRFunction, List<String>> getPicaPathByFunction() {
public Map<FRBRFunction, Map<String, List<String>>> getPicaPathByFunction() {
if (picaPathByFunction == null) {
initializePica();
}
Expand All @@ -208,8 +209,16 @@ public Map<String, List<FRBRFunction>> getFunctionByPicaPath() {
return functionByPicaPath;
}

public Map<FRBRFunction, List<String>> getPicaPathByFunctionConcensed() {
if (picaPathByFunctionCondensed == null) {
initializePica();
}
return picaPathByFunctionCondensed;
}

private void initializePica() {
picaPathByFunction = new HashMap<>();
picaPathByFunctionCondensed = new HashMap<>();
functionByPicaPath = new HashMap<>();
for (Map.Entry<FRBRFunction, List<String>> entry : marcPathByFunction.entrySet()) {
for (String address : entry.getValue()) {
Expand All @@ -219,15 +228,22 @@ private void initializePica() {
for (Crosswalk crosswalk : PicaMarcCrosswalkReader.lookupMarc21(key)) {
String pica = crosswalk.getPica();
if (!picaPathByFunction.containsKey(function))
picaPathByFunction.put(function, new ArrayList<>());
picaPathByFunction.get(function).add(pica);

if (!functionByPicaPath.containsKey(pica))
functionByPicaPath.put(pica, new ArrayList<>());
functionByPicaPath.get(pica).add(function);
picaPathByFunction.put(function, new HashMap<>());
if (!picaPathByFunction.get(function).containsKey(pica))
picaPathByFunction.get(function).put(pica, new ArrayList<>());
picaPathByFunction.get(function).get(pica).add(crosswalk.getPicaUf());

if (!picaPathByFunctionCondensed.containsKey(function))
picaPathByFunctionCondensed.put(function, new ArrayList<>());
picaPathByFunctionCondensed.get(function).add(pica + crosswalk.getPicaUf());

if (!functionByPicaPath.containsKey(pica + crosswalk.getPicaUf()))
functionByPicaPath.put(pica + crosswalk.getPicaUf(), new ArrayList<>());
functionByPicaPath.get(pica + crosswalk.getPicaUf()).add(function);
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void test() {
@Test
public void testLoad() {
FrbrFunctionLister lister = new FrbrFunctionLister(MarcVersion.MARC21);
Map<FRBRFunction, List<String>> picaFunctions = lister.getPicaPathByFunction();
Map<FRBRFunction, List<String>> picaFunctions = lister.getPicaPathByFunctionConcensed();
assertEquals(11, picaFunctions.size());
assertEquals(167, picaFunctions.get(FRBRFunction.DiscoveryObtain).size());
assertEquals(178, picaFunctions.get(FRBRFunction.DiscoverySearch).size());
Expand Down

0 comments on commit 9c83f4a

Please sign in to comment.