Revision 54831
Added by Sandro La Bruzzo about 5 years ago
DOIBoostToActions.java | ||
---|---|---|
3 | 3 |
import com.google.gson.Gson; |
4 | 4 |
import com.google.gson.JsonElement; |
5 | 5 |
import com.google.gson.JsonObject; |
6 |
import com.googlecode.protobuf.format.JsonFormat; |
|
6 | 7 |
import eu.dnetlib.actionmanager.actions.ActionFactory; |
7 | 8 |
import eu.dnetlib.actionmanager.actions.AtomicAction; |
8 | 9 |
import eu.dnetlib.actionmanager.common.Agent; |
... | ... | |
42 | 43 |
public static final String SEPARATOR = "::"; |
43 | 44 |
|
44 | 45 |
private static Map<String, Pair<String, String>> datasources = new HashMap<String, Pair<String, String>>() {{ |
45 |
put(MAG, new Pair<>("Microsoft Academic Graph", OPENAIRE_PREFIX + SEPARATOR + "microsoft")); |
|
46 |
put(ORCID, new Pair<>(ORCID, OPENAIRE_PREFIX + SEPARATOR + "orcid")); |
|
47 |
put(CROSSREF, new Pair<>(CROSSREF, OPENAIRE_PREFIX + SEPARATOR + "crossref")); |
|
48 |
put(UNPAYWALL, new Pair<>(UNPAYWALL, OPENAIRE_PREFIX + SEPARATOR + "unpaywall")); |
|
46 |
put(MAG.toLowerCase(), new Pair<>("Microsoft Academic Graph", OPENAIRE_PREFIX + SEPARATOR + "microsoft"));
|
|
47 |
put(ORCID.toLowerCase(), new Pair<>(ORCID, OPENAIRE_PREFIX + SEPARATOR + "orcid"));
|
|
48 |
put(CROSSREF.toLowerCase(), new Pair<>(CROSSREF, OPENAIRE_PREFIX + SEPARATOR + "crossref"));
|
|
49 |
put(UNPAYWALL.toLowerCase(), new Pair<>(UNPAYWALL, OPENAIRE_PREFIX + SEPARATOR + "unpaywall"));
|
|
49 | 50 |
|
50 | 51 |
}}; |
51 | 52 |
|
... | ... | |
112 | 113 |
//creating Result Proto |
113 | 114 |
final OafProtos.OafEntity.Builder entity = OafProtos.OafEntity.newBuilder().setType(TypeProtos.Type.result); |
114 | 115 |
|
115 |
entity.setDateofcollection("2018-10-10");
|
|
116 |
entity.setDateofcollection("2019-02-15");
|
|
116 | 117 |
|
118 |
|
|
119 |
|
|
117 | 120 |
if (rootElement.has("collectedFrom") && rootElement.get("collectedFrom").isJsonArray()){ |
118 | 121 |
StreamUtils.toStream(rootElement.getAsJsonArray("collectedFrom").iterator()) |
119 | 122 |
.map(JsonElement::getAsString) |
120 | 123 |
.forEach(cf -> { |
121 |
final String id = datasources.get(cf).getValue(); |
|
122 |
final String name = datasources.get(cf).getKey(); |
|
124 |
final String id = datasources.get(cf.toLowerCase()).getValue();
|
|
125 |
final String name = datasources.get(cf.toLowerCase()).getKey();
|
|
123 | 126 |
if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(name)) { |
124 | 127 |
final FieldTypeProtos.KeyValue collectedFrom = FieldTypeProtos.KeyValue.newBuilder() |
125 | 128 |
.setValue(name) |
... | ... | |
134 | 137 |
final String doi = getStringValue(rootElement, "doi"); |
135 | 138 |
if (doi == null) |
136 | 139 |
return null; |
140 |
entity.addOriginalId(doi); |
|
137 | 141 |
final String sourceId = String.format("50|%s" + SEPARATOR + "%s", doiBoostNSPREFIX, AbstractDNetXsltFunctions.md5(doi)); |
138 | 142 |
entity.setId(sourceId); |
139 | 143 |
|
... | ... | |
196 | 200 |
.setSchemename("dnet:access_modes") |
197 | 201 |
.build()); |
198 | 202 |
|
199 |
final String id =datasources.get(it.get("provenance").getAsString()).getValue(); |
|
200 |
final String name =datasources.get(it.get("provenance").getAsString()).getKey(); |
|
203 |
final String id =datasources.get(it.get("provenance").getAsString().toLowerCase()).getValue();
|
|
204 |
final String name =datasources.get(it.get("provenance").getAsString().toLowerCase()).getKey();
|
|
201 | 205 |
if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(name)) { |
202 | 206 |
final FieldTypeProtos.KeyValue collectedFrom = FieldTypeProtos.KeyValue.newBuilder() |
203 | 207 |
.setValue(name) |
... | ... | |
212 | 216 |
|
213 | 217 |
//Adding DOI URL as Instance |
214 | 218 |
final String doiURL = getStringValue(rootElement, "doi-url"); |
219 |
JsonObject hostedByOpenAire = null; |
|
220 |
if (rootElement.has("hostedByOpenAire")) { |
|
221 |
hostedByOpenAire = rootElement.getAsJsonObject("hostedByOpenAire"); |
|
222 |
} |
|
223 |
|
|
215 | 224 |
if (StringUtils.isNotBlank(doiURL)) { |
216 | 225 |
|
217 | 226 |
|
227 |
|
|
228 |
|
|
218 | 229 |
final ResultProtos.Result.Instance.Builder instance = ResultProtos.Result.Instance.newBuilder(); |
219 | 230 |
instance.addUrl(doiURL); |
231 |
instance.setInstancetype(FieldTypeProtos.Qualifier.newBuilder() |
|
232 |
.setClassid(cobjValue) |
|
233 |
.setClassname(typeValue) |
|
234 |
.setSchemeid("dnet:publication_resource") |
|
235 |
.setSchemename("dnet:publication_resource") |
|
236 |
.build()); |
|
220 | 237 |
instance.setAccessright(FieldTypeProtos.Qualifier.newBuilder() |
221 | 238 |
.setClassid("CLOSED") |
222 | 239 |
.setClassname("Closed Access") |
... | ... | |
224 | 241 |
.setSchemename("dnet:access_modes") |
225 | 242 |
.build()); |
226 | 243 |
instance.setCollectedfrom(FieldTypeProtos.KeyValue.newBuilder() |
227 |
.setValue("CrossRef")
|
|
244 |
.setValue(CROSSREF)
|
|
228 | 245 |
.setKey("10|" + OPENAIRE_PREFIX + SEPARATOR + AbstractDNetXsltFunctions.md5("crossref")) |
229 | 246 |
.build()); |
247 |
|
|
248 |
if (hostedByOpenAire == null) |
|
249 |
instance.setHostedby(FieldTypeProtos.KeyValue.newBuilder() |
|
250 |
.setKey("10|" + OPENAIRE_PREFIX + SEPARATOR + "55045bd2a65019fd8e6741a755395c8c") |
|
251 |
.setValue("Unknown Repository") |
|
252 |
.build()); |
|
253 |
else{ |
|
254 |
instance.setHostedby(FieldTypeProtos.KeyValue.newBuilder() |
|
255 |
.setKey(AbstractDNetXsltFunctions.oafSplitId("datasource",hostedByOpenAire.get("id").getAsString())) |
|
256 |
.setValue(hostedByOpenAire.get("name").getAsString()) |
|
257 |
.build()); |
|
258 |
} |
|
259 |
|
|
230 | 260 |
result.addInstance(instance); |
231 | 261 |
} |
232 | 262 |
|
... | ... | |
306 | 336 |
result.setMetadata(metadata.build()); |
307 | 337 |
entity.setResult(result.build()); |
308 | 338 |
oaf.setEntity(entity.build()); |
339 |
|
|
340 |
//System.out.println(JsonFormat.printToString(oaf.build())); |
|
341 |
|
|
309 | 342 |
final List<AtomicAction> actionList = new ArrayList<>(); |
310 | 343 |
|
311 | 344 |
if (!onlyOrganization) |
... | ... | |
381 | 414 |
rel.setResultOrganization(rel_instance.build()); |
382 | 415 |
|
383 | 416 |
rel.addCollectedfrom(FieldTypeProtos.KeyValue.newBuilder() |
384 |
.setValue(datasources.get(MAG).getKey()) |
|
385 |
.setKey("10|" + OPENAIRE_PREFIX + SEPARATOR + AbstractDNetXsltFunctions.md5(StringUtils.substringAfter(datasources.get(MAG).getValue(), SEPARATOR))) |
|
417 |
.setValue(datasources.get(MAG.toLowerCase()).getKey())
|
|
418 |
.setKey("10|" + OPENAIRE_PREFIX + SEPARATOR + AbstractDNetXsltFunctions.md5(StringUtils.substringAfter(datasources.get(MAG.toLowerCase()).getValue(), SEPARATOR)))
|
|
386 | 419 |
.build()); |
387 | 420 |
|
388 | 421 |
|
... | ... | |
437 | 470 |
public static FieldTypeProtos.KeyValue extractIdentifier(final String value) { |
438 | 471 |
FieldTypeProtos.KeyValue.Builder pid = FieldTypeProtos.KeyValue.newBuilder(); |
439 | 472 |
if (StringUtils.contains(value, "orcid.org")){ |
440 |
return pid.setValue(value) |
|
473 |
return pid.setValue(value.replaceAll("https://orcid.org/",""))
|
|
441 | 474 |
.setKey(ORCID).build(); |
442 | 475 |
} |
443 | 476 |
if (StringUtils.contains(value, "academic.microsoft.com/#/detail")){ |
444 |
return pid.setValue(value) |
|
477 |
return pid.setValue(value.replaceAll("https://academic.microsoft.com/#/detail/",""))
|
|
445 | 478 |
.setKey("MAG Identifier").build(); |
446 | 479 |
} |
447 | 480 |
return pid.setValue(value) |
... | ... | |
467 | 500 |
OafProtos.OafEntity.Builder entity = OafProtos.OafEntity.newBuilder(); |
468 | 501 |
entity.setType(TypeProtos.Type.organization); |
469 | 502 |
entity.setId("20|microsoft___" + SEPARATOR +AbstractDNetXsltFunctions.md5(microsoftID)); |
470 |
final String id =datasources.get(affiliation.get("provenance").getAsString()).getValue(); |
|
471 |
final String name =datasources.get(affiliation.get("provenance").getAsString()).getKey(); |
|
503 |
final String id =datasources.get(affiliation.get("provenance").getAsString().toLowerCase()).getValue();
|
|
504 |
final String name =datasources.get(affiliation.get("provenance").getAsString().toLowerCase()).getKey();
|
|
472 | 505 |
if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(name)) { |
473 | 506 |
final FieldTypeProtos.KeyValue collectedFrom = FieldTypeProtos.KeyValue.newBuilder() |
474 | 507 |
.setValue(name) |
... | ... | |
512 | 545 |
|
513 | 546 |
List<JsonObject> authors = getArrayObjects(root, "authors"); |
514 | 547 |
|
515 |
final AtomicInteger counter = new AtomicInteger(); |
|
548 |
final AtomicInteger counter = new AtomicInteger(1);
|
|
516 | 549 |
|
550 |
|
|
517 | 551 |
List<FieldTypeProtos.Author> collect = authors.stream().map(author -> { |
518 | 552 |
final String given = getStringValue(author, "given"); |
519 | 553 |
final String family = getStringValue(author, "family"); |
Also available in: Unified diff
fixed DOIBoost Bug