From 149f8ad71ff0059671356ec26e8a029c93ec08fd Mon Sep 17 00:00:00 2001 From: der Date: Sat, 17 Sep 2022 18:47:08 +0100 Subject: [PATCH 1/2] Test case and fix for missing mapped values in array Addresses: #43 --- src/main/java/com/epimorphics/dclib/values/ValueArray.java | 7 ++++++- .../epimorphics/dclib/framework/TestBasicConverters.java | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/epimorphics/dclib/values/ValueArray.java b/src/main/java/com/epimorphics/dclib/values/ValueArray.java index 316711a..809bb61 100644 --- a/src/main/java/com/epimorphics/dclib/values/ValueArray.java +++ b/src/main/java/com/epimorphics/dclib/values/ValueArray.java @@ -10,6 +10,7 @@ package com.epimorphics.dclib.values; import com.epimorphics.dclib.framework.ConverterProcess; +import com.epimorphics.dclib.framework.NullResult; import com.epimorphics.util.NameUtils; import java.util.ArrayList; @@ -333,7 +334,11 @@ public interface MapValue { public ValueArray applyFunction(MapValue map) { Value[] result = new Value[ value.length ]; for (int i = 0; i < value.length; i++) { - result[i] = map.map( value[i]); + try { + result[i] = map.map( value[i]); + } catch (NullResult n) { + result[i] = new ValueNull(); + } } return new ValueArray(result); } diff --git a/src/test/java/com/epimorphics/dclib/framework/TestBasicConverters.java b/src/test/java/com/epimorphics/dclib/framework/TestBasicConverters.java index 8ae5523..6a68d26 100644 --- a/src/test/java/com/epimorphics/dclib/framework/TestBasicConverters.java +++ b/src/test/java/com/epimorphics/dclib/framework/TestBasicConverters.java @@ -269,7 +269,11 @@ public void testBugs() throws IOException { checkAgainstExpected("test/bugCases/accidental-lang.yaml", "test/bugCases/accidental-lang.csv", "test/bugCases/accidental-lang.ttl"); } - + + @Test + public void testArrayMap() throws IOException { + checkAgainstExpected("test/arrayMap/resource-media-type.yaml", "test/arrayMap/resource_media_types.csv", "test/arrayMap/expected.ttl"); + } @Test public void testDateParseFailure() throws IOException { // A failure to parse a date shouldn't break the whole template, or should it From ac929a2ff641bae009aee00060f18af3cb4e0be4 Mon Sep 17 00:00:00 2001 From: der Date: Sat, 17 Sep 2022 18:54:04 +0100 Subject: [PATCH 2/2] Test case --- test/arrayMap/expected.ttl | 26 + test/arrayMap/media-type.ttl | 665 +++++++++++++++++++++++++ test/arrayMap/resource-media-type.yaml | 82 +++ test/arrayMap/resource_media_types.csv | 4 + 4 files changed, 777 insertions(+) create mode 100644 test/arrayMap/expected.ttl create mode 100644 test/arrayMap/media-type.ttl create mode 100644 test/arrayMap/resource-media-type.yaml create mode 100644 test/arrayMap/resource_media_types.csv diff --git a/test/arrayMap/expected.ttl b/test/arrayMap/expected.ttl new file mode 100644 index 0000000..59d2952 --- /dev/null +++ b/test/arrayMap/expected.ttl @@ -0,0 +1,26 @@ +@prefix void: . +@prefix c: . +@prefix owl: . +@prefix org: . +@prefix xsd: . +@prefix skos: . +@prefix rdfs: . +@prefix version: . +@prefix qb: . +@prefix at: . +@prefix dct: . +@prefix rdf: . +@prefix reg: . +@prefix u: . +@prefix time: . +@prefix api: . +@prefix prov: . +@prefix dataset: . +@prefix foaf: . +@prefix dc: . + +dataset:0002 c:mediaType , , . + +dataset:0001 c:mediaType , . + +dataset:0003 c:mediaType . diff --git a/test/arrayMap/media-type.ttl b/test/arrayMap/media-type.ttl new file mode 100644 index 0000000..900dd05 --- /dev/null +++ b/test/arrayMap/media-type.ttl @@ -0,0 +1,665 @@ +@prefix c: . +@prefix u: . +@prefix rdf: . +@prefix rdfs: . +@prefix m: . + + + a c:MediaType ; + c:ianaMediaType "text/turtle" ; + c:relatedFileExtension ".ttl" ; + u:acronym [ a u:Acronym ; + u:notation "TTL" ; + u:prefLabel "Terse Triple Language"@en + ] ; + u:identifier "text/turtle" ; + u:inScheme ; + u:prefLabel "Turtle RDF document"@en . + + + a c:MediaType ; + c:ianaMediaType "application/gml+xml" ; + c:relatedFileExtension ".gml" ; + u:acronym [ a u:Acronym ; + u:notation "GML" ; + u:prefLabel "Geography Markup Language"@en + ] ; + u:identifier "application/gml+xml" ; + u:inScheme ; + u:prefLabel "GML document"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ms-excel" ; + c:ianaMediaTypeAlias "zz-application/zz-winassoc-xls" , "application/x-msexcel" , "application/vnd.ms-excel.sheet.macroEnabled.12" , "application/msexcel" ; + c:relatedFileExtension ".xla" , ".xlm" , ".xll" , ".xlc" , ".xls" , ".xld" , ".xlw" , ".xlt" ; + u:acronym [ a u:Acronym ; + u:notation "XLS" ; + u:prefLabel "Microsoft eXcel Spreadsheet"@en + ] ; + u:altLabel "xls / xlsx"@en , "XLSM"@en ; + u:identifier "application/vnd.ms-excel" ; + u:inScheme ; + u:prefLabel "Excel spreadsheet"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ms-word.document.macroEnabled.12" ; + c:relatedFileExtension ".docm" ; + u:altLabel "DOCM"@en ; + u:identifier "application/vnd.ms-word.document.macroEnabled.12" ; + u:inScheme ; + u:prefLabel "MS Word Macro Enabled"@en . + + + a c:MediaType ; + c:ianaMediaType "x-service/vnd.ogc.wfs" ; + u:acronym [ a u:Acronym ; + u:notation "OGC WFS" ; + u:prefLabel "Open Geospatial Consortium Web Feature Service"@en + ] ; + u:altLabel "WFS"@en ; + u:identifier "x-service/vnd.ogc.wfs" ; + u:inScheme ; + u:prefLabel "OGC WFS"@en . + + + a c:MediaType ; + c:ianaMediaType "text/csv" ; + c:ianaMediaTypeAlias "text/x-csv" , "text/x-comma-separated-values" ; + c:relatedFileExtension ".csv" ; + u:acronym [ a u:Acronym ; + u:notation "CSV" ; + u:prefLabel "Comma Separated Values"@en + ] ; + u:altLabel "CSV."@en ; + u:identifier "text/csv" ; + u:inScheme ; + u:prefLabel "CSV document"@en . + + + a u:ConceptScheme ; + rdfs:comment "Reference list of media types organised into collections."@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ms-powerpoint" ; + c:relatedFileExtension ".ppt" ; + u:acronym [ a u:Acronym ; + u:notation "PPT" ; + u:prefLabel "PowerPoinT"@en + ] ; + u:identifier "application/vnd.ms-powerpoint" ; + u:inScheme ; + u:prefLabel "Powerpoint"@en . + + + a c:MediaType ; + c:ianaMediaType "application/x-qgis" ; + c:relatedFileExtension ".qgs" ; + u:acronym [ a u:Acronym ; + u:notation "QGIS" ; + u:prefLabel "Q Geospatial Information System"@en + ] ; + u:identifier "application/x-qgis" ; + u:inScheme ; + u:prefLabel "Q GIS"@en . + + + a c:MediaType ; + c:ianaMediaType "text/html" ; + c:relatedFileExtension ".html" , ".htm" ; + u:acronym [ a u:Acronym ; + u:notation "HTML" ; + u:prefLabel "HyperText Markup Language"@en + ] ; + u:altLabel "HTML5"@en , "SHTML"@en , "webpage"@en , "text/html; charset=UTF-8"@en ; + u:identifier "text/html" ; + u:inScheme ; + u:prefLabel "HTML document"@en . + + + a c:MediaType ; + c:ianaMediaType "text/plain" ; + c:relatedFileExtension ".txt" , ".text" ; + u:acronym [ a u:Acronym ; + u:notation "TXT" ; + u:prefLabel "TeXT File"@en + ] ; + u:identifier "text/plain" ; + u:inScheme ; + u:prefLabel "Plain text"@en . + + + a u:Collection ; + u:hasMember , , , , , , , , , , , ; + u:inScheme ; + u:prefLabel "Spatial"@en . + + + a u:Collection ; + u:hasMember , , ; + u:inScheme ; + u:prefLabel "Developer Data Exchange"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.microsoft.portable-executable" ; + c:ianaMediaTypeAlias "application/x-msdos-program" ; + c:relatedFileExtension ".dll" , ".exe" ; + u:acronym [ a u:Acronym ; + u:notation "EXE" ; + u:prefLabel "EXEcutable"@en + ] ; + u:identifier "application/vnd.microsoft.portable-executable" ; + u:inScheme ; + u:prefLabel "MS-DOS/Windows Executable"@en . + + + a c:MediaType ; + c:ianaMediaType "application/x-compressed-tar" ; + c:relatedFileExtension ".tgz" , ".tar.gz" ; + u:acronym [ a u:Acronym ; + u:notation "TGZ" ; + u:prefLabel "Tape ARchive GNU Zip"@en + ] ; + u:identifier "application/x-compressed-tar" ; + u:inScheme ; + u:prefLabel "Tar archive (gzip-compressed)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/n-quads" ; + c:relatedFileExtension ".nq" ; + u:acronym [ a u:Acronym ; + u:notation "NQ" ; + u:prefLabel "N-Quads"@en + ] ; + u:identifier "application/n-quads" ; + u:inScheme ; + u:prefLabel "N-Quads RDF document"@en . + + + a c:MediaType ; + c:ianaMediaType "application/xml" ; + c:ianaMediaTypeAlias "text/xml" ; + c:relatedFileExtension ".ashx" , ".xml" , ".xsd" , ".xbl" , ".rng" , ".aspx" ; + u:acronym [ a u:Acronym ; + u:notation "XML" ; + u:prefLabel "eXtensible Markup Language"@en + ] ; + u:altLabel "ASPX"@en , "ASHX"@en ; + u:identifier "application/xml" ; + u:inScheme ; + u:prefLabel "XML document"@en . + + + a u:Collection ; + u:hasMember , , , , , , ; + u:inScheme ; + u:prefLabel "Tabular"@en . + + + a c:MediaType ; + c:ianaMediaType "application/octet-stream" ; + u:acronym [ a u:Acronym ; + u:notation "BIN" ; + u:prefLabel "Binary"@en + ] ; + u:altLabel "BIN"@en ; + u:identifier "application/octet-stream" ; + u:inScheme ; + u:prefLabel "Octet Stream"@en . + + + a c:MediaType ; + c:ianaMediaType "application/rdf+xml" ; + c:ianaMediaTypeAlias "text/rdf" ; + c:relatedFileExtension ".owl" , ".rdfs" , ".rdf" ; + u:acronym [ a u:Acronym ; + u:notation "RDF" ; + u:prefLabel "Resource Description Framework"@en + ] ; + u:altLabel "SKOS RDF"@en ; + u:identifier "application/rdf+xml" ; + u:inScheme ; + u:prefLabel "RDF file"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ogc.wms_xml" ; + c:relatedFileExtension ".wms" ; + u:acronym [ a u:Acronym ; + u:notation "WMS" ; + u:prefLabel "Open Geospatial Consortiom Web Map Service"@en + ] ; + u:altLabel "OGC WMS"@en ; + u:identifier "application/vnd.ogc.wms_xml" ; + u:inScheme ; + u:prefLabel "Open Geospatial Consortiom Web Map Service"@en . + + + a c:MediaType ; + c:ianaMediaType "application/msword" ; + c:relatedFileExtension ".dot" , ".doc" ; + u:altLabel "DOT"@en , "DOC"@en ; + u:identifier "application/msword" ; + u:inScheme ; + u:prefLabel "MS Word"@en . + + + a u:Collection ; + u:hasMember , , , , , , ; + u:inScheme ; + u:prefLabel "Linked Data"@en . + + + a u:Collection ; + u:hasMember , , , , , , , , , , ; + u:inScheme ; + u:prefLabel "Document"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.openxmlformats-officedocument.presentationml.presentation" ; + c:relatedFileExtension ".pptx" ; + u:acronym [ a u:Acronym ; + u:notation "PPTX" ; + u:prefLabel "PowerPoinT (XML)"@en + ] ; + u:identifier "application/vnd.openxmlformats-officedocument.presentationml.presentation" ; + u:inScheme ; + u:prefLabel "Powerpoint (XML)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/zip" ; + c:ianaMediaTypeAlias "application/x-zip-compressed" , "application/x-zip" ; + c:relatedFileExtension ".zip" ; + u:acronym [ a u:Acronym ; + u:notation "ZIP" ; + u:prefLabel "Zip"@en + ] ; + u:altLabel "CSV/Zip"@en , "ZIP / ZIP"@en , "CSV / Zip"@en , "CSV (zip)"@en ; + u:identifier "application/zip" ; + u:inScheme ; + u:prefLabel "Zip archive"@en . + + + a u:Collection ; + u:hasMember , , , ; + u:inScheme ; + u:prefLabel "Container"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ms-powerpoint.presentation.macroEnabled.12" ; + c:relatedFileExtension ".pptm" ; + u:acronym [ a u:Acronym ; + u:notation "PPTM" ; + u:prefLabel "PowerPoinT"@en + ] ; + u:identifier "application/vnd.ms-powerpoint.presentation.macroEnabled.12" ; + u:inScheme ; + u:prefLabel "Powerpoint (macro enabled)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/geo+json" ; + c:ianaMediaTypeAlias "application/vnd.geo+json" ; + c:relatedFileExtension ".geo.json" , ".geojson" ; + u:acronym [ a u:Acronym ; + u:notation "GeoJSON" ; + u:prefLabel "Geographic JavaScript Object Notation"@en + ] ; + u:identifier "application/geo+json" ; + u:inScheme ; + u:prefLabel "GeoJSON geospatial data"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ; + c:relatedFileExtension ".docx" ; + u:altLabel "DOCX"@en ; + u:identifier "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ; + u:inScheme ; + u:prefLabel "MS Word Document (docx)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/n-triples" ; + c:relatedFileExtension ".nt" ; + u:acronym [ a u:Acronym ; + u:notation "NT" ; + u:prefLabel "N-Triples"@en + ] ; + u:identifier "application/n-triples" ; + u:inScheme ; + u:prefLabel "N-Triples RDF document"@en . + + + a c:MediaType ; + c:ianaMediaType "x-service/vnd.esri.geoservices.rest" ; + u:acronym [ a u:Acronym ; + u:notation "ESRI" ; + u:prefLabel "ESRI"@en + ] ; + u:altLabel "ESRI GeoService"@en , "ArcGIS GeoServices REST API"@en , "esri rest api"@en ; + u:identifier "x-service/vnd.esri.geoservices.rest" ; + u:inScheme ; + u:prefLabel "Esri REST"@en . + + + a c:MediaType ; + c:ianaMediaType "x-service/vnd.w3c.http" ; + u:acronym [ a u:Acronym ; + u:notation "WWW" ; + u:prefLabel "World Wide Web"@en + ] ; + u:altLabel "website containing data files"@en , "website"@en , "web server"@en ; + u:identifier "x-service/vnd.w3c.http" ; + u:inScheme ; + u:prefLabel "HTTP(s) Web Server"@en . + + + a c:MediaType ; + c:ianaMediaType "x-service/vnd.w3c.sparql" ; + u:altLabel "SPARQL"@en ; + u:identifier "x-service/vnd.w3c.sparql" ; + u:inScheme ; + u:prefLabel "SPARQL Service"@en . + + + a c:MediaType ; + c:ianaMediaType "application/json" ; + c:relatedFileExtension ".json" ; + u:acronym [ a u:Acronym ; + u:notation "JSON" ; + u:prefLabel "JavaScript Object Notation"@en + ] ; + u:identifier "application/json" ; + u:inScheme ; + u:prefLabel "JSON document"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.google-earth.kml+xml" ; + c:relatedFileExtension ".kml" ; + u:acronym [ a u:Acronym ; + u:notation "KML" ; + u:prefLabel "Keyhole Markup Language"@en + ] ; + u:identifier "application/vnd.google-earth.kml+xml" ; + u:inScheme ; + u:prefLabel "KML geographic data"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.openxmlformats-officedocument.wordprocessingml.template" ; + c:relatedFileExtension ".dotx" ; + u:altLabel "DOTX"@en ; + u:identifier "application/vnd.openxmlformats-officedocument.wordprocessingml.template" ; + u:inScheme ; + u:prefLabel "MS Word Template (dotx)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.google-earth.kmz" ; + c:relatedFileExtension ".kmz" ; + u:acronym [ a u:Acronym ; + u:notation "KML" ; + u:prefLabel "Keyhole Markup Language"@en + ] ; + u:altLabel "KMZ"@en ; + u:identifier "application/vnd.google-earth.kmz" ; + u:inScheme ; + u:prefLabel "KML geographic compressed data"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.ms-excel.sheet.binary.macroenabled.12" ; + c:relatedFileExtension ".xlsb" ; + u:acronym [ a u:Acronym ; + u:notation "XLSB" ; + u:prefLabel "Microsoft eXcel Spreadsheet Binary"@en + ] ; + u:identifier "application/vnd.ms-excel.sheet.binary.macroenabled.12" ; + u:inScheme ; + u:prefLabel "Excel spreadsheet (binary)"@en . + + + a c:MediaType ; + c:ianaMediaType "application/x-ogc-aaigrid" ; + c:relatedFileExtension ".asc" , ".grd" ; + u:acronym [ a u:Acronym ; + u:notation "AAIGRID" ; + u:prefLabel "Arcinfo ASCII Grid"@en + ] ; + u:identifier "application/x-ogc-aaigrid" ; + u:inScheme ; + u:prefLabel "ASCII Grid"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.shx" ; + c:relatedFileExtension ".shx" ; + u:acronym [ a u:Acronym ; + u:notation "SHX" ; + u:prefLabel "SHape indeX format "@en + ] ; + u:identifier "application/vnd.shx" ; + u:inScheme ; + u:prefLabel "ESRI Shapefile Index"@en . + + + a c:MediaType ; + c:ianaMediaType "application/trig" ; + c:ianaMediaTypeAlias "application/x-trig" ; + c:relatedFileExtension ".trig" ; + u:acronym [ a u:Acronym ; + u:notation "TriG" ; + u:prefLabel "TriG RDF Graph Triple Language"@en + ] ; + u:identifier "application/trig" ; + u:inScheme ; + u:prefLabel "TriG RDF document"@en . + + + a c:MediaType ; + c:ianaMediaType "x-service/arcgis-map" ; + u:identifier "x-service/arcgis-map" ; + u:inScheme ; + u:prefLabel "ArcGIS Online Map"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.oasis.opendocument.spreadsheet" ; + c:relatedFileExtension ".ods" ; + u:acronym [ a u:Acronym ; + u:notation "ODS" ; + u:prefLabel "OpenDocument Spreadsheet"@en + ] ; + u:identifier "application/vnd.oasis.opendocument.spreadsheet" ; + u:inScheme ; + u:prefLabel "ODS spreadsheet"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ; + c:relatedFileExtension ".xlsx" ; + u:acronym [ a u:Acronym ; + u:notation "XLSX" ; + u:prefLabel "eXcel Spreadsheet (XML)"@en + ] ; + u:acronym [ a u:Acronym ; + u:notation "XLSX" ; + u:prefLabel "eXcel Spreadsheet (XML)"@en + ] ; + u:identifier "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ; + u:inScheme ; + u:prefLabel "Excel 2007 spreadsheet"@en . + + + a c:MediaType ; + c:ianaMediaType "application/pdf" ; + c:ianaMediaTypeAlias "application/nappdf" , "image/pdf" , "application/acrobat" , "application/x-pdf" ; + c:relatedFileExtension ".pdf" ; + u:acronym [ a u:Acronym ; + u:notation "PDF" ; + u:prefLabel "Portable Document Format"@en + ] ; + u:altLabel "PDF / PDF"@en ; + u:identifier "application/pdf" ; + u:inScheme ; + u:prefLabel "PDF document"@en . + + + a u:Collection ; + u:hasMember , , ; + u:inScheme ; + u:prefLabel "Imagery"@en . + + + a c:MediaType ; + c:ianaMediaType "application/ld+json" ; + c:relatedFileExtension ".jsonld" ; + u:acronym [ a u:Acronym ; + u:notation "JSON-LD" ; + u:prefLabel "JavaScript Object Notation for Linked Data"@en + ] ; + u:identifier "application/ld+json" ; + u:inScheme ; + u:prefLabel "JSON-LD document"@en . + + + a c:MediaType ; + c:ianaMediaType "image/jpeg" ; + c:ianaMediaTypeAlias "image/pjpeg" ; + c:relatedFileExtension ".jpg" , ".jpe" , ".jpeg" ; + u:acronym [ a u:Acronym ; + u:notation "JPEG" ; + u:prefLabel "Joint Photographic Experts Group"@en + ] ; + u:identifier "image/jpeg" ; + u:inScheme ; + u:prefLabel "JPEG image"@en . + + + a c:MediaType ; + c:ianaMediaType "application/x-tar" ; + c:ianaMediaTypeAlias "application/x-gtar" ; + c:relatedFileExtension ".gem" , ".tar" , ".gtar" ; + u:acronym [ a u:Acronym ; + u:notation "TAR" ; + u:prefLabel "Tape ARchive"@en + ] ; + u:identifier "application/x-tar" ; + u:inScheme ; + u:prefLabel "Tar archive"@en . + + + a c:MediaType ; + c:ianaMediaType "application/gzip" ; + c:relatedFileExtension ".gz" ; + u:acronym [ a u:Acronym ; + u:notation "GZIP" ; + u:prefLabel "GNU ZIP"@en + ] ; + u:identifier "application/gzip" ; + u:inScheme ; + u:prefLabel "GZIP Compressed"@en . + + + a c:MediaType ; + c:ianaMediaType "text/rtf" ; + u:acronym [ a u:Acronym ; + u:notation "RTF" ; + u:prefLabel "Rich Text Format"@en + ] ; + u:altLabel ".rtf"@en , "RTF / PDF"@en , "RTF"@en ; + u:identifier "text/rtf" ; + u:inScheme ; + u:prefLabel "Rich Text Format"@en . + + + a u:Collection ; + u:hasMember , ; + u:inScheme ; + u:prefLabel "Other"@en . + + + a c:MediaType ; + c:ianaMediaType "text/tab-separated-values" ; + c:relatedFileExtension ".tsv" ; + u:acronym [ a u:Acronym ; + u:notation "TSV" ; + u:prefLabel "Tab Separated Values"@en + ] ; + u:altLabel "tab-d"@en ; + u:identifier "text/tab-separated-values" ; + u:inScheme ; + u:prefLabel "TSV document"@en . + + + a u:Collection ; + u:hasMember ; + u:inScheme ; + u:prefLabel "Executable"@en . + + + a c:MediaType ; + c:ianaMediaType "image/png" ; + c:relatedFileExtension ".png" ; + u:acronym [ a u:Acronym ; + u:notation "PNG" ; + u:prefLabel "Portable Network Graphics"@en + ] ; + u:identifier "image/png" ; + u:inScheme ; + u:prefLabel "PNG image"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.shp" ; + c:relatedFileExtension ".shp" ; + u:acronym [ a u:Acronym ; + u:notation "SHP" ; + u:prefLabel "SHaPe format"@en + ] ; + u:identifier "application/vnd.shp" ; + u:inScheme ; + u:prefLabel "ESRI Shapefile"@en . + + + a c:MediaType ; + c:ianaMediaType "image/tiff" ; + c:relatedFileExtension ".tiff" , ".tif" ; + u:acronym [ a u:Acronym ; + u:notation "TIFF" ; + u:prefLabel "Tagged Image File Format"@en + ] ; + u:identifier "image/tiff" ; + u:inScheme ; + u:prefLabel "TIFF image"@en . + + + a c:MediaType ; + c:ianaMediaType "application/x-sqlite3" ; + c:relatedFileExtension ".sqlite" ; + u:altLabel "SQLite"@en ; + u:identifier "application/x-sqlite3" ; + u:inScheme ; + u:prefLabel "SQLite database"@en . + + + a c:MediaType ; + c:ianaMediaType "application/vnd.dbf" ; + c:ianaMediaTypeAlias "application/x-dbase" , "application/dbase" , "application/dbf" ; + c:relatedFileExtension ".dbf" ; + u:acronym [ a u:Acronym ; + u:notation "DBF" ; + u:prefLabel "dBase DataBase File"@en + ] ; + u:identifier "application/vnd.dbf" ; + u:inScheme ; + u:prefLabel "dBase DataBase File"@en . diff --git a/test/arrayMap/resource-media-type.yaml b/test/arrayMap/resource-media-type.yaml new file mode 100644 index 0000000..3fcea27 --- /dev/null +++ b/test/arrayMap/resource-media-type.yaml @@ -0,0 +1,82 @@ +name : catalog.xform +type : Composite + +requiredColumns: +- resource_format +- resource_mime_type +- resource_mimetype_inner + +prefixes : + c : http://vocab.epimorphics.com/agora/def/catalog/ + u : http://vocab.epimorphics.com/agora/def/upper/ + dataset: http://example.org/dataset/ + +sources : +- name : mediatype.map + sourceType : RDFSparql +# source : ../../vocab/vocab.epimorphics.com/agora/reference/media-type.ttl + source : test/arrayMap/media-type.ttl + query : " + select (lcase(str(?k)) as ?key) ?value + where { + ?value a c:MediaType . + { ?value (c:ianaMediaType|c:ianaMediaTypeAlias) ?k } + UNION + { ?value (u:acronym/(u:notation|u:prefLabel)) ?k } + UNION + { ?value (u:prefLabel|u:altLabel) ?k } + UNION + { ?value c:relatedFileExtension ?k } + } + " + +bind : + +- resource_id : "dataset:{value($row.number).format('%04d')}" + +- r_mt : "{ { var res = nullValue() ; + /* 'empty(res) || res.isNull()' because plain 'null' and 'ValueNull' results arise - confusing*/ + res = (empty(res) || res.isNull()) && !empty(resource_mime_type) ? resource_mime_type.toLowerCase().split(',').trim().map('mediatype.map',false) : res ; + res = (empty(res) || res.isNull()) && !empty(resource_mimetype_inner) ? resource_mimetype_inner.toLowerCase().split(',').trim().map('mediatype.map',false) : res ; + res = (empty(res) || res.isNull()) && !empty(resource_format) ? resource_format.toLowerCase().split(',').trim().map('mediatype.map',false) : res; + return res; + } }" + +- check_mt : " + { { var failed = + ( !empty(resource_format) || + !empty(resource_mime_type) || + !empty(resource_mimetype_inner) + ) && ( empty(r_mt) || r_mt.isNull() + ) ; + + if(!failed && r_mt.isMulti() ) { + /* Look for nulls in array results */ + var i = 0; + while(i lt r_mt.value.size() && !failed) { + var item = r_mt.get(i); + failed = failed || (empty(item) || item.isNull()); + i = i+1 ; + } + } + if(failed) { + print( value('WARNING: resource ') + .append(resource_id) + .append(' Unknown format : \"') + .append(empty(resource_format) ? '' : resource_format ) + .append('\" Outer MIME Type : \"') + .append(empty(resource_mime_type) ? '' : resource_mime_type ) + .append('\" inner MIME Type : \"') + .append(empty(resource_mimetype_inner) ? '' : resource_mimetype_inner ) + .append('\"') + ) + } + return nullValue() + } }" + +templates: +- name : main + "@id" : "<{resource_id}>" + : "{r_mt}" + + diff --git a/test/arrayMap/resource_media_types.csv b/test/arrayMap/resource_media_types.csv new file mode 100644 index 0000000..2a37ef6 --- /dev/null +++ b/test/arrayMap/resource_media_types.csv @@ -0,0 +1,4 @@ +"resource_format","resource_mime_type","resource_mimetype_inner" +"application/zip, application/octet-stream, application/x-zip-compressed, multipart/x-zip",, +"application/zip, application/octet-stream, application/x-zip-compressed,text/plain",, +".csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",