Skip to content

Commit

Permalink
Merge #2003 from remote-tracking branch 'origin/2000-orderElements'
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed May 28, 2024
2 parents 27851dd + 6e8657c commit c38ba53
Show file tree
Hide file tree
Showing 154 changed files with 1,458 additions and 1,441 deletions.
47 changes: 29 additions & 18 deletions src/main/java/org/lobid/resources/EtikettJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,43 @@ public void process(final String json) {

private String getEtikettForEveryUri(final Map<String, Object> jsonMap)
throws IOException {
// don't label the root id
Object rootId = jsonMap.remove("id");
getAllJsonNodes(jsonMap);
jsonMap.put("id", rootId);
// don't label the root id
Iterator<String> it = jsonMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
getAllNodesRecursivelyAndLabelThemIfNecessary(jsonMap, key);
}
return pretty ? JsonUtils.toPrettyString(jsonMap)
: JsonUtils.toString(jsonMap);
}

return pretty ? JsonUtils.toPrettyString(jsonMap)
: JsonUtils.toString(jsonMap);
private void getAllNodesRecursivelyAndLabelThemIfNecessary(Map<String, Object> jsonMap, String key) {
if (jsonMap.get(key) instanceof ArrayList) {
((ArrayList) jsonMap.get(key))//
.stream().filter(e -> (e instanceof LinkedHashMap))
.forEach(e -> labelNodesWithKeyId((Map<String, Object>) e));
}
else if (jsonMap.get(key) instanceof LinkedHashMap) {
labelNodesWithKeyId((Map<String, Object>) jsonMap.get(key));
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<String, Object> getAllJsonNodes(Map<String, Object> jsonMap) {
@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<String, Object> labelNodesWithKeyId(Map<String, Object> jsonMap) {
Iterator<String> it = jsonMap.keySet().iterator();
boolean hasLabel = false;
String id = null;
while (it.hasNext()) {
String key = it.next();
if (key.equals("label"))
hasLabel = true;
else if (!hasLabel && key.equals("id"))
id = (String) jsonMap.get(key);
if (jsonMap.get(key) instanceof ArrayList)
((ArrayList) jsonMap.get(key))//
.stream().filter(e -> (e instanceof LinkedHashMap))
.forEach(e -> getAllJsonNodes((Map<String, Object>) e));
else if (jsonMap.get(key) instanceof LinkedHashMap)
getAllJsonNodes((Map<String, Object>) jsonMap.get(key));
if (key.equals("label")) {
hasLabel = true;
}
else if (!hasLabel && key.equals("id")) {
id = (String) jsonMap.get(key);
}
else {
getAllNodesRecursivelyAndLabelThemIfNecessary(jsonMap, key);
}
}
if (id != null && !(hasLabel))
jsonMap.put("label", etikettMaker.getEtikett(id).label);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/alma/alma.fix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ end

add_field("@context","http://lobid.org/resources/context.jsonld")

# Set empty elements to manipulate the order winthin the record.
add_field("id","")
set_array("type[]")
set_array("medium[]")
add_field("title","")

do list(path:"880??","var":"$i")
copy_field("$i.6","$i.linkageTest")
replace_all("$i.linkageTest","\\d{3}(-\\d{2}).*","880$1")
Expand Down
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990001412590206441.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990001412590206441#!",
"type" : [ "BibliographicResource", "ReferenceSource", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Handwörterbuch des Volksschulwesens",
"almaMmsId" : "990001412590206441",
"hbzId" : "HT000161712",
"deprecatedUri" : "http://lobid.org/resources/HT000161712#!",
"oclcNumber" : [ "600913146" ],
"title" : "Handwörterbuch des Volksschulwesens",
"publication" : [ {
"startDate" : "1920",
"type" : [ "PublicationEvent" ],
Expand Down Expand Up @@ -376,15 +382,10 @@
} ],
"id" : "http://lobid.org/items/990001412590206441:DE-466:22135518500006463#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "ReferenceSource", "Book" ],
"responsibilityStatement" : [ "unter Mitw. zahlr. Schulmänner hrsg. von E. Clausnitzer ..." ],
"contribution" : [ {
"agent" : {
Expand All @@ -400,6 +401,5 @@
"label" : "Herausgeber/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990001412590206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990011470300206441.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990011470300206441#!",
"type" : [ "BibliographicResource", "EditedVolume", "Proceedings", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "What should political theory be now?",
"almaMmsId" : "990011470300206441",
"hbzId" : "HT003109553",
"deprecatedUri" : "http://lobid.org/resources/HT003109553#!",
"isbn" : [ "087395694X", "9780873956949", "0873956958", "9780873956956" ],
"oclcNumber" : [ "230434370" ],
"title" : "What should political theory be now?",
"otherTitleInformation" : [ "Essays from the Shambaugh Conference on Political Theory" ],
"publication" : [ {
"startDate" : "1983",
Expand Down Expand Up @@ -142,15 +148,10 @@
} ],
"id" : "http://lobid.org/items/990011470300206441:DE-385:22264500330006470#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "EditedVolume", "Proceedings", "Book" ],
"responsibilityStatement" : [ "ed. by John S. Nelson" ],
"contribution" : [ {
"agent" : {
Expand Down Expand Up @@ -178,6 +179,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990011470300206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990014830510206441.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990014830510206441#!",
"type" : [ "BibliographicResource", "Biography", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Charlie Chaplin",
"almaMmsId" : "990014830510206441",
"hbzId" : "HT003864492",
"deprecatedUri" : "http://lobid.org/resources/HT003864492#!",
"isbn" : [ "0405039204", "9780405039201" ],
"oclcNumber" : [ "1067416031" ],
"title" : "Charlie Chaplin",
"edition" : [ "Reprint ed. [d. Ausg.] New York, Schuman, 1951" ],
"publication" : [ {
"startDate" : "1972",
Expand Down Expand Up @@ -163,15 +169,10 @@
} ],
"id" : "http://lobid.org/items/990014830510206441:DE-385:22291734190006470#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "Biography", "Book" ],
"responsibilityStatement" : [ "Theodore Huff" ],
"contribution" : [ {
"agent" : {
Expand All @@ -183,6 +184,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990014830510206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990016782920206441.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990016782920206441#!",
"type" : [ "BibliographicResource", "PublishedScore", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Erleben - Verstehen - Lernen",
"almaMmsId" : "990016782920206441",
"hbzId" : "HT004285445",
"deprecatedUri" : "http://lobid.org/resources/HT004285445#!",
"ismn" : [ "M204421206" ],
"oclcNumber" : [ "1068203015" ],
"stockNumber" : [ "N 2120" ],
"title" : "Erleben - Verstehen - Lernen",
"otherTitleInformation" : [ "Klavierschule für Erwachsene" ],
"publication" : [ {
"startDate" : "1989",
Expand Down Expand Up @@ -199,15 +205,10 @@
} ],
"id" : "http://lobid.org/items/990016782920206441:DE-60:228656400007816#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "PublishedScore", "Book" ],
"responsibilityStatement" : [ "Uli Molsen" ],
"contribution" : [ {
"agent" : {
Expand All @@ -223,6 +224,5 @@
"label" : "Komposition"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990016782920206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990021367710206441.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990021367710206441#!",
"type" : [ "BibliographicResource", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Labor economics",
"almaMmsId" : "990021367710206441",
"hbzId" : "HT005207972",
"deprecatedUri" : "http://lobid.org/resources/HT005207972#!",
"isbn" : [ "0256018243", "9780256018240" ],
"oclcNumber" : [ "265495256" ],
"title" : "Labor economics",
"otherTitleInformation" : [ "wages, employment, and trade unionism" ],
"edition" : [ "3. ed" ],
"publication" : [ {
Expand Down Expand Up @@ -191,15 +197,10 @@
} ],
"id" : "http://lobid.org/items/990021367710206441:DE-466:990014134660106463#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "Book" ],
"responsibilityStatement" : [ "F. Ray Marshall ; Allan M. Cartter ; Allan G. King" ],
"contribution" : [ {
"agent" : {
Expand Down Expand Up @@ -234,6 +235,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990021367710206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990021974470206441.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990021974470206441#!",
"type" : [ "BibliographicResource", "Legislation", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Sowjetisches Verwaltungsrecht",
"almaMmsId" : "990021974470206441",
"hbzId" : "HT005271161",
"deprecatedUri" : "http://lobid.org/resources/HT005271161#!",
"oclcNumber" : [ "1067969357" ],
"title" : "Sowjetisches Verwaltungsrecht",
"otherTitleInformation" : [ "allg. Teil" ],
"publication" : [ {
"startDate" : "1954",
Expand Down Expand Up @@ -227,15 +233,10 @@
} ],
"id" : "http://lobid.org/items/990021974470206441:DE-6-016:23561372540006449#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "Legislation", "Book" ],
"responsibilityStatement" : [ "Unionsinstitut der Rechtswissenschaften beim Ministerium der Justiz der UdSSR. Hrsg. d. Übers.: Deutsches Institut für Rechtswissenschaft. S. S. Studenikin ..." ],
"contribution" : [ {
"agent" : {
Expand Down Expand Up @@ -273,6 +274,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990021974470206441#!"
} ]
}
16 changes: 8 additions & 8 deletions src/test/resources/alma-fix/990026405480206441.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"id" : "http://lobid.org/resources/990026405480206441#!",
"type" : [ "BibliographicResource", "Book" ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"title" : "Burgenkunde",
"almaMmsId" : "990026405480206441",
"hbzId" : "HT006813395",
"deprecatedUri" : "http://lobid.org/resources/HT006813395#!",
"isbn" : [ "3893505547", "9783893505548" ],
"oclcNumber" : [ "722126366" ],
"title" : "Burgenkunde",
"otherTitleInformation" : [ "Bauwesen und Geschichte der Burgen" ],
"edition" : [ "Neue, verb. u. erw. Aufl., [verb. u. erw. Nachdr. der 3. Aufl. 1912]" ],
"publication" : [ {
Expand Down Expand Up @@ -233,15 +239,10 @@
} ],
"id" : "http://lobid.org/items/990026405480206441:DE-466:22148766820006463#!"
} ],
"medium" : [ {
"label" : "Print",
"id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
} ],
"bibliographicLevel" : {
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "Book" ],
"responsibilityStatement" : [ "von Otto Piper" ],
"contribution" : [ {
"agent" : {
Expand All @@ -253,6 +254,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990026405480206441#!"
} ]
}
Loading

0 comments on commit c38ba53

Please sign in to comment.