|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PubPeerFoundation\PublicationDataExtractor; |
|
4
|
|
|
|
|
5
|
|
|
use Volan\Volan; |
|
6
|
|
|
use Volan\ValidatorResult; |
|
7
|
|
|
|
|
8
|
|
|
class Schema |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Array validation schema. |
|
12
|
|
|
*/ |
|
13
|
|
|
const SCHEMA = [ |
|
14
|
|
|
'root' => [ |
|
15
|
|
|
'_source' => [ |
|
16
|
|
|
'_type' => 'string', |
|
17
|
|
|
], |
|
18
|
|
|
'authors' => [ |
|
19
|
|
|
'_type' => 'nested_array', |
|
20
|
|
|
'first_name' => [ |
|
21
|
|
|
'_type' => 'string', |
|
22
|
|
|
], |
|
23
|
|
|
'last_name' => [ |
|
24
|
|
|
'_type' => 'required_string', |
|
25
|
|
|
], |
|
26
|
|
|
'orcid' => [ |
|
27
|
|
|
'_type' => 'string', |
|
28
|
|
|
], |
|
29
|
|
|
'email' => [ |
|
30
|
|
|
'_type' => 'string', |
|
31
|
|
|
], |
|
32
|
|
|
'affiliation' => [ |
|
33
|
|
|
'_type' => 'array', |
|
34
|
|
|
'name' => [ |
|
35
|
|
|
'_type' => 'string', |
|
36
|
|
|
], |
|
37
|
|
|
], |
|
38
|
|
|
], |
|
39
|
|
|
'identifiers' => [ |
|
40
|
|
|
'_type' => 'nested_array', |
|
41
|
|
|
'value' => [ |
|
42
|
|
|
'_type' => 'required_string', |
|
43
|
|
|
], |
|
44
|
|
|
'type' => [ |
|
45
|
|
|
'_type' => 'required_string', |
|
46
|
|
|
], |
|
47
|
|
|
], |
|
48
|
|
|
'journal' => [ |
|
49
|
|
|
'_type' => 'required_array', |
|
50
|
|
|
'title' => [ |
|
51
|
|
|
'_type' => 'string', |
|
52
|
|
|
], |
|
53
|
|
|
'issn' => [ |
|
54
|
|
|
'_type' => 'array', |
|
55
|
|
|
], |
|
56
|
|
|
'publisher' => [ |
|
57
|
|
|
'_type' => 'string', |
|
58
|
|
|
], |
|
59
|
|
|
], |
|
60
|
|
|
'publication' => [ |
|
61
|
|
|
'_type' => 'required_array', |
|
62
|
|
|
'title' => [ |
|
63
|
|
|
'_type' => 'required_string', |
|
64
|
|
|
], |
|
65
|
|
|
'abstract' => [ |
|
66
|
|
|
'_type' => 'string', |
|
67
|
|
|
], |
|
68
|
|
|
'url' => [ |
|
69
|
|
|
'_type' => 'required_string', |
|
70
|
|
|
], |
|
71
|
|
|
'published_at' => [ |
|
72
|
|
|
'_type' => 'string', |
|
73
|
|
|
], |
|
74
|
|
|
], |
|
75
|
|
|
'types' => [ |
|
76
|
|
|
'_type' => 'nested_array', |
|
77
|
|
|
'name' => [ |
|
78
|
|
|
'_type' => 'string', |
|
79
|
|
|
], |
|
80
|
|
|
], |
|
81
|
|
|
'tags' => [ |
|
82
|
|
|
'_type' => 'nested_array', |
|
83
|
|
|
'name' => [ |
|
84
|
|
|
'_type' => 'string', |
|
85
|
|
|
], |
|
86
|
|
|
], |
|
87
|
|
|
'affiliations' => [ |
|
88
|
|
|
'_type' => 'nested_array', |
|
89
|
|
|
'name' => [ |
|
90
|
|
|
'_type' => 'string', |
|
91
|
|
|
], |
|
92
|
|
|
], |
|
93
|
|
|
'updates' => [ |
|
94
|
|
|
'_type' => 'array', |
|
95
|
|
|
'timestamp' => [ |
|
96
|
|
|
'_type' => 'string', |
|
97
|
|
|
], |
|
98
|
|
|
'identifier' => [ |
|
99
|
|
|
'_type' => 'array', |
|
100
|
|
|
'doi' => [ |
|
101
|
|
|
'_type' => 'string', |
|
102
|
|
|
], |
|
103
|
|
|
], |
|
104
|
|
|
'type' => [ |
|
105
|
|
|
'_type' => 'string', |
|
106
|
|
|
], |
|
107
|
|
|
], |
|
108
|
|
|
], |
|
109
|
|
|
]; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Validate the data against Schema. |
|
113
|
|
|
* |
|
114
|
|
|
* @param $data |
|
115
|
|
|
* @return \Volan\ValidatorResult |
|
116
|
|
|
*/ |
|
117
|
|
|
public static function validate($data): ValidatorResult |
|
118
|
|
|
{ |
|
119
|
|
|
$validator = new Volan(static::SCHEMA); |
|
120
|
|
|
$result = $validator->validate($data); |
|
121
|
|
|
|
|
122
|
|
|
return $result; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get the main data types from Schema. |
|
127
|
|
|
* |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
|
|
public static function getDataTypes(): array |
|
131
|
|
|
{ |
|
132
|
|
|
return array_slice(array_keys(self::SCHEMA['root']), 1); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|