From e1bab599561ad4a3f2f353b38b9fb79eff2c597d Mon Sep 17 00:00:00 2001 From: Mugiwara84 Date: Tue, 11 Sep 2018 11:46:55 +0200 Subject: [PATCH 1/2] Force cell values (codes and labels of codelists) to be retrieved as strings. --- .../europa/ec/eurostat/los/codes/CodelistMaker.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java b/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java index 076feda..ee6da03 100644 --- a/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java +++ b/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java @@ -17,6 +17,8 @@ import org.apache.jena.vocabulary.RDFS; import org.apache.jena.vocabulary.SKOS; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -75,8 +77,8 @@ public static Model createConceptScheme(String clTag, Sheet clSheet) { rowIterator.next(); while (rowIterator.hasNext()) { Row currentRow = rowIterator.next(); - String itemCode = currentRow.getCell(0).toString().trim(); - String itemName = currentRow.getCell(1).toString().trim(); + String itemCode = getStringValue(currentRow.getCell(0)); + String itemName = getStringValue(currentRow.getCell(1)); Resource item = clModel.createResource(clURI + "/" + itemCode, concept); item.addProperty(RDF.type, SKOS.Concept); item.addProperty(SKOS.notation, itemCode); @@ -86,6 +88,11 @@ public static Model createConceptScheme(String clTag, Sheet clSheet) { return clModel; } + + private static String getStringValue(Cell cellule) { + cellule.setCellType(CellType.STRING); + return cellule.toString().trim(); + } private static String normalize(String original) { From f7ac79faf5f1fea83cc83bc3796d176bea5287d0 Mon Sep 17 00:00:00 2001 From: Mugiwara84 Date: Tue, 11 Sep 2018 14:14:42 +0200 Subject: [PATCH 2/2] Concept scheme and associated concept are deduced from sheet name. --- .../eu/europa/ec/eurostat/los/codes/CodelistMaker.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java b/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java index ee6da03..c4954ca 100644 --- a/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java +++ b/src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java @@ -31,6 +31,7 @@ public class CodelistMaker { public final static String BASE_URI = "http://id.linked-open-statistics.org/"; public final static String CODES_BASE_URI = BASE_URI + "codes/"; public final static String CONCEPTS_BASE_URI = BASE_URI + "concepts/"; + public final static String BASE_CONCEPT_SCHEME_LABEL="Code list for"; public static void main(String[] args) throws IOException { @@ -56,10 +57,9 @@ public static Model createConceptScheme(String clTag, Sheet clSheet) { clModel.setNsPrefix("los-codes", CODES_BASE_URI); clModel.setNsPrefix("los-concepts", CONCEPTS_BASE_URI); - // Codelist code and name should be on the first line - // Create the concept scheme and the associated concept - String conceptName = normalize(clSheet.getRow(0).getCell(0).toString()); - String clName = clSheet.getRow(0).getCell(1).toString(); + // Create the concept scheme and the associated concept from sheet name + String conceptName = normalize(clSheet.getSheetName()); + String clName = BASE_CONCEPT_SCHEME_LABEL +" "+conceptName; String clURI = CODES_BASE_URI + clTag; Resource scheme = clModel.createResource(clURI, SKOS.ConceptScheme); scheme.addProperty(SKOS.prefLabel, clName, "fr");