-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork.rs
More file actions
208 lines (186 loc) · 5.4 KB
/
Copy pathwork.rs
File metadata and controls
208 lines (186 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::{
api_entities::{
common_types::{DehydratedAuthor, DehydratedInstitution, DehydratedSource, Field, Meta},
APIEntity,
},
impl_try_from_for_entity_response, impl_try_from_for_single_entity,
utils::{deserialize_null_default, deserialize_opt_string_from_uint_null_missing},
};
#[derive(Deserialize, Serialize, Debug)]
pub struct WorkIds {
pub openalex: String,
pub doi: Option<String>,
#[serde(
default,
deserialize_with = "deserialize_opt_string_from_uint_null_missing"
)]
pub mag: Option<String>,
pub pmid: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Location {
#[serde(default)]
pub is_accepted: bool,
pub is_oa: bool,
#[serde(default)]
pub is_published: bool,
pub landing_page_url: Option<String>,
pub license: Option<String>,
pub source: Option<DehydratedSource>,
pub pdf_url: Option<String>,
pub version: Option<String>,
pub license_id: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct OpenAccess {
pub is_oa: bool,
pub oa_status: String,
pub oa_url: Option<String>,
pub any_repository_has_fulltext: bool,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Authorship {
pub author_position: String,
pub author: DehydratedAuthor,
pub institutions: Vec<DehydratedInstitution>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct APC {
pub value: u32,
pub currency: String,
pub value_usd: Option<u32>,
pub provenance: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Biblio {
pub volume: Option<String>,
pub issue: Option<String>,
pub first_page: Option<String>,
pub last_page: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct WorkTopic {
pub id: String,
pub display_name: String,
pub score: f32,
pub subfield: Field,
pub field: Field,
pub domain: Field,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Keyword {
pub id: String,
pub display_name: String,
pub score: f32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Concept {
pub id: String,
pub wikidata: String,
pub display_name: String,
pub level: u32,
pub score: f32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct YearCount {
pub year: u32,
pub cited_by_count: u32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct MeshTag {
pub descriptor_ui: String,
pub descriptor_name: String,
pub qualifier_ui: String,
pub qualifier_name: Option<String>,
pub is_major_topic: bool,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Grant {
pub funder: String,
pub funder_display_name: String,
pub award_id: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct CitedByPercentileYear {
pub min: u32,
pub max: u32,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Work {
#[serde(deserialize_with = "deserialize_null_default")]
pub abstract_inverted_index: HashMap<String, Vec<u32>>,
pub authorships: Vec<Authorship>,
pub apc_list: Option<APC>,
pub apc_paid: Option<APC>,
pub best_oa_location: Option<Location>,
pub biblio: Biblio,
pub cited_by_api_url: String,
pub cited_by_count: u32,
pub concepts: Vec<Concept>,
pub corresponding_author_ids: Vec<String>,
pub corresponding_institution_ids: Vec<String>,
pub countries_distinct_count: u32,
pub counts_by_year: Vec<YearCount>,
pub created_date: String,
pub display_name: Option<String>,
pub doi: Option<String>,
pub fulltext_origin: Option<String>,
pub grants: Vec<Grant>,
pub has_fulltext: bool,
pub id: String,
pub ids: WorkIds,
pub indexed_in: Vec<String>,
pub institutions_distinct_count: u32,
pub is_paratext: bool,
pub is_retracted: bool,
pub keywords: Vec<Keyword>,
pub language: Option<String>,
pub license: Option<String>,
pub locations: Vec<Location>,
pub locations_count: u32,
pub mesh: Vec<MeshTag>,
pub ngrams_url: Option<String>,
pub open_access: OpenAccess,
pub primary_location: Option<Location>,
pub primary_topic: Option<WorkTopic>,
pub publication_date: String,
pub publication_year: u32,
pub referenced_works: Vec<String>,
pub related_works: Vec<String>,
pub sustainable_development_goals: Vec<Keyword>,
pub topics: Vec<WorkTopic>,
pub title: Option<String>,
#[serde(rename = "type")]
pub work_type: String,
pub type_crossref: String,
pub updated_date: String,
pub cited_by_percentile_year: CitedByPercentileYear,
pub fwci: Option<f32>,
pub referenced_works_count: u32,
}
impl Work {
pub fn get_abstract(&self) -> String {
let mut res: Vec<&str> = vec![];
for (s, positions) in self.abstract_inverted_index.iter() {
for pos in positions {
while res.len() <= (*pos as usize) {
res.push("");
}
res[*pos as usize] = s;
}
}
res.join(" ")
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct WorkResponse {
pub meta: Meta,
pub results: Vec<Work>,
}
impl_try_from_for_single_entity!(Work);
impl_try_from_for_entity_response!(WorkResponse);
impl APIEntity<Work, WorkResponse> for Work {
const API_URL: &'static str = "https://api.openalex.org/works";
}