Skip to content

Commit 561e8cb

Browse files
committed
Fix #13
Fix #14
1 parent edeaa42 commit 561e8cb

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>fr.sparna.rdf.xls2rdf</groupId>
66
<artifactId>xls2rdf-pom</artifactId>
7-
<version>2.0.1</version>
7+
<version>2.0.3</version>
88
<packaging>pom</packaging>
99

1010
<name>XLS2RDF root POM</name>

xls2rdf-app/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
<parent>
66
<groupId>fr.sparna.rdf.xls2rdf</groupId>
77
<artifactId>xls2rdf-pom</artifactId>
8-
<version>2.0.1</version>
8+
<version>2.0.3</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

1212
<groupId>fr.sparna.rdf.xls2rdf</groupId>
1313
<artifactId>xls2rdf-app</artifactId>
1414
<!-- version inherited from parent pom -->
1515

16-
<name>Sparna SKOS : Excel2RDF Command Line application</name>
17-
<description>Application to run Excel2RDF converter</description>
16+
<name>Excel2RDF Command Line application</name>
17+
<description>Application to run Excel2RDF converter and generate RDF from Excel spreadsheets</description>
1818

1919
<organization>
2020
<name>Sparna</name>
@@ -121,7 +121,7 @@
121121
<dependency>
122122
<groupId>fr.sparna.rdf.xls2rdf</groupId>
123123
<artifactId>xls2rdf-lib</artifactId>
124-
<version>2.0.1</version>
124+
<version>2.0.3</version>
125125
</dependency>
126126

127127
<dependency>

xls2rdf-lib/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<parent>
66
<groupId>fr.sparna.rdf.xls2rdf</groupId>
77
<artifactId>xls2rdf-pom</artifactId>
8-
<version>2.0.1</version>
8+
<version>2.0.3</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

1212
<groupId>fr.sparna.rdf.xls2rdf</groupId>
1313
<artifactId>xls2rdf-lib</artifactId>
1414
<!-- version inherited from parent pom -->
1515

16-
<name>Sparna SKOS : Excel2RDF Library</name>
16+
<name>Excel2RDF Library</name>
1717
<description>Turns Excel files from specific templates into RDF and SKOS</description>
1818

1919
<organization>

xls2rdf-lib/src/main/java/fr/sparna/rdf/xls2rdf/ExcelHelper.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package fr.sparna.rdf.xls2rdf;
22

3+
import java.util.ArrayList;
34
import java.util.Calendar;
5+
import java.util.List;
46
import java.util.TimeZone;
57

68
import org.apache.poi.ss.usermodel.Cell;
79
import org.apache.poi.ss.usermodel.CellType;
810
import org.apache.poi.ss.usermodel.DateUtil;
911
import org.apache.poi.ss.usermodel.Row;
1012
import org.apache.poi.ss.usermodel.Sheet;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1115

1216
public class ExcelHelper {
1317

18+
private static Logger log = LoggerFactory.getLogger(ExcelHelper.class.getName());
19+
1420
private ExcelHelper() {
1521
}
1622

@@ -51,17 +57,29 @@ public static Calendar asCalendar(String value) {
5157
}
5258

5359
public static Row columnLookup(String value, Sheet sheet, int columnIndex) {
60+
List<Row> foundRows = new ArrayList<>();
5461
for(Row r : sheet) {
5562
Cell c = r.getCell(columnIndex);
5663
if(c != null) {
5764
String cellValue = getCellValue(c);
5865
if(cellValue.trim().equals(value.trim())) {
59-
return r;
66+
foundRows.add(r);
6067
}
6168
}
6269
}
6370

64-
return null;
71+
if(foundRows.size() == 0) {
72+
// not found
73+
return null;
74+
} else if(foundRows.size() > 1) {
75+
// found multiple times
76+
throw new Xls2RdfException("Ambiguous reference : found value '"+value+"' "+foundRows.size()+" times in column index "+columnIndex+". Fix the values to garantee they are unique.");
77+
} else {
78+
// single value
79+
return foundRows.get(0);
80+
}
81+
82+
6583
}
6684

6785

xls2rdf-lib/src/main/java/fr/sparna/rdf/xls2rdf/SkosPostProcessor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public void afterSheet(Model model, Resource mainResource, List<Resource> rowRes
3131
}
3232

3333
// add the inverse broaders and narrowers
34+
log.debug("Adding inverse skos:broader and skos:narrower");
3435
model.filter(null, SKOS.BROADER, null).forEach(
3536
s -> {
3637
if(s.getObject() instanceof Resource) {
3738
model.add(((Resource)s.getObject()), SKOS.NARROWER, s.getSubject());
3839
} else {
39-
log.warn("Found a skos:broadeer with Literal value : "+s.getObject().stringValue());
40+
log.warn("Found a skos:broader with Literal value : '"+s.getObject().stringValue()+"'");
4041
}
4142
}
4243
);
@@ -45,17 +46,19 @@ public void afterSheet(Model model, Resource mainResource, List<Resource> rowRes
4546
if(s.getObject() instanceof Resource) {
4647
model.add(((Resource)s.getObject()), SKOS.BROADER, s.getSubject());
4748
} else {
48-
log.warn("Found a skos:narrower with Literal value : "+s.getObject().stringValue());
49+
log.warn("Found a skos:narrower with Literal value : '"+s.getObject().stringValue()+"'");
4950
}
5051
}
5152
);
5253

