@lsbjordao/type-taxon-script 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tts +1 -1
- package/dist/export.js +33 -33
- package/dist/exportOntology.js +356 -0
- package/dist/exportToCsv.js +33 -33
- package/dist/init.js +16 -16
- package/dist/src/export.js +238 -0
- package/dist/src/exportOntology.js +366 -0
- package/dist/src/exportSources.js +63 -0
- package/dist/src/exportToCsv.js +268 -0
- package/dist/src/findProperty.js +58 -0
- package/dist/src/import.js +98 -0
- package/dist/src/init.js +141 -0
- package/dist/src/new.js +47 -0
- package/dist/src/tts.js +130 -0
- package/package.json +43 -39
- package/readme.md +540 -540
package/bin/tts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
require('../dist/tts.js')
|
package/dist/export.js
CHANGED
|
@@ -64,22 +64,22 @@ function ttsExport(genus, load) {
|
|
|
64
64
|
const speciesCall = taxa.map((species) => {
|
|
65
65
|
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
66
66
|
}).join('\n');
|
|
67
|
-
const fileContent = `// Import genus ${genus}
|
|
68
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
69
|
-
|
|
70
|
-
// Import species of ${genus}
|
|
71
|
-
${importStatements}
|
|
72
|
-
|
|
73
|
-
const ${genus}_species: ${genus}[] = [
|
|
74
|
-
${speciesCall}
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
// Export ${genus}DB.json
|
|
78
|
-
//import { writeFileSync } from 'fs'
|
|
79
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
80
|
-
console.log(jsonData)
|
|
81
|
-
//const inputFilePath = '../output/${genus}DB.json'
|
|
82
|
-
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
67
|
+
const fileContent = `// Import genus ${genus}
|
|
68
|
+
import { ${genus} } from '../taxon/${genus}'
|
|
69
|
+
|
|
70
|
+
// Import species of ${genus}
|
|
71
|
+
${importStatements}
|
|
72
|
+
|
|
73
|
+
const ${genus}_species: ${genus}[] = [
|
|
74
|
+
${speciesCall}
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
// Export ${genus}DB.json
|
|
78
|
+
//import { writeFileSync } from 'fs'
|
|
79
|
+
const jsonData = JSON.stringify(${genus}_species);
|
|
80
|
+
console.log(jsonData)
|
|
81
|
+
//const inputFilePath = '../output/${genus}DB.json'
|
|
82
|
+
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
83
83
|
//console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
84
84
|
const tempFilePath = './temp/exportTemp.ts';
|
|
85
85
|
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
@@ -156,23 +156,23 @@ console.log(jsonData)
|
|
|
156
156
|
const speciesCall = taxa.map((species) => {
|
|
157
157
|
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
158
158
|
}).join('\n');
|
|
159
|
-
const fileContent = `// Import genus ${genus}
|
|
160
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
161
|
-
|
|
162
|
-
// Import species of ${genus}
|
|
163
|
-
${importStatements}
|
|
164
|
-
|
|
165
|
-
const ${genus}_species: ${genus}[] = [
|
|
166
|
-
${speciesCall}
|
|
167
|
-
]
|
|
168
|
-
|
|
169
|
-
// Export ${genus}DB.json
|
|
170
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
171
|
-
console.log(jsonData)
|
|
172
|
-
// import { writeFileSync } from 'fs'
|
|
173
|
-
// const jsonData = JSON.stringify(${genus}_species)
|
|
174
|
-
// const inputFilePath = '../output/${genus}DB.json'
|
|
175
|
-
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
159
|
+
const fileContent = `// Import genus ${genus}
|
|
160
|
+
import { ${genus} } from '../taxon/${genus}'
|
|
161
|
+
|
|
162
|
+
// Import species of ${genus}
|
|
163
|
+
${importStatements}
|
|
164
|
+
|
|
165
|
+
const ${genus}_species: ${genus}[] = [
|
|
166
|
+
${speciesCall}
|
|
167
|
+
]
|
|
168
|
+
|
|
169
|
+
// Export ${genus}DB.json
|
|
170
|
+
const jsonData = JSON.stringify(${genus}_species);
|
|
171
|
+
console.log(jsonData)
|
|
172
|
+
// import { writeFileSync } from 'fs'
|
|
173
|
+
// const jsonData = JSON.stringify(${genus}_species)
|
|
174
|
+
// const inputFilePath = '../output/${genus}DB.json'
|
|
175
|
+
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
176
176
|
// console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
177
177
|
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
178
178
|
const fileToTranspile = 'exportTemp';
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const fs_1 = __importDefault(require("fs"));
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
41
|
+
const n3_1 = require("n3");
|
|
42
|
+
const { namedNode, literal, quad, blankNode } = n3_1.DataFactory;
|
|
43
|
+
const NS = {
|
|
44
|
+
tts: 'https://tts.example.org/ontology/',
|
|
45
|
+
inst: 'https://tts.example.org/instance/',
|
|
46
|
+
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
|
47
|
+
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
|
|
48
|
+
owl: 'http://www.w3.org/2002/07/owl#',
|
|
49
|
+
skos: 'http://www.w3.org/2004/02/skos/core#',
|
|
50
|
+
xsd: 'http://www.w3.org/2001/XMLSchema#',
|
|
51
|
+
dcterms: 'http://purl.org/dc/terms/',
|
|
52
|
+
prov: 'http://www.w3.org/ns/prov#'
|
|
53
|
+
};
|
|
54
|
+
function tts(local) {
|
|
55
|
+
return namedNode(`${NS.tts}${encodeURIComponent(local)}`);
|
|
56
|
+
}
|
|
57
|
+
function inst(local) {
|
|
58
|
+
return namedNode(`${NS.inst}${encodeURIComponent(local)}`);
|
|
59
|
+
}
|
|
60
|
+
function rdf(local) {
|
|
61
|
+
return namedNode(`${NS.rdf}${local}`);
|
|
62
|
+
}
|
|
63
|
+
function rdfs(local) {
|
|
64
|
+
return namedNode(`${NS.rdfs}${local}`);
|
|
65
|
+
}
|
|
66
|
+
function owl(local) {
|
|
67
|
+
return namedNode(`${NS.owl}${local}`);
|
|
68
|
+
}
|
|
69
|
+
function skos(local) {
|
|
70
|
+
return namedNode(`${NS.skos}${local}`);
|
|
71
|
+
}
|
|
72
|
+
function xsd(local) {
|
|
73
|
+
return namedNode(`${NS.xsd}${local}`);
|
|
74
|
+
}
|
|
75
|
+
function dcterms(local) {
|
|
76
|
+
return namedNode(`${NS.dcterms}${local}`);
|
|
77
|
+
}
|
|
78
|
+
function prov(local) {
|
|
79
|
+
return namedNode(`${NS.prov}${local}`);
|
|
80
|
+
}
|
|
81
|
+
function createWriter() {
|
|
82
|
+
return new n3_1.Writer({
|
|
83
|
+
prefixes: {
|
|
84
|
+
tts: NS.tts,
|
|
85
|
+
inst: NS.inst,
|
|
86
|
+
rdf: NS.rdf,
|
|
87
|
+
rdfs: NS.rdfs,
|
|
88
|
+
owl: NS.owl,
|
|
89
|
+
skos: NS.skos,
|
|
90
|
+
xsd: NS.xsd,
|
|
91
|
+
dcterms: NS.dcterms,
|
|
92
|
+
prov: NS.prov
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function writerToString(writer) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
writer.end((err, result) => {
|
|
99
|
+
if (err)
|
|
100
|
+
reject(err);
|
|
101
|
+
else
|
|
102
|
+
resolve(result);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function isClassLike(value) {
|
|
107
|
+
return typeof value === 'function' && !!value.prototype;
|
|
108
|
+
}
|
|
109
|
+
function isPrimitive(value) {
|
|
110
|
+
return (typeof value === 'string' ||
|
|
111
|
+
typeof value === 'number' ||
|
|
112
|
+
typeof value === 'boolean');
|
|
113
|
+
}
|
|
114
|
+
function normalizeDatatype(datatype) {
|
|
115
|
+
if (!datatype)
|
|
116
|
+
return null;
|
|
117
|
+
if (datatype.startsWith('xsd:')) {
|
|
118
|
+
return namedNode(datatype.replace('xsd:', NS.xsd));
|
|
119
|
+
}
|
|
120
|
+
if (datatype.startsWith('http://') || datatype.startsWith('https://')) {
|
|
121
|
+
return namedNode(datatype);
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function addMappings(writer, subject, mappings) {
|
|
126
|
+
if (!(mappings === null || mappings === void 0 ? void 0 : mappings.length))
|
|
127
|
+
return;
|
|
128
|
+
for (const m of mappings) {
|
|
129
|
+
writer.addQuad(subject, skos(m.relation), namedNode(m.iri));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function toPascalLike(input) {
|
|
133
|
+
return input
|
|
134
|
+
.replace(/\.ts$/, '')
|
|
135
|
+
.replace(/[_\-\s]+([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())
|
|
136
|
+
.replace(/^[a-z]/, c => c.toUpperCase());
|
|
137
|
+
}
|
|
138
|
+
function localId(value, fallback) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
return (_b = (_a = value === null || value === void 0 ? void 0 : value._id) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.id) !== null && _b !== void 0 ? _b : fallback;
|
|
141
|
+
}
|
|
142
|
+
function primitiveToLiteral(value) {
|
|
143
|
+
if (typeof value === 'string')
|
|
144
|
+
return literal(value);
|
|
145
|
+
if (typeof value === 'number')
|
|
146
|
+
return literal(String(value), xsd('decimal'));
|
|
147
|
+
return literal(String(value), xsd('boolean'));
|
|
148
|
+
}
|
|
149
|
+
function importModules(pattern) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const files = yield (0, fast_glob_1.default)(pattern, { absolute: true });
|
|
152
|
+
const modules = [];
|
|
153
|
+
for (const file of files) {
|
|
154
|
+
const mod = yield Promise.resolve(`${toFileUrl(file)}`).then(s => __importStar(require(s)));
|
|
155
|
+
modules.push({ file, mod });
|
|
156
|
+
}
|
|
157
|
+
return modules;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function toFileUrl(filePath) {
|
|
161
|
+
return `file://${path_1.default.resolve(filePath)}`;
|
|
162
|
+
}
|
|
163
|
+
function inferRangeFromValue(value) {
|
|
164
|
+
if (typeof value === 'number')
|
|
165
|
+
return xsd('decimal');
|
|
166
|
+
if (typeof value === 'boolean')
|
|
167
|
+
return xsd('boolean');
|
|
168
|
+
if (typeof value === 'string')
|
|
169
|
+
return xsd('string');
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
function serializeSourceLikeArray(writer, subject, values) {
|
|
173
|
+
for (const v of values) {
|
|
174
|
+
if (typeof v === 'string') {
|
|
175
|
+
writer.addQuad(subject, dcterms('source'), literal(v));
|
|
176
|
+
}
|
|
177
|
+
else if (v && typeof v === 'object') {
|
|
178
|
+
const refNode = blankNode();
|
|
179
|
+
writer.addQuad(subject, dcterms('source'), refNode);
|
|
180
|
+
for (const [rk, rv] of Object.entries(v)) {
|
|
181
|
+
if (rv == null)
|
|
182
|
+
continue;
|
|
183
|
+
if (typeof rv === 'string') {
|
|
184
|
+
writer.addQuad(refNode, tts(rk), literal(rv));
|
|
185
|
+
}
|
|
186
|
+
else if (typeof rv === 'number') {
|
|
187
|
+
writer.addQuad(refNode, tts(rk), literal(String(rv), xsd('decimal')));
|
|
188
|
+
}
|
|
189
|
+
else if (typeof rv === 'boolean') {
|
|
190
|
+
writer.addQuad(refNode, tts(rk), literal(String(rv), xsd('boolean')));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function serializeObject(writer, subject, object, objectTypeName, objectId, visited) {
|
|
197
|
+
var _a, _b, _c, _d;
|
|
198
|
+
if (visited.has(object))
|
|
199
|
+
return;
|
|
200
|
+
visited.add(object);
|
|
201
|
+
writer.addQuad(subject, rdf('type'), tts(objectTypeName));
|
|
202
|
+
for (const [key, value] of Object.entries(object)) {
|
|
203
|
+
if (value == null)
|
|
204
|
+
continue;
|
|
205
|
+
if (key.startsWith('_'))
|
|
206
|
+
continue;
|
|
207
|
+
if (key === 'sources' && Array.isArray(value)) {
|
|
208
|
+
serializeSourceLikeArray(writer, subject, value);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const predicate = tts(key);
|
|
212
|
+
if (isPrimitive(value)) {
|
|
213
|
+
writer.addQuad(subject, predicate, primitiveToLiteral(value));
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (Array.isArray(value)) {
|
|
217
|
+
for (let i = 0; i < value.length; i++) {
|
|
218
|
+
const item = value[i];
|
|
219
|
+
if (item == null)
|
|
220
|
+
continue;
|
|
221
|
+
if (isPrimitive(item)) {
|
|
222
|
+
writer.addQuad(subject, predicate, primitiveToLiteral(item));
|
|
223
|
+
}
|
|
224
|
+
else if (typeof item === 'object') {
|
|
225
|
+
const childId = localId(item, `${objectId}-${key}-${i + 1}`);
|
|
226
|
+
const childNode = inst(childId);
|
|
227
|
+
writer.addQuad(subject, predicate, childNode);
|
|
228
|
+
serializeObject(writer, childNode, item, (_b = (_a = item.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : toPascalLike(key), childId, visited);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (typeof value === 'object') {
|
|
234
|
+
const childId = localId(value, `${objectId}-${key}`);
|
|
235
|
+
const childNode = inst(childId);
|
|
236
|
+
writer.addQuad(subject, predicate, childNode);
|
|
237
|
+
serializeObject(writer, childNode, value, (_d = (_c = value.constructor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : toPascalLike(key), childId, visited);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function buildOntologyTTL() {
|
|
242
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const writer = createWriter();
|
|
245
|
+
const modules = yield importModules('./characters/v1/**/*.ts');
|
|
246
|
+
for (const { mod } of modules) {
|
|
247
|
+
for (const exported of Object.values(mod)) {
|
|
248
|
+
if (!isClassLike(exported))
|
|
249
|
+
continue;
|
|
250
|
+
const cls = exported;
|
|
251
|
+
const classNode = tts(cls.name);
|
|
252
|
+
writer.addQuad(classNode, rdf('type'), owl('Class'));
|
|
253
|
+
writer.addQuad(classNode, rdfs('label'), literal((_b = (_a = cls.semantic) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : cls.name));
|
|
254
|
+
if ((_c = cls.semantic) === null || _c === void 0 ? void 0 : _c.definition) {
|
|
255
|
+
writer.addQuad(classNode, rdfs('comment'), literal(cls.semantic.definition));
|
|
256
|
+
}
|
|
257
|
+
addMappings(writer, classNode, (_d = cls.semantic) === null || _d === void 0 ? void 0 : _d.ontologyMappings);
|
|
258
|
+
const attrs = (_e = cls.semanticAttributes) !== null && _e !== void 0 ? _e : {};
|
|
259
|
+
for (const [attrName, meta] of Object.entries(attrs)) {
|
|
260
|
+
const propNode = tts(attrName);
|
|
261
|
+
const kind = meta.kind === 'object' ? owl('ObjectProperty') : owl('DatatypeProperty');
|
|
262
|
+
writer.addQuad(propNode, rdf('type'), kind);
|
|
263
|
+
writer.addQuad(propNode, rdfs('domain'), classNode);
|
|
264
|
+
writer.addQuad(propNode, rdfs('label'), literal((_f = meta.label) !== null && _f !== void 0 ? _f : attrName));
|
|
265
|
+
if (meta.definition) {
|
|
266
|
+
writer.addQuad(propNode, rdfs('comment'), literal(meta.definition));
|
|
267
|
+
}
|
|
268
|
+
const dt = normalizeDatatype(meta.datatype);
|
|
269
|
+
if (dt) {
|
|
270
|
+
writer.addQuad(propNode, rdfs('range'), dt);
|
|
271
|
+
}
|
|
272
|
+
if (meta.unit) {
|
|
273
|
+
writer.addQuad(propNode, dcterms('format'), literal(meta.unit));
|
|
274
|
+
}
|
|
275
|
+
addMappings(writer, propNode, meta.ontologyMappings);
|
|
276
|
+
if ((_g = meta.allowedValues) === null || _g === void 0 ? void 0 : _g.length) {
|
|
277
|
+
for (const value of meta.allowedValues) {
|
|
278
|
+
writer.addQuad(propNode, tts('allowedValue'), literal(value));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return writerToString(writer);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function buildInstancesTTL(genus) {
|
|
288
|
+
var _a, _b;
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
const writer = createWriter();
|
|
291
|
+
const modules = yield importModules(`./taxon/${genus}/**/*.ts`);
|
|
292
|
+
const visited = new WeakSet();
|
|
293
|
+
for (const { file, mod } of modules) {
|
|
294
|
+
const fileName = path_1.default.basename(file, '.ts');
|
|
295
|
+
for (const [exportName, exported] of Object.entries(mod)) {
|
|
296
|
+
if (!exported || typeof exported !== 'object')
|
|
297
|
+
continue;
|
|
298
|
+
const subjectId = localId(exported, exportName || fileName);
|
|
299
|
+
const subjectNode = inst(subjectId);
|
|
300
|
+
serializeObject(writer, subjectNode, exported, (_b = (_a = exported.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : toPascalLike(fileName), subjectId, visited);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return writerToString(writer);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function mergeTTL(ttls) {
|
|
307
|
+
const nonEmpty = ttls.filter(Boolean);
|
|
308
|
+
if (!nonEmpty.length)
|
|
309
|
+
return '';
|
|
310
|
+
const prefixLines = new Set();
|
|
311
|
+
const bodies = [];
|
|
312
|
+
for (const ttl of nonEmpty) {
|
|
313
|
+
const lines = ttl.split('\n');
|
|
314
|
+
const localBody = [];
|
|
315
|
+
for (const line of lines) {
|
|
316
|
+
if (line.startsWith('@prefix')) {
|
|
317
|
+
prefixLines.add(line);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
localBody.push(line);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
bodies.push(localBody.join('\n').trim());
|
|
324
|
+
}
|
|
325
|
+
return `${Array.from(prefixLines).join('\n')}\n\n${bodies.join('\n\n')}\n`;
|
|
326
|
+
}
|
|
327
|
+
function ttsExportOntology(genus) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
if (!genus) {
|
|
330
|
+
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (!fs_1.default.existsSync('./characters/v1')) {
|
|
334
|
+
console.error('\x1b[31m✖ Directory ./characters/v1 not found.\x1b[0m');
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (!fs_1.default.existsSync(`./taxon/${genus}`)) {
|
|
338
|
+
console.error(`\x1b[31m✖ Directory ./taxon/${genus} not found.\x1b[0m`);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
fs_1.default.mkdirSync('./output', { recursive: true });
|
|
342
|
+
const ontologyTTL = yield buildOntologyTTL();
|
|
343
|
+
const instancesTTL = yield buildInstancesTTL(genus);
|
|
344
|
+
const semanticTTL = mergeTTL([ontologyTTL, instancesTTL]);
|
|
345
|
+
const ontologyPath = `./output/${genus}Ontology.ttl`;
|
|
346
|
+
const instancesPath = `./output/${genus}Instances.ttl`;
|
|
347
|
+
const semanticPath = `./output/${genus}Semantic.ttl`;
|
|
348
|
+
fs_1.default.writeFileSync(ontologyPath, ontologyTTL, 'utf8');
|
|
349
|
+
fs_1.default.writeFileSync(instancesPath, instancesTTL, 'utf8');
|
|
350
|
+
fs_1.default.writeFileSync(semanticPath, semanticTTL, 'utf8');
|
|
351
|
+
console.log(`\x1b[1m\x1b[32m✔ Ontology schema exported: \x1b[33m${ontologyPath}\x1b[0m`);
|
|
352
|
+
console.log(`\x1b[1m\x1b[32m✔ RDF instances exported: \x1b[33m${instancesPath}\x1b[0m`);
|
|
353
|
+
console.log(`\x1b[1m\x1b[32m✔ Combined semantic graph exported: \x1b[33m${semanticPath}\x1b[0m`);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
exports.default = ttsExportOntology;
|
package/dist/exportToCsv.js
CHANGED
|
@@ -66,22 +66,22 @@ function ttsExportToCsv(genus, load) {
|
|
|
66
66
|
const speciesCall = taxa.map((species) => {
|
|
67
67
|
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
68
68
|
}).join('\n');
|
|
69
|
-
const fileContent = `// Import genus ${genus}
|
|
70
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
71
|
-
|
|
72
|
-
// Import species of ${genus}
|
|
73
|
-
${importStatements}
|
|
74
|
-
|
|
75
|
-
const ${genus}_species: ${genus}[] = [
|
|
76
|
-
${speciesCall}
|
|
77
|
-
]
|
|
78
|
-
|
|
79
|
-
// Export ${genus}DB.json
|
|
80
|
-
//import { writeFileSync } from 'fs'
|
|
81
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
82
|
-
console.log(jsonData)
|
|
83
|
-
//const inputFilePath = '../output/${genus}DB.json'
|
|
84
|
-
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
69
|
+
const fileContent = `// Import genus ${genus}
|
|
70
|
+
import { ${genus} } from '../taxon/${genus}'
|
|
71
|
+
|
|
72
|
+
// Import species of ${genus}
|
|
73
|
+
${importStatements}
|
|
74
|
+
|
|
75
|
+
const ${genus}_species: ${genus}[] = [
|
|
76
|
+
${speciesCall}
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
// Export ${genus}DB.json
|
|
80
|
+
//import { writeFileSync } from 'fs'
|
|
81
|
+
const jsonData = JSON.stringify(${genus}_species);
|
|
82
|
+
console.log(jsonData)
|
|
83
|
+
//const inputFilePath = '../output/${genus}DB.json'
|
|
84
|
+
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
85
85
|
//console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
86
86
|
const tempFilePath = './temp/exportTemp.ts';
|
|
87
87
|
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
@@ -172,23 +172,23 @@ console.log(jsonData)
|
|
|
172
172
|
const speciesCall = taxa.map((species) => {
|
|
173
173
|
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
174
174
|
}).join('\n');
|
|
175
|
-
const fileContent = `// Import genus ${genus}
|
|
176
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
177
|
-
|
|
178
|
-
// Import species of ${genus}
|
|
179
|
-
${importStatements}
|
|
180
|
-
|
|
181
|
-
const ${genus}_species: ${genus}[] = [
|
|
182
|
-
${speciesCall}
|
|
183
|
-
]
|
|
184
|
-
|
|
185
|
-
// Export ${genus}DB.json
|
|
186
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
187
|
-
console.log(jsonData)
|
|
188
|
-
// import { writeFileSync } from 'fs'
|
|
189
|
-
// const jsonData = JSON.stringify(${genus}_species)
|
|
190
|
-
// const inputFilePath = '../output/${genus}DB.json'
|
|
191
|
-
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
175
|
+
const fileContent = `// Import genus ${genus}
|
|
176
|
+
import { ${genus} } from '../taxon/${genus}'
|
|
177
|
+
|
|
178
|
+
// Import species of ${genus}
|
|
179
|
+
${importStatements}
|
|
180
|
+
|
|
181
|
+
const ${genus}_species: ${genus}[] = [
|
|
182
|
+
${speciesCall}
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
// Export ${genus}DB.json
|
|
186
|
+
const jsonData = JSON.stringify(${genus}_species);
|
|
187
|
+
console.log(jsonData)
|
|
188
|
+
// import { writeFileSync } from 'fs'
|
|
189
|
+
// const jsonData = JSON.stringify(${genus}_species)
|
|
190
|
+
// const inputFilePath = '../output/${genus}DB.json'
|
|
191
|
+
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
192
192
|
// console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
193
193
|
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
194
194
|
const fileToTranspile = 'exportTemp';
|
package/dist/init.js
CHANGED
|
@@ -30,23 +30,23 @@ function createInputCSVFiles() {
|
|
|
30
30
|
if (!fs.existsSync(inputDir)) {
|
|
31
31
|
fs.mkdirSync(inputDir);
|
|
32
32
|
console.log('\x1b[36mℹ️ The', '\x1b[33m./input', '\x1b[36mdirectory has been created.\x1b[0m');
|
|
33
|
-
const taxaToExportContent = `Mimosa afranioi
|
|
34
|
-
Mimosa arenosa var arenosa
|
|
35
|
-
Mimosa aurivillus var calothamnos
|
|
36
|
-
Mimosa bimucronata
|
|
37
|
-
Mimosa blanchetii
|
|
38
|
-
Mimosa caesalpiniifolia
|
|
39
|
-
Mimosa campicola
|
|
40
|
-
Mimosa cordistipula
|
|
41
|
-
Mimosa cubatanensis
|
|
42
|
-
Mimosa debilis var debilis
|
|
43
|
-
Mimosa diplotricha var diplotricha
|
|
44
|
-
Mimosa dolens var dolens
|
|
45
|
-
Mimosa dryandroides var dryandroides
|
|
33
|
+
const taxaToExportContent = `Mimosa afranioi
|
|
34
|
+
Mimosa arenosa var arenosa
|
|
35
|
+
Mimosa aurivillus var calothamnos
|
|
36
|
+
Mimosa bimucronata
|
|
37
|
+
Mimosa blanchetii
|
|
38
|
+
Mimosa caesalpiniifolia
|
|
39
|
+
Mimosa campicola
|
|
40
|
+
Mimosa cordistipula
|
|
41
|
+
Mimosa cubatanensis
|
|
42
|
+
Mimosa debilis var debilis
|
|
43
|
+
Mimosa diplotricha var diplotricha
|
|
44
|
+
Mimosa dolens var dolens
|
|
45
|
+
Mimosa dryandroides var dryandroides
|
|
46
46
|
Mimosa elliptica`;
|
|
47
|
-
const importTaxaContent = `"specificEpithet";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.numberOfPairs.min";"leaf.bipinnate.pinnae.numberOfPairs.max";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.numberOfPairs.value";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.min";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.max";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.value";"inflorescence.spicate";"inflorescence.capitate";"flower.merism";"flower.calyx.shape";"flower.corolla.shape";"flower.numberWhorlsOfStamens";"androecium.filaments.colour";"descriptionAuthorship"
|
|
48
|
-
"arenosa var arenosa";"";"4";"12";"";"";"";"12";"30";"";"";"yes";"";"['4-merous', '5-merous']";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"
|
|
49
|
-
"artemisiana";"";"7";"12";"";"";"";"15";"29";"";"";"yes";"";"4-merous";"campanulate";"campanulate";"diplostemonous";"withish";"June Doe"
|
|
47
|
+
const importTaxaContent = `"specificEpithet";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.numberOfPairs.min";"leaf.bipinnate.pinnae.numberOfPairs.max";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.numberOfPairs.value";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.min";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.max";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.value";"inflorescence.spicate";"inflorescence.capitate";"flower.merism";"flower.calyx.shape";"flower.corolla.shape";"flower.numberWhorlsOfStamens";"androecium.filaments.colour";"descriptionAuthorship"
|
|
48
|
+
"arenosa var arenosa";"";"4";"12";"";"";"";"12";"30";"";"";"yes";"";"['4-merous', '5-merous']";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"
|
|
49
|
+
"artemisiana";"";"7";"12";"";"";"";"15";"29";"";"";"yes";"";"4-merous";"campanulate";"campanulate";"diplostemonous";"withish";"June Doe"
|
|
50
50
|
"ceratonia var pseudo-obovata";"";"2";"4";"5";"";"";"2";"4";"5";"";"";"yes";"3-merous";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"`;
|
|
51
51
|
const taxaToExportPath = path.join(inputDir, 'taxaToExport.csv');
|
|
52
52
|
const importTaxaPath = path.join(inputDir, 'importTaxa.csv');
|