Skip to content

Commit a3c2fb9

Browse files
author
rossbowen
committed
Stop emitting triple when cell is null and valueUrl is present #45
1 parent 14c7e0a commit a3c2fb9

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

lib/metadata/TableSchema.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,21 @@ class TableSchema {
144144
return undefined
145145
}
146146

147-
if (column.valueUrl) {
148-
return this.factory.namedNode(column.valueUrl.fill(row))
149-
}
150-
151147
let value = column.titles.reduce((value, title) => {
152148
return value || row[title]
153149
}, '')
154150

155-
if (value === '') {
156-
value = column.defaultValue
151+
if (!column.virtual) {
152+
if (value === '') {
153+
value = column.defaultValue
154+
}
155+
if (typeof value === 'undefined' || value === column.nullValue) {
156+
return undefined
157+
}
157158
}
158159

159-
if (typeof value === 'undefined' || value === column.nullValue) {
160-
return undefined
160+
if (column.valueUrl) {
161+
return this.factory.namedNode(column.valueUrl.fill(row))
161162
}
162163

163164
if (column.datatype.base.value === this.ns.dateTime.value) {

test/support/test031-null-cell.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a,b
2+
100,200
3+
300,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"@context": "http://www.w3.org/ns/csvw",
3+
"url": "nulls.csv",
4+
"tableSchema": {
5+
"columns": [
6+
{
7+
"titles": "a",
8+
"name": "a",
9+
"propertyUrl": "http://example.org/a",
10+
"valueUrl": "http://example.org/{a}"
11+
},
12+
{
13+
"titles": "b",
14+
"name": "b",
15+
"propertyUrl": "http://example.org/b",
16+
"valueUrl": "http://example.org/{b}"
17+
}
18+
]
19+
}
20+
}

test/support/test031-null-cell.nt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
_:c14n0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/csvw#Row> .
2+
_:c14n0 <http://www.w3.org/ns/csvw#describes> _:c14n3 .
3+
_:c14n0 <http://www.w3.org/ns/csvw#rownum> "1"^^<http://www.w3.org/2001/XMLSchema#integer> .
4+
_:c14n0 <http://www.w3.org/ns/csvw#url> <test031-null-cell.csv#row=2> .
5+
_:c14n1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/csvw#Table> .
6+
_:c14n1 <http://www.w3.org/ns/csvw#row> _:c14n0 .
7+
_:c14n1 <http://www.w3.org/ns/csvw#row> _:c14n5 .
8+
_:c14n1 <http://www.w3.org/ns/csvw#url> <test031-null-cell.csv> .
9+
_:c14n2 <http://example.org/a> <http://example.org/300> .
10+
_:c14n3 <http://example.org/a> <http://example.org/100> .
11+
_:c14n3 <http://example.org/b> <http://example.org/200> .
12+
_:c14n4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/csvw#TableGroup> .
13+
_:c14n4 <http://www.w3.org/ns/csvw#table> _:c14n1 .
14+
_:c14n5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/csvw#Row> .
15+
_:c14n5 <http://www.w3.org/ns/csvw#describes> _:c14n2 .
16+
_:c14n5 <http://www.w3.org/ns/csvw#rownum> "2"^^<http://www.w3.org/2001/XMLSchema#integer> .
17+
_:c14n5 <http://www.w3.org/ns/csvw#url> <test031-null-cell.csv#row=3> .

0 commit comments

Comments
 (0)