5354
if(!model.filter(mainResource, RDF.TYPE, SKOS.COLLECTION).isEmpty()) {
55+
log.debug("Adding skos:member to the main resource");
5456
// if the header object was explicitely typed as skos:Collection, then add skos:members to every included skos:Concept
5557
model.filter(null, RDF.TYPE, SKOS.CONCEPT).forEach(
5658
s -> { model.add(mainResource, SKOS.MEMBER, ((Resource)s.getSubject())); }
5759
);
5860
} else if(new ClassTest(model).test(mainResource)) {
61+
log.debug("Adding rdf:type to the main resource");
5962
// for each resource without an explicit rdf:type, declare it of the type specified in the header
6063
rowResources.stream().filter(r -> model.filter(r, RDF.TYPE, null).isEmpty()).forEach(r -> {
6164
model.add(r, RDF.TYPE, mainResource);
@@ -65,6 +68,7 @@ public void afterSheet(Model model, Resource mainResource, List<Resource> rowRes
6568
// no explicit type given in header : we suppose this is a ConceptScheme and apply SKOS post processings
6669

6770
// add a skos:inScheme to every skos:Concept or skos:Collection or skos:OrderedCollection that was created
71+
log.debug("Adding skos:inScheme");
6872
model.filter(null, RDF.TYPE, SKOS.CONCEPT).forEach(
6973
s -> { model.add(((Resource)s.getSubject()), SKOS.IN_SCHEME, mainResource); }
7074
);
@@ -77,6 +81,7 @@ public void afterSheet(Model model, Resource mainResource, List<Resource> rowRes
7781

7882
// if at least one skos:Concept was generated,
7983
// or if no entry was generated at all, declare the URI in B1 as a ConceptScheme
84+
log.debug("Setting rdf:type skos:ConceptScheme to main resource");
8085
if(
8186
!model.filter(null, RDF.TYPE, SKOS.CONCEPT).isEmpty()
8287
||
@@ -86,6 +91,7 @@ public void afterSheet(Model model, Resource mainResource, List<Resource> rowRes
8691
}
8792

8893
// add skos:topConceptOf and skos:hasTopConcept for each skos:Concept without broader/narrower
94+
log.debug("Adding skos:hasTopConcept / skos:topConceptOf");
8995
model.filter(null, RDF.TYPE, SKOS.CONCEPT).subjects().forEach(
9096
concept -> {
9197
if(

xls2rdf-lib/src/main/java/fr/sparna/rdf/xls2rdf/ValueProcessorFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,21 @@ public Value processValue(Model model, Resource subject, String value, Cell cell
421421
}
422422
}
423423
} else if(datatype.stringValue().equals(XMLSchema.BOOLEAN.stringValue())) {
424-
List<String> ALLOWED_BOOLEAN_VALUES = Arrays.asList(new String[] { "true", "false" });
424+
List<String> TRUE_VALUES = Arrays.asList(new String[] { "true", "vrai", "1" });
425+
List<String> FALSE_VALUES = Arrays.asList(new String[] { "false", "faux", "0" });
425426

426427
if(
427-
!ALLOWED_BOOLEAN_VALUES.contains(unescapedValue.toLowerCase())
428+
!TRUE_VALUES.contains(unescapedValue.toLowerCase())
429+
&&
430+
!FALSE_VALUES.contains(unescapedValue.toLowerCase())
428431
) {
429432
this.messageListener.onMessage(MessageCode.WRONG_FORMAT, new CellReference(cell).formatAsString(), "Failed to parse boolean format for value '"+ value +"'");
430433
} else {
431-
l = SimpleValueFactory.getInstance().createLiteral(unescapedValue.toLowerCase(), datatype);
434+
if(TRUE_VALUES.contains(unescapedValue.toLowerCase())) {
435+
l = SimpleValueFactory.getInstance().createLiteral("true", datatype);
436+
} else {
437+
l = SimpleValueFactory.getInstance().createLiteral("false", datatype);
438+
}
432439
}
433440
}
434441
else {

xls2rdf-lib/src/main/java/fr/sparna/rdf/xls2rdf/Xls2RdfConverter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,13 @@ private Model processSheet(Sheet sheet) {
322322
}
323323

324324
// read the rows after the header line and process each row
325+
log.info("Converting rows...");
325326
for (int rowIndex = (headerRowIndex + 1); rowIndex <= sheet.getLastRowNum(); rowIndex++) {
326327
Row r = sheet.getRow(rowIndex);
327328
if(r != null) {
329+
if(rowIndex % 1000 == 0) {
330+
log.info("Row "+rowIndex+"...");
331+
}
328332
Resource rowResource = handleRow(model, csResource, columnNames, prefixManager, r);
329333
if(rowResource != null) {
330334
rowResources.add(rowResource);

0 commit comments

Comments
 (0)