1
|
package eu.dnetlib.resolver.parser;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Arrays;
|
5
|
import java.util.List;
|
6
|
|
7
|
import com.ximpleware.AutoPilot;
|
8
|
import com.ximpleware.VTDGen;
|
9
|
import com.ximpleware.VTDNav;
|
10
|
import eu.dnetlib.data.transform.VtdUtilityParser;
|
11
|
import eu.dnetlib.dli.resolver.model.*;
|
12
|
|
13
|
import eu.dnetlib.pid.resolver.model.ObjectProvenance;
|
14
|
import eu.dnetlib.pid.resolver.model.ObjectRelation;
|
15
|
import eu.dnetlib.pid.resolver.model.ObjectType;
|
16
|
import eu.dnetlib.pid.resolver.model.PID;
|
17
|
import eu.dnetlib.pid.resolver.parser.AbstractResolverParser;
|
18
|
import org.apache.commons.lang3.StringUtils;
|
19
|
import org.apache.commons.logging.Log;
|
20
|
import org.apache.commons.logging.LogFactory;
|
21
|
|
22
|
/**
|
23
|
* Created by sandro on 9/29/16.
|
24
|
*/
|
25
|
public class ScholixResolverParser extends AbstractResolverParser {
|
26
|
|
27
|
private static final Log log = LogFactory.getLog(ScholixResolverParser.class);
|
28
|
|
29
|
@Override
|
30
|
public DLIResolvedObject parseObject(final String record) {
|
31
|
|
32
|
try {
|
33
|
final DLIResolvedObject parsedObject = new DLIResolvedObject();
|
34
|
final VTDGen vg = new VTDGen();
|
35
|
vg.setDoc(record.getBytes());
|
36
|
vg.parse(true);
|
37
|
|
38
|
final VTDNav vn = vg.getNav();
|
39
|
final AutoPilot ap = new AutoPilot(vn);
|
40
|
ap.declareXPathNameSpace("dri", "http://www.driver-repository.eu/namespace/dri");
|
41
|
|
42
|
final String resolvedDate = VtdUtilityParser.getSingleValue(ap, vn, "//dri:resolvedDate");
|
43
|
parsedObject.setResolvedDate(resolvedDate);
|
44
|
|
45
|
//final String datasourcePrefix = VtdUtilityParser.getSingleValue(ap, vn, "//dri:datasourceprefix");
|
46
|
ap.declareXPathNameSpace("oaf", "http://namespace.dnet.eu/oaf");
|
47
|
|
48
|
final String completionStatus = VtdUtilityParser.getSingleValue(ap, vn, "//oaf:completionStatus");
|
49
|
//final String provisionMode = VtdUtilityParser.getSingleValue(ap, vn, "//oaf:provisionMode");
|
50
|
|
51
|
List<VtdUtilityParser.Node> provenances =
|
52
|
VtdUtilityParser.getTextValuesWithAttributes(ap, vn, "//oaf:collectedFrom", Arrays.asList("completionStatus", "id", "name"));
|
53
|
|
54
|
|
55
|
ap.declareXPathNameSpace("scholix", "http://www.scholix.org");
|
56
|
|
57
|
final String sourcePid = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/identifier/identifier");
|
58
|
final String sourcePidTye = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/identifier/schema");
|
59
|
final String sourceType = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/objectType/type");
|
60
|
|
61
|
final String sourcePublisherId = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/publisher//identifier");
|
62
|
final String sourcePublisher = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/publisher/name");
|
63
|
|
64
|
|
65
|
if (StringUtils.isEmpty(sourcePid) || StringUtils.isEmpty(sourcePidTye)) {
|
66
|
return null;
|
67
|
}
|
68
|
|
69
|
final List<ObjectProvenance> provenanceList = new ArrayList<>();
|
70
|
if (provenances != null) {
|
71
|
provenances.forEach(it -> {
|
72
|
final DLIObjectProvenance provenance = new DLIObjectProvenance();
|
73
|
provenance.setDatasourceId(it.getAttributes().get("id"));
|
74
|
provenance.setDatasource(it.getAttributes().get("name"));
|
75
|
provenance.setCompletionStatus(it.getAttributes().get("completionStatus"));
|
76
|
provenance.setPublisher(sourcePublisher);
|
77
|
provenance.setPublisherId(sourcePublisherId);
|
78
|
provenance.setProvisionMode("collected");
|
79
|
provenanceList.add(provenance);
|
80
|
|
81
|
});
|
82
|
}
|
83
|
|
84
|
|
85
|
parsedObject.setDatasourceProvenance(provenanceList);
|
86
|
|
87
|
parsedObject.setCompletionStatus(completionStatus);
|
88
|
|
89
|
parsedObject.setPid(sourcePid);
|
90
|
parsedObject.setPidType(sourcePidTye);
|
91
|
if (!StringUtils.isEmpty(sourceType))
|
92
|
parsedObject.setType(ObjectType.valueOf(sourceType));
|
93
|
|
94
|
final String sourceTitle = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:source/title");
|
95
|
|
96
|
final List<String> creators = VtdUtilityParser.getTextValue(ap, vn, "//scholix:source//scholix:creatorName");
|
97
|
|
98
|
if (!StringUtils.isEmpty(sourceTitle))
|
99
|
parsedObject.setTitles(Arrays.asList(sourceTitle));
|
100
|
if (creators != null) {
|
101
|
final List<String> sourceCreators = new ArrayList<>();
|
102
|
|
103
|
creators.forEach(
|
104
|
agent -> {
|
105
|
if (!StringUtils.isEmpty(agent)) {
|
106
|
sourceCreators.add(agent);
|
107
|
}
|
108
|
}
|
109
|
);
|
110
|
parsedObject.setAuthors(sourceCreators);
|
111
|
}
|
112
|
|
113
|
parsedObject.setDate(VtdUtilityParser.getSingleValue(ap, vn, "//scholix:link/scholix:publicationDate"));
|
114
|
|
115
|
final String targetPid = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:target/identifier/identifier");
|
116
|
final String targetPidTye = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:target/identifier/schema");
|
117
|
final String targetType = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:target/objectType/type");
|
118
|
|
119
|
|
120
|
if (StringUtils.isEmpty(targetPid) || StringUtils.isEmpty(targetPidTye)) {
|
121
|
return null;
|
122
|
}
|
123
|
|
124
|
|
125
|
final String relationType = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:relashionship/name");
|
126
|
final String inverseRelationSemantic = VtdUtilityParser.getSingleValue(ap, vn, "//scholix:relashionship/inverseRelashionship");
|
127
|
|
128
|
|
129
|
final List<ObjectRelation> relations = new ArrayList<>();
|
130
|
|
131
|
DLIObjectRelation relation = new DLIObjectRelation();
|
132
|
relation.setCompletionStatus(CompletionStatus.incomplete.toString());
|
133
|
relation.setRelationProvenance(parsedObject.getDatasourceProvenance());
|
134
|
relation.setRelationSemantics(relationType);
|
135
|
relation.setInverseRelation(inverseRelationSemantic);
|
136
|
relation.setTargetPID(new PID(targetPid, targetPidTye));
|
137
|
if (!StringUtils.isEmpty(targetType))
|
138
|
relation.setTargetType(ObjectType.valueOf(targetType));
|
139
|
relations.add(relation);
|
140
|
parsedObject.setRelations(relations);
|
141
|
|
142
|
return parsedObject;
|
143
|
} catch (Throwable e) {
|
144
|
log.error("Error on parsing parser");
|
145
|
}
|
146
|
return null;
|
147
|
}
|
148
|
}
|