1 |
43443
|
claudio.at
|
package eu.dnetlib.data.mapreduce.hbase.broker;
|
2 |
|
|
|
3 |
52765
|
michele.ar
|
import static eu.dnetlib.data.mapreduce.hbase.broker.mapping.EventFactory.asEvent;
|
4 |
|
|
|
5 |
43443
|
claudio.at
|
import java.io.IOException;
|
6 |
|
|
import java.util.List;
|
7 |
52765
|
michele.ar
|
import java.util.stream.Collectors;
|
8 |
43443
|
claudio.at
|
|
9 |
52765
|
michele.ar
|
import org.apache.commons.lang.StringUtils;
|
10 |
|
|
import org.dom4j.DocumentException;
|
11 |
|
|
|
12 |
49832
|
claudio.at
|
import com.google.common.collect.Lists;
|
13 |
52765
|
michele.ar
|
|
14 |
43558
|
claudio.at
|
import eu.dnetlib.broker.objects.OpenAireEventPayload;
|
15 |
43443
|
claudio.at
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory;
|
16 |
|
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory;
|
17 |
49832
|
claudio.at
|
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper;
|
18 |
43443
|
claudio.at
|
import eu.dnetlib.data.proto.FieldTypeProtos.StringField;
|
19 |
|
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Created by claudio on 26/07/16.
|
23 |
|
|
*/
|
24 |
52765
|
michele.ar
|
public class AbstractEventFactory { // Abstract of the publication
|
25 |
43443
|
claudio.at
|
|
26 |
49832
|
claudio.at
|
public static List<EventWrapper> process(final Oaf current, final Oaf other, final float trust)
|
27 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
28 |
49832
|
claudio.at
|
return new AbstractEventFactory().processAbstract(current, other, trust);
|
29 |
43443
|
claudio.at
|
}
|
30 |
|
|
|
31 |
49832
|
claudio.at
|
private List<EventWrapper> processAbstract(final Oaf current, final Oaf other, final float trust)
|
32 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
33 |
49832
|
claudio.at
|
|
34 |
|
|
final List<EventWrapper> events = Lists.newArrayList();
|
35 |
|
|
|
36 |
43443
|
claudio.at
|
if (hasAbstract(other)) {
|
37 |
44085
|
michele.ar
|
// doProcessAbstract(context, current, other, Topic.MORE_ABSTRACT);
|
38 |
43443
|
claudio.at
|
|
39 |
|
|
if (!hasAbstract(current)) {
|
40 |
49832
|
claudio.at
|
events.add(doProcessAbstract(current, other, Topic.ENRICH_MISSING_ABSTRACT, trust));
|
41 |
43443
|
claudio.at
|
}
|
42 |
49832
|
claudio.at
|
}
|
43 |
44085
|
michele.ar
|
|
44 |
49832
|
claudio.at
|
return events;
|
45 |
43443
|
claudio.at
|
}
|
46 |
|
|
|
47 |
49832
|
claudio.at
|
private EventWrapper doProcessAbstract(final Oaf current, final Oaf other, final Topic topic, final float trust)
|
48 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
49 |
43443
|
claudio.at
|
final Oaf.Builder prototype = Oaf.newBuilder(current);
|
50 |
|
|
final List<StringField> descriptionList = other.getEntity().getResult().getMetadata().getDescriptionList();
|
51 |
|
|
prototype.getEntityBuilder().getResultBuilder().getMetadataBuilder().addAllDescription(descriptionList);
|
52 |
|
|
|
53 |
|
|
final Oaf oaf = prototype.build();
|
54 |
|
|
|
55 |
44085
|
michele.ar
|
final OpenAireEventPayload payload =
|
56 |
|
|
HighlightFactory.highlightEnrichAbstract(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), descriptionList);
|
57 |
43443
|
claudio.at
|
|
58 |
49832
|
claudio.at
|
return EventWrapper.newInstance(
|
59 |
|
|
asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust),
|
60 |
52765
|
michele.ar
|
payload.getHighlight().getAbstracts().stream().filter(StringUtils::isNotBlank).sorted().collect(Collectors.joining(", ")),
|
61 |
49832
|
claudio.at
|
topic.getValue());
|
62 |
43443
|
claudio.at
|
}
|
63 |
|
|
|
64 |
|
|
private boolean hasAbstract(final Oaf oaf) {
|
65 |
49832
|
claudio.at
|
return oaf.getEntity().getResult().getMetadata().getDescriptionList()
|
66 |
|
|
.stream()
|
67 |
|
|
.anyMatch(s -> StringUtils.isNotBlank(s.getValue()));
|
68 |
43443
|
claudio.at
|
}
|
69 |
|
|
|
70 |
|
|
}
|