1 | /**
|
2 | * Take `Object` containing flatten hits from ISTEXResult.
|
3 | *
|
4 | * @see ISTEXResult
|
5 | * @see OBJFlatten (from ezs-basics)
|
6 | *
|
7 | * @example
|
8 | *
|
9 | * data: {
|
10 | * 'author/0/name': 'Geoffrey Strickland',
|
11 | * 'author/0/affiliations/0': 'University of Reading',
|
12 | * 'host/issn/0': '0047-2441',
|
13 | * 'host/eissn/0': '1740-2379',
|
14 | * 'title': 'Maupassant, Zola, Jules Vallès and the Paris Commune of 1871',
|
15 | * 'publicationDate': '1983',
|
16 | * 'doi/0': '10.1177/004724418301305203',
|
17 | * 'id': 'F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483',
|
18 | * 'score': 1 }
|
19 | *
|
20 | * @example
|
21 | *
|
22 | * .pipe(ezs('ISTEXTriplify', {
|
23 | * property: [
|
24 | * 'doi/0 -> http://purl.org/ontology/bibo/doi',
|
25 | * 'language -> http://purl.org/dc/terms/language',
|
26 | * 'author/\\d+/name -> http://purl.org/dc/terms/creator',
|
27 | * 'author/\\d+/affiliations -> https://data.istex.fr/ontology/istex#affiliation',
|
28 | * ],
|
29 | * ));
|
30 | *
|
31 | * @example
|
32 | *
|
33 | * <https://data.istex.fr/document/F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483>
|
34 | * a <http://purl.org/ontology/bibo/Document> ;
|
35 | * "10.1002/zaac.19936190205" ;
|
36 | * <https://data.istex.fr/ontology/istex#idIstex> "F6CB7249E90BD96D5F7E3C4E80CC1C3FEE4FF483" ;
|
37 | * <http://purl.org/dc/terms/creator> "Geoffrey Strickland" ;
|
38 | * <https://data.istex.fr/ontology/istex#affiliation> "University of Reading" ;
|
39 | *
|
40 | * @param {Object} [property=[]] path to uri for the properties to output (property and uri separated by ` -> `)
|
41 | * @param {string} [source=""] the root of the keys (ex: `istex/`)
|
42 | * @returns {string}
|
43 | */
|
44 | function ISTEXTriplify(data, feed) {
|
45 | if (this.isLast()) {
|
46 | return feed.close();
|
47 | }
|
48 | const source = this.getParam('source', '');
|
49 | const property = this.getParam('property', []);
|
50 | const properties = property
|
51 | .map(prop => prop.split(' -> '));
|
52 | const regexps = properties
|
53 | .map(([path, prop]) => ([
|
54 | new RegExp(path),
|
55 | prop,
|
56 | ]));
|
57 | feed.write(`<https://api.istex.fr/${data[`${source}arkIstex`]}> <https://data.istex.fr/ontology/istex#idIstex> "${data[`${source}id`]}" .\n`);
|
58 | feed.write(`<https://api.istex.fr/${data[`${source}arkIstex`]}> a <http://purl.org/ontology/bibo/Document> .\n`);
|
59 |
|
60 | const dataArray = Object.entries(data);
|
61 |
|
62 | regexps.forEach(([regex, prop]) => {
|
63 | dataArray
|
64 | .filter(([key]) => key.match(regex))
|
65 | .forEach(([, value]) => {
|
66 | if (!value) return;
|
67 | if (value.startsWith('http')) {
|
68 | feed.write(`<https://api.istex.fr/${data[`${source}arkIstex`]}> <${prop}> <${value}> .\n`);
|
69 | } else {
|
70 | feed.write(`<https://api.istex.fr/${data[`${source}arkIstex`]}> <${prop}> "${value}" .\n`);
|
71 | }
|
72 | });
|
73 | });
|
74 |
|
75 | feed.end();
|
76 | }
|
77 |
|
78 | export default {
|
79 | ISTEXTriplify,
|
80 | };
|