Skip to content

Commit

Permalink
insert rdf:type into generated RDF when each value is specified in co…
Browse files Browse the repository at this point in the history
…nvert settings json for a primary csv (#32)
  • Loading branch information
banjun authored and takanakahiko committed May 3, 2019
1 parent e48ce83 commit 0af5615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _data/convert-settings/pripara-characters-setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"subjectBaseUrl": "/rdfs/characters/",
"PredicateBaseUrl": "/preds/",
"dataCsvPath": "../_data/pripara-characters.csv",
"columnsCsvPath": "../_data/convert-settings/pripara-characters-columns.csv"
"columnsCsvPath": "../_data/convert-settings/pripara-characters-columns.csv",
"rdfType": "$BASE_URL/prism-schema.ttl#Character"
}
8 changes: 8 additions & 0 deletions csv2rdf/csv2rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Setting {
PredicateBaseUrl: string
dataCsvPath: string
columnsCsvPath: string
rdfType: string
}

const addQuad = (store: N3.N3Store, key, predicate, subject, setting: Setting) => {
Expand Down Expand Up @@ -52,6 +53,13 @@ export default class {
const datas = await getDatas(setting.dataCsvPath)
const columns = await getColumns(setting.columnsCsvPath)
datas.forEach(row => {
if (setting.rdfType) {
this.store.addQuad(
process.env.BASE_URL + setting.subjectBaseUrl + row["key"],
namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
namedNode(setting.rdfType.replace("$BASE_URL", process.env.BASE_URL))
);
}
columns.forEach(col => {
if (row[col.key].length > 0) addQuad(this.store, row["key"], col.prdicate, row[col.key], setting)
})
Expand Down

0 comments on commit 0af5615

Please sign in to comment.