Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force cell values (codes and labels of codelists) to be retrieved as … #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/main/java/eu/europa/ec/eurostat/los/codes/CodelistMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,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 {

Expand All @@ -54,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");
Expand All @@ -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);
Expand All @@ -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) {

Expand Down