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