Skip to content

Commit 36150c2

Browse files
authored
Merge pull request #46 from rossbowen/null-cell
Stop emitting triple when cell is null and valueUrl is present #45
2 parents a503d83 + a3c2fb9 commit 36150c2

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
@@ -146,20 +146,21 @@ class TableSchema {
146146
return undefined
147147
}
148148

149-
if (column.valueUrl) {
150-
return this.factory.namedNode(column.valueUrl.fill(row))
151-
}
152-
153149
let value = column.titles.reduce((value, title) => {
154150
return value || row[title]
155151
}, '')
156152

157-
if (value === '') {
158-
value = column.defaultValue
153+
if (!column.virtual) {
154+
if (value === '') {
155+
value = column.defaultValue
156+
}
157+
if (typeof value === 'undefined' || value === column.nullValue) {
158+
return undefined
159+
}
159160
}
160161

161-
if (typeof value === 'undefined' || value === column.nullValue) {
162-
return undefined
162+
if (column.valueUrl) {
163+
return this.factory.namedNode(column.valueUrl.fill(row))
163164
}
164165

165166
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)