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 3, 2022
1 parent 9ec0431 commit 5c0cf6f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import de.gwdg.metadataqa.marc.definition.structure.Indicator;
import de.gwdg.metadataqa.marc.definition.structure.MarcDefinition;
import de.gwdg.metadataqa.marc.definition.structure.SubfieldDefinition;
import de.gwdg.metadataqa.marc.utils.pica.crosswalk.Crosswalk;
import de.gwdg.metadataqa.marc.utils.pica.crosswalk.PicaMarcCrosswalkReader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -31,6 +35,7 @@ public class FrbrFunctionLister {

private Map<String, List<FRBRFunction>> functionByMarcPath;
private AppendableHashMap<FRBRFunction, String> marcPathByfunction;
private Map<FRBRFunction, List<String>> picaPathByfunction;

public FrbrFunctionLister(MarcVersion marcVersion) {
this.marcVersion = marcVersion;
Expand Down Expand Up @@ -159,4 +164,23 @@ public Map<FRBRFunction, Integer> getBaseline() {
public Map<FRBRFunction, List<String>> getMarcPathByfunction() {
return marcPathByfunction.getMap();
}

public Map<FRBRFunction, List<String>> getPicaPathByfunction() {
if (picaPathByfunction == null) {
picaPathByfunction = new HashMap<>();
for (Map.Entry<FRBRFunction, List<String>> entry : marcPathByfunction.entrySet()) {
for (String address : entry.getValue()) {
if (address.contains("$")) {
String key = address.replace("$", " $");
for (Crosswalk crosswalk : PicaMarcCrosswalkReader.lookupMarc21(key)) {
if (!picaPathByfunction.containsKey(entry.getKey()))
picaPathByfunction.put(entry.getKey(), new ArrayList<>());
picaPathByfunction.get(entry.getKey()).add(crosswalk.getPica());
}
}
}
}
}
return picaPathByfunction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ public static List<Crosswalk> read() {
}

public static List<Crosswalk> lookupMarc21(String key) {
if (mapping == null)
initialize();

return marcIndex.getOrDefault(key, new ArrayList<>());
}

public static List<Crosswalk> lookupPica(String key) {
if (mapping == null)
initialize();

return picaIndex.getOrDefault(key, new ArrayList<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,7 @@ public void test() {
@Test
public void testLoad() {
FrbrFunctionLister lister = new FrbrFunctionLister(MarcVersion.MARC21);
Map<FRBRFunction, List<String>> marcFunctions = lister.getMarcPathByfunction();
Map<FRBRFunction, List<String>> picaFunctions = new HashMap<>();
List<Crosswalk> mapping = PicaMarcCrosswalkReader.read();
for (Map.Entry<FRBRFunction, List<String>> entry : marcFunctions.entrySet()) {
for (String address : entry.getValue()) {
if (address.contains("$")) {
String key = address.replace("$", " $");
for (Crosswalk crosswalk : PicaMarcCrosswalkReader.lookupMarc21(key)) {
if (!picaFunctions.containsKey(entry.getKey()))
picaFunctions.put(entry.getKey(), new ArrayList<>());
picaFunctions.get(entry.getKey()).add(crosswalk.getPica());
}
}
}
}
Map<FRBRFunction, List<String>> picaFunctions = lister.getPicaPathByfunction();
assertEquals(11, picaFunctions.size());
assertEquals(167, picaFunctions.get(FRBRFunction.DiscoveryObtain).size());
assertEquals(178, picaFunctions.get(FRBRFunction.DiscoverySearch).size());
Expand Down

0 comments on commit 5c0cf6f

Please sign in to comment.