From 88715e99e3fe69d5722acda498226551e4267926 Mon Sep 17 00:00:00 2001 From: Bart Hanssens Date: Wed, 12 Feb 2025 15:05:09 +0100 Subject: [PATCH] Gh-347: fix context for healthdata json-ld --- .../scrapers/healthdata/DcatHealthData.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scrapers/src/main/java/be/gov/data/scrapers/healthdata/DcatHealthData.java b/scrapers/src/main/java/be/gov/data/scrapers/healthdata/DcatHealthData.java index f0df05440..55aa6cd02 100644 --- a/scrapers/src/main/java/be/gov/data/scrapers/healthdata/DcatHealthData.java +++ b/scrapers/src/main/java/be/gov/data/scrapers/healthdata/DcatHealthData.java @@ -38,10 +38,15 @@ import java.net.MalformedURLException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; import org.eclipse.rdf4j.model.vocabulary.DCAT; import org.eclipse.rdf4j.model.vocabulary.DCTERMS; @@ -67,12 +72,11 @@ public class DcatHealthData extends Dcat { private final static Map CONTEXT = new HashMap<>(); static { + CONTEXT.put("dcat", DCAT.NAMESPACE); + CONTEXT.put("org", ORG.NAMESPACE); + CONTEXT.put("vcard", VCARD4.NAMESPACE); CONTEXT.put("title", DCTERMS.TITLE.toString()); CONTEXT.put("identifier", DCTERMS.IDENTIFIER.toString()); - CONTEXT.put("dcat:Dataset", DCAT.DATASET.toString()); - CONTEXT.put("dcat:Distribution", DCAT.DISTRIBUTION.toString()); - CONTEXT.put("org:Organization", ORG.ORGANIZATION.toString()); - CONTEXT.put("vcard:Contact", VCARD4.CONTACT.toString()); CONTEXT.put("description", DCTERMS.DESCRIPTION.toString()); CONTEXT.put("accessLevel", DCTERMS.ACCESS_RIGHTS.toString()); CONTEXT.put("issued", DCTERMS.ISSUED.toString()); @@ -80,6 +84,7 @@ public class DcatHealthData extends Dcat { CONTEXT.put("modified", DCTERMS.MODIFIED.toString()); CONTEXT.put("license", DCTERMS.LICENSE.toString()); CONTEXT.put("spatial", DCTERMS.SPATIAL.toString()); + CONTEXT.put("temporal", DCTERMS.TEMPORAL.toString()); CONTEXT.put("publisher", DCTERMS.PUBLISHER.toString()); CONTEXT.put("fn", VCARD4.FN.toString()); CONTEXT.put("hasEmail", VCARD4.HAS_EMAIL.toString()); @@ -91,6 +96,7 @@ public class DcatHealthData extends Dcat { CONTEXT.put("mediaType", DCAT.MEDIA_TYPE.toString()); CONTEXT.put("downloadURL", DCAT.DOWNLOAD_URL.toString()); CONTEXT.put("keyword", DCAT.KEYWORD.toString()); + CONTEXT.put("label", DCAT.KEYWORD.toString()); CONTEXT.put("theme", DCAT.THEME.toString()); CONTEXT.put("references", DCTERMS.REFERENCES.toString()); CONTEXT.put("data", RDFS.LABEL.toString()); @@ -99,11 +105,11 @@ public class DcatHealthData extends Dcat { @Override public void generateDcat(Cache cache, Storage store) throws RepositoryException, MalformedURLException { Map map = cache.retrievePage(getBase()); - String ttl = map.get("all").getContent(); + String json = map.get("all").getContent(); List datasets; // Change JSON file to JSON-LD - try (InputStream in = new ByteArrayInputStream(ttl.getBytes(StandardCharsets.UTF_8))) { + try (InputStream in = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))) { datasets = (List) JsonUtils.fromInputStream(in); } catch (IOException ex) { throw new RepositoryException(ex); @@ -116,12 +122,13 @@ public void generateDcat(Cache cache, Storage store) throws RepositoryException, String str = ""; try { str = JsonUtils.toString(jsonld); + System.err.println(str); } catch (IOException ex) { throw new RepositoryException(ex); } - try (InputStream json = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8))) { - store.add(json, RDFFormat.JSONLD); + try (InputStream jsonis = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8))) { + store.add(jsonis, RDFFormat.JSONLD); } catch (RDFParseException | IOException ex) { throw new RepositoryException(ex); }