diff --git a/src/main/java/de/hbz/lobid/helper/JsonConverter.java b/src/main/java/de/hbz/lobid/helper/JsonConverter.java index 3e8f4733a..6f789241b 100644 --- a/src/main/java/de/hbz/lobid/helper/JsonConverter.java +++ b/src/main/java/de/hbz/lobid/helper/JsonConverter.java @@ -19,6 +19,7 @@ License, or (at your option) any later version. import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -62,6 +63,7 @@ public class JsonConverter { private String mainSubjectOfTheResource; private EtikettMakerInterface etikette; + private Map visited = new HashMap<>(); /** * @param e An EtikettMaker provides access to labels @@ -261,13 +263,27 @@ private void createObject(String uri, Map newObject) { if (s.getObject() instanceof org.openrdf.model.Literal) { newObject.put(e.name, s.getObject().stringValue()); } else { + if (statementVisited(s)) { + continue; + } if (!mainSubjectOfTheResource.equals(s.getObject().stringValue())) { createObject(newObject, s, e); } else { newObject.put(e.name, s.getObject().stringValue()); } } + } + + } + + private boolean statementVisited(Statement s) { + boolean result = visited.containsKey(s); + if (result) { + logger.debug("Already visited " + s); + } + visited.put(s, s); + return result; } private Set find(String uri) { diff --git a/src/test/java/TestRdfToJsonConversion.java b/src/test/java/TestRdfToJsonConversion.java index cb87a0230..df4e9d701 100644 --- a/src/test/java/TestRdfToJsonConversion.java +++ b/src/test/java/TestRdfToJsonConversion.java @@ -109,7 +109,8 @@ private static boolean testFiles(String fnameNtriples, String fnameJson, String uri) { Map expected = null; Map actual = null; - TestRdfToJsonConversion.logger.info("New test, begin converting files"); + TestRdfToJsonConversion.logger + .info("Convert " + fnameNtriples + " to " + fnameJson); try (InputStream in = new FileInputStream(new File(fnameNtriples)); InputStream out = new File(fnameJson).exists() ? new FileInputStream(new File(fnameJson)) : makeFile(fnameJson)) { diff --git a/src/test/resources/input/nt/00507/HT005077920.nt b/src/test/resources/input/nt/00507/HT005077920.nt new file mode 100644 index 000000000..a1f53ac96 --- /dev/null +++ b/src/test/resources/input/nt/00507/HT005077920.nt @@ -0,0 +1,45 @@ + . + "20060320"^^ . + "19991118"^^ . + "Zeitschrift"^^ . + "Zeitschrift"^^ . + "HITEE"^^ . + "Industrielle Technik"^^ . + "Routledge"^^ . + . + . + . + "Regionalgeschichte"^^ . + "Germantown, NY : Periodical Service Co."^^ . + "07341512"^^ . + "Technik | Geschichte | Zeitschrift"^^ . + . + . + "47030-2"^^ . + "1983 - "^^ . + "Zeitgeschichte"^^ . + "Periodikum"^^ . + . + "Ortsgeschichte"^^ . + . + "HITEEB"^^ . + . + "Abingdon; Routledge; 1983"^^ . + . + "Landesgeschichte"^^ . + "HT005077920"^^ . + . + . + "Abingdon"^^ . + "Hist Technol"^^ . + . + "Zeitschriften"^^ . + . + "HT ; an international journal"^^ . + "History and technology"^^ . + . + . + "Geschichte"^^ . + "Geschichte"^^ . + "Technik"^^ . + "Technik"^^ . diff --git a/src/test/resources/output/json/00507/HT005077920.json b/src/test/resources/output/json/00507/HT005077920.json new file mode 100644 index 000000000..eb6276320 --- /dev/null +++ b/src/test/resources/output/json/00507/HT005077920.json @@ -0,0 +1,62 @@ +{ + "@context" : "http://lobid.org/context/lobid-resources.json", + "describedby" : [ { + "id" : "http://lobid.org/resource/HT005077920/about" + } ], + "edition" : [ "Germantown, NY : Periodical Service Co." ], + "exemplar" : [ { + "id" : "http://lobid.org/item/HT005077920:DE-294-11:Z%201023" + }, { + "id" : "http://lobid.org/item/HT005077920:DE-361:14%20CA000%20H870" + } ], + "hbzId" : [ "HT005077920" ], + "id" : "http://lobid.org/resource/HT005077920", + "isPrimaryTopicOf" : [ { + "id" : "http://193.30.112.134/F/?func=find-c&ccl_term=IDN%3DHT005077920" + } ], + "issn" : [ "07341512" ], + "issued" : [ "1983 - " ], + "language" : [ { + "id" : "http://id.loc.gov/vocabulary/iso639-2/eng" + } ], + "medium" : [ { + "id" : "http://rdvocab.info/termList/RDAproductionMethod/1010" + } ], + "otherTitleInformation" : [ "HT ; an international journal" ], + "placeOfPublication" : [ "Abingdon" ], + "publicationStatement" : [ "Abingdon; Routledge; 1983" ], + "publisher" : [ "Routledge" ], + "sameAs" : [ { + "id" : "http://ld.zdb-services.de/resource/47030-2" + }, { + "describedby" : [ { + "dateCreated" : "19991118", + "dateModified" : "20060320", + "id" : "http://lobid.org/resource/ZDB47030-2/about", + "primaryTopic" : [ { + "id" : "http://lobid.org/resource/ZDB47030-2", + "sameAs" : "http://lobid.org/resource/HT005077920" + } ] + } ], + "id" : "http://lobid.org/resource/ZDB47030-2" + } ], + "shortTitle" : [ "Hist Technol", "HITEEB", "HITEE" ], + "subject" : [ { + "id" : "http://d-nb.info/gnd/4020517-4", + "preferredName" : "Geschichte", + "preferredNameForTheSubjectHeading" : "Geschichte" + }, { + "id" : "http://d-nb.info/gnd/4059205-4", + "preferredName" : "Technik", + "preferredNameForTheSubjectHeading" : "Technik" + }, { + "id" : "http://d-nb.info/gnd/4067488-5", + "preferredName" : "Zeitschrift", + "preferredNameForTheSubjectHeading" : "Zeitschrift" + } ], + "subjectChain" : [ "Technik | Geschichte | Zeitschrift" ], + "subjectLabel" : [ "Industrielle Technik", "Zeitschriften", "Landesgeschichte", "Ortsgeschichte", "Periodikum", "Zeitgeschichte", "Regionalgeschichte" ], + "title" : [ "History and technology" ], + "type" : [ "http://purl.org/ontology/bibo/Journal", "http://purl.org/dc/terms/BibliographicResource" ], + "zdbId" : [ "47030-2" ] +} \ No newline at end of file