2024-02-07 15:33:12 +01:00
|
|
|
|
2024-02-27 12:35:34 +01:00
|
|
|
package eu.dnetlib.dhp.oa.graph.dump.skgif;
|
2024-02-07 15:33:12 +01:00
|
|
|
|
|
|
|
import java.io.Serializable;
|
2024-02-27 12:35:34 +01:00
|
|
|
import java.util.*;
|
2024-02-07 15:33:12 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2024-02-27 12:35:34 +01:00
|
|
|
import eu.dnetlib.dhp.oa.graph.dump.skgif.exception.NoAllowedTypeException;
|
|
|
|
import eu.dnetlib.dhp.oa.graph.dump.skgif.exception.NoTitleFoundException;
|
2024-03-01 09:35:15 +01:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.*;
|
2023-09-18 08:59:02 +02:00
|
|
|
import eu.dnetlib.dhp.skgif.model.*;
|
|
|
|
import scala.Tuple2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author miriam.baglioni
|
|
|
|
* @Date 01/09/23
|
|
|
|
*/
|
|
|
|
public class ResultMapper implements Serializable {
|
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
public static <E extends Result> ResearchProduct map(
|
|
|
|
E input)
|
|
|
|
throws Exception {
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
ResearchProduct out = new ResearchProduct();
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
Optional<Qualifier> ort = Optional.ofNullable(input.getResulttype());
|
|
|
|
if (ort.isPresent()) {
|
|
|
|
try {
|
2024-03-12 14:58:42 +01:00
|
|
|
// out.setLocal_identifier(Utils.getIdentifier(Prefixes.RESEARCH_PRODUCT, input.getId()));
|
2024-03-12 14:51:14 +01:00
|
|
|
out.setLocal_identifier(input.getId());
|
2024-02-07 15:33:12 +01:00
|
|
|
mapPid(out, input);
|
|
|
|
mapTitle(out, input);
|
|
|
|
mapAbstract(out, input);
|
|
|
|
mapType(out, input);
|
|
|
|
mapTopic(out, input);
|
|
|
|
mapContribution(out, input);
|
2024-04-05 12:59:41 +02:00
|
|
|
mapMeasure(out, input);
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-20 09:57:33 +01:00
|
|
|
//The manifestation will be included extending the result as well as the relations to funder, organization and other results
|
2024-02-27 12:35:34 +01:00
|
|
|
return out;
|
2024-02-07 15:33:12 +01:00
|
|
|
} catch (ClassCastException cce) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-04-05 12:59:41 +02:00
|
|
|
private static void mapMeasure(ResearchProduct out, eu.dnetlib.dhp.schema.oaf.Result input) {
|
|
|
|
if (Optional.ofNullable(input.getMeasures()).isPresent()) {
|
|
|
|
Indicator i = new Indicator();
|
|
|
|
DownloadsAndViews uc = new DownloadsAndViews();
|
|
|
|
input.getMeasures().forEach(m -> {
|
|
|
|
if (m.getId().equals("downloads")) {
|
|
|
|
uc.setDownloads(m.getUnit().get(0).getValue());
|
|
|
|
}
|
|
|
|
if (m.getId().equals("views")) {
|
|
|
|
uc.setViews(m.getUnit().get(0).getValue());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!uc.isEmpty()) {
|
|
|
|
i.setDownloadsAndViews(uc);
|
|
|
|
out.setIndicator(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static <E extends Result> void mapContribution(ResearchProduct out, E input) {
|
|
|
|
if (Optional.ofNullable(input.getAuthor()).isPresent()) {
|
|
|
|
int count = 0;
|
2024-02-27 12:35:34 +01:00
|
|
|
List<Contribution> contributionList = new ArrayList<>();
|
2024-02-07 15:33:12 +01:00
|
|
|
for (Author a : input.getAuthor()) {
|
|
|
|
count += 1;
|
|
|
|
Contribution contribution = new Contribution();
|
2024-03-01 09:35:15 +01:00
|
|
|
Tuple2<String, Boolean> orcid = Utils.getOrcid(a.getPid());
|
2024-03-04 16:28:52 +01:00
|
|
|
MinPerson minPerson = new MinPerson();
|
|
|
|
minPerson.setFull_name(a.getFullname());
|
2024-03-01 09:35:15 +01:00
|
|
|
if (orcid != null) {
|
2024-03-04 16:28:52 +01:00
|
|
|
minPerson.setLocal_identifier(Utils.getIdentifier(Prefixes.PERSON, orcid._1() + orcid._2()));
|
|
|
|
minPerson.setOrcid(orcid._1());
|
|
|
|
contribution.setPerson(minPerson);
|
2024-03-01 09:35:15 +01:00
|
|
|
} else {
|
|
|
|
if (Optional.ofNullable(a.getRank()).isPresent()) {
|
2024-03-11 09:56:40 +01:00
|
|
|
minPerson
|
|
|
|
.setLocal_identifier(
|
|
|
|
Utils.getIdentifier(Prefixes.TEMPORARY_PERSON, input.getId() + a.getRank()));
|
2024-03-01 09:35:15 +01:00
|
|
|
contribution
|
2024-03-04 16:28:52 +01:00
|
|
|
.setPerson(minPerson);
|
2024-02-07 15:33:12 +01:00
|
|
|
} else {
|
2024-03-11 09:56:40 +01:00
|
|
|
minPerson
|
|
|
|
.setLocal_identifier(Utils.getIdentifier(Prefixes.TEMPORARY_PERSON, input.getId() + count));
|
2024-03-04 16:28:52 +01:00
|
|
|
contribution.setPerson(minPerson);
|
2024-02-27 12:35:34 +01:00
|
|
|
}
|
2024-03-01 09:35:15 +01:00
|
|
|
}
|
|
|
|
if (Optional.ofNullable(a.getRank()).isPresent()) {
|
|
|
|
contribution.setRank(a.getRank());
|
|
|
|
}
|
|
|
|
|
2024-02-27 12:35:34 +01:00
|
|
|
contributionList.add(contribution);
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2024-02-27 12:35:34 +01:00
|
|
|
out.setContributions(contributionList);
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static <E extends Result> void mapTopic(ResearchProduct out, E input) {
|
|
|
|
if (Optional.ofNullable(input.getSubject()).isPresent()) {
|
2024-02-20 09:57:33 +01:00
|
|
|
out
|
|
|
|
.setTopics(
|
|
|
|
input
|
|
|
|
.getSubject()
|
|
|
|
.stream()
|
2024-03-01 09:35:15 +01:00
|
|
|
.filter(
|
2024-04-05 12:59:41 +02:00
|
|
|
s -> s.getQualifier().getClassid().equalsIgnoreCase("fos")
|
|
|
|
||
|
|
|
|
s.getQualifier().getClassid().equalsIgnoreCase("sdg")
|
|
|
|
|| s.getQualifier().getClassid().equalsIgnoreCase("keyword"))
|
2024-02-20 09:57:33 +01:00
|
|
|
.map(s -> {
|
|
|
|
ResultTopic topic = new ResultTopic();
|
2024-03-04 16:28:52 +01:00
|
|
|
MinTopic minTopic = new MinTopic();
|
2024-03-11 09:56:40 +01:00
|
|
|
minTopic
|
|
|
|
.setLocal_identifier(
|
|
|
|
Utils.getIdentifier(Prefixes.TOPIC, s.getQualifier().getClassid() + s.getValue()));
|
2024-03-04 16:28:52 +01:00
|
|
|
minTopic.setValue(s.getValue());
|
2024-04-05 12:59:41 +02:00
|
|
|
minTopic.setScheme(s.getQualifier().getClassid());
|
2024-03-01 09:35:15 +01:00
|
|
|
topic
|
2024-03-11 09:56:40 +01:00
|
|
|
.setTopic(minTopic);
|
2024-03-01 09:35:15 +01:00
|
|
|
if (Optional.ofNullable(s.getDataInfo()).isPresent()) {
|
2024-02-27 12:35:34 +01:00
|
|
|
Provenance provenance = new Provenance();
|
2024-03-11 09:56:40 +01:00
|
|
|
try {
|
|
|
|
provenance.setTrust(Double.valueOf(s.getDataInfo().getTrust()));
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
|
|
|
|
}
|
2024-04-05 12:59:41 +02:00
|
|
|
provenance.setType(s.getDataInfo().getProvenanceaction().getClassname());
|
2024-02-27 12:35:34 +01:00
|
|
|
topic.setProvenance(provenance);
|
|
|
|
}
|
|
|
|
|
2024-02-20 09:57:33 +01:00
|
|
|
return topic;
|
|
|
|
})
|
|
|
|
.collect(Collectors.toList()));
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static <E extends Result> void mapType(ResearchProduct out, E input) throws NoAllowedTypeException {
|
|
|
|
switch (input.getResulttype().getClassid()) {
|
|
|
|
case "publication":
|
2024-02-27 12:35:34 +01:00
|
|
|
out.setProduct_type(ResearchTypes.LITERATURE.label);
|
2024-02-07 15:33:12 +01:00
|
|
|
break;
|
|
|
|
case "dataset":
|
2024-02-27 12:35:34 +01:00
|
|
|
out.setProduct_type(ResearchTypes.RESEARCH_DATA.label);
|
2024-02-07 15:33:12 +01:00
|
|
|
break;
|
|
|
|
case "software":
|
2024-02-27 12:35:34 +01:00
|
|
|
out.setProduct_type(ResearchTypes.RESEARCH_SOFTWARE.label);
|
2024-02-07 15:33:12 +01:00
|
|
|
break;
|
|
|
|
case "other":
|
2024-02-27 12:35:34 +01:00
|
|
|
out.setProduct_type(ResearchTypes.OTHER.label);
|
2024-02-07 15:33:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ClassCastException("Result type not present or not allowed");
|
|
|
|
}
|
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static void mapPid(ResearchProduct out, Result input) {
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getPid())
|
|
|
|
.ifPresent(
|
|
|
|
value -> out
|
|
|
|
.setIdentifiers(
|
|
|
|
value
|
|
|
|
.stream()
|
|
|
|
.map(
|
|
|
|
p -> {
|
|
|
|
Identifier identifier = new Identifier();
|
|
|
|
identifier.setValue(p.getValue());
|
2024-02-27 12:35:34 +01:00
|
|
|
identifier.setScheme(p.getQualifier().getClassid());
|
2024-02-07 15:33:12 +01:00
|
|
|
return identifier;
|
|
|
|
})
|
|
|
|
.collect(Collectors.toList())));
|
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static void mapTitle(ResearchProduct out, Result input) throws NoTitleFoundException {
|
|
|
|
Optional<List<StructuredProperty>> otitle = Optional.ofNullable(input.getTitle());
|
|
|
|
if (otitle.isPresent()) {
|
|
|
|
List<StructuredProperty> iTitle = otitle
|
|
|
|
.get()
|
|
|
|
.stream()
|
|
|
|
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("main title"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (!iTitle.isEmpty()) {
|
2024-03-01 09:35:15 +01:00
|
|
|
out.setTitles(Collections.singletonMap("none", Arrays.asList(iTitle.get(0).getValue())));
|
2024-02-07 15:33:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
iTitle = otitle
|
|
|
|
.get()
|
|
|
|
.stream()
|
|
|
|
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("subtitle"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (!iTitle.isEmpty()) {
|
2024-03-01 09:35:15 +01:00
|
|
|
out.setTitles(Collections.singletonMap("none", Arrays.asList(iTitle.get(0).getValue())));
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
|
2024-02-07 15:33:12 +01:00
|
|
|
private static void mapAbstract(ResearchProduct out, Result input) {
|
|
|
|
final List<String> descriptionList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getDescription())
|
|
|
|
.ifPresent(value -> value.forEach(d -> descriptionList.add(d.getValue())));
|
2024-03-01 09:35:15 +01:00
|
|
|
out.setAbstracts(Collections.singletonMap("none", descriptionList));
|
2024-02-07 15:33:12 +01:00
|
|
|
}
|
2023-09-18 08:59:02 +02:00
|
|
|
}
|