Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions bin/jskos-convert
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program
.option("-m, --marktop", "explicitly mark concepts without broader as top concepts")
.option("--creator <uri and/or name>", "add creator to mappings")
.option("--created <timestamp>", "add creation timestamp to mappings")
.option("-i, --identifier", "add mapping sameness identifier")
.option("--delimiter <char>", "CSV delimiter (default: ,)")
.example("mappings -t csv mappings.ndjson")
.example("concepts -r registry.json -s example http://example.org/jskos.csv")
Expand Down
14 changes: 13 additions & 1 deletion lib/jskos-convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mappingsFromRows from "./csv-to-mapping.js"
import conceptsFromRows from "./csv-to-concept.js"
import rowsFromConcepts from "./concept-to-csv.js"

import { ConceptScheme } from "jskos-tools"
import { ConceptScheme, addMappingIdentifiers } from "jskos-tools"

import rdfSerializer from "./rdf-serializer.js"
import { formats } from "./rdf-serializer.js"
Expand Down Expand Up @@ -86,6 +86,18 @@ function convert (opts) {
} else if (from === "csv" && to === "ndjson") {
steps.push(mappingsFromRows({ language, fromScheme: scheme, toScheme: destination, partOf: partof, creator, created }))
}
if (opts.identifier) {
steps.push(new stream.Transform({
objectMode: true,
async transform(mapping, encoding, callback) {
try {
callback(null, await addMappingIdentifiers(mapping))
} catch(e) {
callback(e)
}
},
}))
}
if (opts.validate) {
steps.push(validator(opts))
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"cocoda-sdk": "^3.4.13",
"commander": "^12.1.0",
"csv": "^6.4.1",
"jskos-tools": "^1.0.43",
"jskos-tools": "^1.2.0",
"jskos-validate": "^1.2.0",
"json-anystream": "^2.0.1",
"jsonld": "^9.0.0",
Expand Down
32 changes: 31 additions & 1 deletion test/convert-mappings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import { ConceptScheme } from "jskos-tools"
import { ConceptScheme, addMappingIdentifiers } from "jskos-tools"
import mappingsFromRows from "../lib/csv-to-mapping.js"

// { fromNotation: "612.111", toNotation: "4070945-0", type: "exact" }
Expand Down Expand Up @@ -81,4 +81,34 @@ describe("convert-mappings", () => {

done()
})

it("adds mapping sameness identifier", async () => {
const mapping = {
from: { memberSet: [{ uri: "http://example.org/voc/A1", notation: ["A1"] }] },
fromScheme: { uri: "http://example.org/voc" },
to: { memberSet: [{ uri: "http://example.com/voc/x", notation: ["x"] }] },
toScheme: { uri: "http://example.com/voc" },
type: ["http://www.w3.org/2004/02/skos/core#exactMatch"],
}
const result = await addMappingIdentifiers(mapping)
assert.ok(Array.isArray(result.identifier))
assert.ok(result.identifier.some(id => id.startsWith("mapping:")))
assert.ok(result.identifier.some(id => id.startsWith("urn:jskos:mapping:members:")))
assert.ok(result.identifier.some(id => id.startsWith("urn:jskos:mapping:content:")))
})

it("replaces existing mapping sameness identifier", async () => {
const mapping = {
from: { memberSet: [{ uri: "http://example.org/voc/A1", notation: ["A1"] }] },
fromScheme: { uri: "http://example.org/voc" },
to: { memberSet: [{ uri: "http://example.com/voc/x", notation: ["x"] }] },
toScheme: { uri: "http://example.com/voc" },
type: ["http://www.w3.org/2004/02/skos/core#exactMatch"],
identifier: ["mapping:oldid"],
}
const result = await addMappingIdentifiers(mapping)
const samenessIds = result.identifier.filter(id => id.startsWith("mapping:"))
assert.strictEqual(samenessIds.length, 1)
assert.ok(!samenessIds[0].includes("oldid"))
})
})
Loading