UNPKG

3.6 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
8
9var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13/**
14 * Take `Object` containing flatten hits from ISTEXResult.
15 *
16 * @see ISTEXResult
17 * @see OBJFlatten (from ezs-basics)
18 *
19 * @example
20 *
21 * data: {
22 * 'author/0/name': 'Geoffrey Strickland',
23 * 'author/0/affiliations/0': 'University of Reading',
24 * 'host/issn/0': '0047-2441',
25 * 'host/eissn/0': '1740-2379',
26 * 'title': 'Maupassant, Zola, Jules Vallès and the Paris Commune of 1871',
27 * 'publicationDate': '1983',
28 * 'doi/0': '10.1177/004724418301305203',
29 * 'id': 'F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483',
30 * 'score': 1 }
31 *
32 * @example
33 *
34 * .pipe(ezs('ISTEXTriplify', {
35 * property: [
36 * 'doi/0 -> http://purl.org/ontology/bibo/doi',
37 * 'language -> http://purl.org/dc/terms/language',
38 * 'author/\\d+/name -> http://purl.org/dc/terms/creator',
39 * 'author/\\d+/affiliations -> https://data.istex.fr/ontology/istex#affiliation',
40 * ],
41 * ));
42 *
43 * @example
44 *
45 * <https://data.istex.fr/document/F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483>
46 * a <http://purl.org/ontology/bibo/Document> ;
47 * "10.1002/zaac.19936190205" ;
48 * <https://data.istex.fr/ontology/istex#idIstex> "F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483" ;
49 * <http://purl.org/dc/terms/creator> "Geoffrey Strickland" ;
50 * <https://data.istex.fr/ontology/istex#affiliation> "University of Reading" ;
51 *
52 * @param {Object} [property=[]] path to uri for the properties to output (property and uri separated by ` -> `)
53 * @param {string} [source=""] the root of the keys (ex: `istex/`)
54 * @returns {string}
55 */
56function ISTEXTriplify(data, feed) {
57 if (this.isLast()) {
58 return feed.close();
59 }
60 var source = this.getParam('source', '');
61 var property = this.getParam('property', []);
62 var properties = property.map(function (prop) {
63 return prop.split(' -> ');
64 });
65 var regexps = properties.map(function (_ref) {
66 var _ref2 = (0, _slicedToArray3.default)(_ref, 2),
67 path = _ref2[0],
68 prop = _ref2[1];
69
70 return [new RegExp(path), prop];
71 });
72 feed.write('<https://api.istex.fr/' + data[source + 'arkIstex'] + '> <https://data.istex.fr/ontology/istex#idIstex> "' + data[source + 'id'] + '" .\n');
73 feed.write('<https://api.istex.fr/' + data[source + 'arkIstex'] + '> a <http://purl.org/ontology/bibo/Document> .\n');
74
75 var dataArray = Object.entries(data);
76
77 regexps.forEach(function (_ref3) {
78 var _ref4 = (0, _slicedToArray3.default)(_ref3, 2),
79 regex = _ref4[0],
80 prop = _ref4[1];
81
82 dataArray.filter(function (_ref5) {
83 var _ref6 = (0, _slicedToArray3.default)(_ref5, 1),
84 key = _ref6[0];
85
86 return key.match(regex);
87 }).forEach(function (_ref7) {
88 var _ref8 = (0, _slicedToArray3.default)(_ref7, 2),
89 value = _ref8[1];
90
91 if (!value) return;
92 if (value.startsWith('http')) {
93 feed.write('<https://api.istex.fr/' + data[source + 'arkIstex'] + '> <' + prop + '> <' + value + '> .\n');
94 } else {
95 feed.write('<https://api.istex.fr/' + data[source + 'arkIstex'] + '> <' + prop + '> "' + value + '" .\n');
96 }
97 });
98 });
99
100 feed.end();
101}
102
103exports.default = {
104 ISTEXTriplify: ISTEXTriplify
105};
\No newline at end of file