WIP: Graph footprint optimisation #287

Draft
claudio.atzori wants to merge 39 commits from ticket_8369 into beta
17 changed files with 502 additions and 660 deletions
Showing only changes of commit f8f4b9a018 - Show all commits

View File

@ -9,13 +9,13 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.jetbrains.annotations.NotNull;
import com.google.gson.Gson; import com.google.gson.Gson;
import eu.dnetlib.dhp.common.api.zenodo.ZenodoModel; import eu.dnetlib.dhp.common.api.zenodo.ZenodoModel;
import eu.dnetlib.dhp.common.api.zenodo.ZenodoModelList; import eu.dnetlib.dhp.common.api.zenodo.ZenodoModelList;
import okhttp3.*; import okhttp3.*;
import org.jetbrains.annotations.NotNull;
public class ZenodoAPIClient implements Serializable { public class ZenodoAPIClient implements Serializable {
@ -80,7 +80,7 @@ public class ZenodoAPIClient implements Serializable {
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + body); throw new IOException("Unexpected code " + responseCode + body);
ZenodoModel newSubmission = new Gson().fromJson(body, ZenodoModel.class); ZenodoModel newSubmission = new Gson().fromJson(body, ZenodoModel.class);
@ -115,7 +115,7 @@ public class ZenodoAPIClient implements Serializable {
} }
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
if(! checkOKStatus(responseCode)){ if (!checkOKStatus(responseCode)) {
throw new IOException("Unexpected code " + responseCode + getBody(conn)); throw new IOException("Unexpected code " + responseCode + getBody(conn));
} }
@ -126,7 +126,7 @@ public class ZenodoAPIClient implements Serializable {
private String getBody(HttpURLConnection conn) throws IOException { private String getBody(HttpURLConnection conn) throws IOException {
String body = "{}"; String body = "{}";
try (BufferedReader br = new BufferedReader( try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"))) { new InputStreamReader(conn.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
String responseLine = null; String responseLine = null;
while ((responseLine = br.readLine()) != null) { while ((responseLine = br.readLine()) != null) {
@ -155,7 +155,6 @@ public class ZenodoAPIClient implements Serializable {
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setRequestMethod("PUT"); conn.setRequestMethod("PUT");
try (OutputStream os = conn.getOutputStream()) { try (OutputStream os = conn.getOutputStream()) {
byte[] input = metadata.getBytes("utf-8"); byte[] input = metadata.getBytes("utf-8");
os.write(input, 0, input.length); os.write(input, 0, input.length);
@ -164,19 +163,18 @@ public class ZenodoAPIClient implements Serializable {
final int responseCode = conn.getResponseCode(); final int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + getBody(conn)); throw new IOException("Unexpected code " + responseCode + getBody(conn));
return responseCode; return responseCode;
} }
private boolean checkOKStatus(int responseCode) { private boolean checkOKStatus(int responseCode) {
if(HttpURLConnection.HTTP_OK != responseCode || if (HttpURLConnection.HTTP_OK != responseCode ||
HttpURLConnection.HTTP_CREATED != responseCode) HttpURLConnection.HTTP_CREATED != responseCode)
return true ; return true;
return false; return false;
} }
@ -233,7 +231,6 @@ public class ZenodoAPIClient implements Serializable {
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setRequestMethod("POST"); conn.setRequestMethod("POST");
try (OutputStream os = conn.getOutputStream()) { try (OutputStream os = conn.getOutputStream()) {
byte[] input = json.getBytes("utf-8"); byte[] input = json.getBytes("utf-8");
os.write(input, 0, input.length); os.write(input, 0, input.length);
@ -245,7 +242,7 @@ public class ZenodoAPIClient implements Serializable {
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + body); throw new IOException("Unexpected code " + responseCode + body);
ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class); ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class);
@ -290,13 +287,12 @@ public class ZenodoAPIClient implements Serializable {
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + body); throw new IOException("Unexpected code " + responseCode + body);
ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class); ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class);
bucket = zenodoModel.getLinks().getBucket(); bucket = zenodoModel.getLinks().getBucket();
return responseCode; return responseCode;
} }
@ -331,22 +327,16 @@ public class ZenodoAPIClient implements Serializable {
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
String body = getBody(conn); String body = getBody(conn);
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + body); throw new IOException("Unexpected code " + responseCode + body);
return body; return body;
} }
private String getBucket(String inputUurl) throws IOException { private String getBucket(String inputUurl) throws IOException {
@ -363,15 +353,13 @@ public class ZenodoAPIClient implements Serializable {
int responseCode = conn.getResponseCode(); int responseCode = conn.getResponseCode();
conn.disconnect(); conn.disconnect();
if(!checkOKStatus(responseCode)) if (!checkOKStatus(responseCode))
throw new IOException("Unexpected code " + responseCode + body); throw new IOException("Unexpected code " + responseCode + body);
ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class); ZenodoModel zenodoModel = new Gson().fromJson(body, ZenodoModel.class);
return zenodoModel.getLinks().getBucket(); return zenodoModel.getLinks().getBucket();
} }
} }

View File

@ -86,7 +86,6 @@ public class ModelConstants {
public static final Qualifier PROVENANCE_ACTION_SET_QUALIFIER = qualifier( public static final Qualifier PROVENANCE_ACTION_SET_QUALIFIER = qualifier(
SYSIMPORT_ACTIONSET, SYSIMPORT_ACTIONSET, DNET_PROVENANCE_ACTIONS); SYSIMPORT_ACTIONSET, SYSIMPORT_ACTIONSET, DNET_PROVENANCE_ACTIONS);
public static final String UNKNOWN = "UNKNOWN"; public static final String UNKNOWN = "UNKNOWN";
public static final String NOT_AVAILABLE = "not available"; public static final String NOT_AVAILABLE = "not available";

View File

@ -2,16 +2,12 @@
package eu.dnetlib.dhp.schema.oaf.common; package eu.dnetlib.dhp.schema.oaf.common;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static eu.dnetlib.dhp.schema.common.ModelConstants.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Date; import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
@ -96,26 +92,6 @@ public class ModelSupport {
idPrefixEntity.put("50", "result"); idPrefixEntity.put("50", "result");
} }
private static void set(Map<String, RelationInverse> relationInverseMap, String relType, String subRelType,
String relClass, String inverseRelClass) {
relationInverseMap
.put(
rel(relType, subRelType, relClass), new RelationInverse()
.setInverseRelClass(inverseRelClass)
.setRelClass(relClass)
.setRelType(relType)
.setSubReltype(subRelType));
if (!relClass.equals(inverseRelClass)) {
relationInverseMap
.put(
rel(relType, subRelType, inverseRelClass), new RelationInverse()
.setInverseRelClass(relClass)
.setRelClass(inverseRelClass)
.setRelType(relType)
.setSubReltype(subRelType));
}
}
/** /**
* Helper method: combines the relation attributes * Helper method: combines the relation attributes
* @param relType * @param relType
@ -127,6 +103,24 @@ public class ModelSupport {
return String.format("%s_%s_%s", relType, subRelType, relClass); return String.format("%s_%s_%s", relType, subRelType, relClass);
} }
/**
* Helper method: deserialize the relation attributes serialized with rel
* @param relType
* @param subRelType
* @param relClass
* @return
*/
public static RelationLabel unRel(String deserialization) {
final String[] s = deserialization.split("_");
if (s!= null && s.length==3) {
final Relation.RELTYPE currentRelType = Relation.RELTYPE.valueOf(s[0]);
final Relation.SUBRELTYPE currentSubRelType = Relation.SUBRELTYPE.valueOf(s[1]);
final Relation.RELCLASS currentRelClass = Relation.RELCLASS.valueOf(s[2]);
return new RelationLabel(currentRelClass, currentRelType, currentSubRelType);
}
throw new IllegalArgumentException("Invalid relationship format for "+ deserialization);
}
private static final String schemeTemplate = "dnet:%s_%s_relations"; private static final String schemeTemplate = "dnet:%s_%s_relations";
public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String DATE_FORMAT = "yyyy-MM-dd";

View File

@ -1,46 +0,0 @@
package eu.dnetlib.dhp.schema.oaf.common;
public class RelationInverse {
private String relClass;
private String inverseRelClass;
private String relType;
private String subReltype;
public String getRelType() {
return relType;
}
public RelationInverse setRelType(String relType) {
this.relType = relType;
return this;
}
public String getSubReltype() {
return subReltype;
}
public RelationInverse setSubReltype(String subReltype) {
this.subReltype = subReltype;
return this;
}
public String getRelClass() {
return relClass;
}
public RelationInverse setRelClass(String relClass) {
this.relClass = relClass;
return this;
}
public String getInverseRelClass() {
return inverseRelClass;
}
public RelationInverse setInverseRelClass(String inverseRelClass) {
this.inverseRelClass = inverseRelClass;
return this;
}
}

View File

@ -0,0 +1,33 @@
package eu.dnetlib.dhp.schema.oaf.common;
import eu.dnetlib.dhp.schema.oaf.Relation;
public class RelationLabel {
private final Relation.RELCLASS relClass;
private final Relation.RELTYPE relType;
private final Relation.SUBRELTYPE subReltype;
public RelationLabel(Relation.RELCLASS relClass, Relation.RELTYPE relType, Relation.SUBRELTYPE subReltype) {
this.relClass = relClass;
this.relType = relType;
this.subReltype = subReltype;
}
public RelationLabel inverse() {
return new RelationLabel(relClass.getInverse(), relType, subReltype);
}
public Relation.RELTYPE getRelType() {
return relType;
}
public Relation.SUBRELTYPE getSubReltype() {
return subReltype;
}
public Relation.RELCLASS getRelClass() {
return relClass;
}
}

View File

@ -18,443 +18,443 @@ import eu.dnetlib.dhp.schema.oaf.common.AccessRightComparator;
public class OafMapperUtils { public class OafMapperUtils {
private OafMapperUtils() { private OafMapperUtils() {
} }
public static KeyValue keyValue(final String k, final String v) { public static KeyValue keyValue(final String k, final String v) {
final KeyValue kv = new KeyValue(); final KeyValue kv = new KeyValue();
kv.setKey(k); kv.setKey(k);
kv.setValue(v); kv.setValue(v);
return kv; return kv;
} }
public static List<KeyValue> listKeyValues(final String... s) { public static List<KeyValue> listKeyValues(final String... s) {
if (s.length % 2 > 0) { if (s.length % 2 > 0) {
throw new IllegalArgumentException("Invalid number of parameters (k,v,k,v,....)"); throw new IllegalArgumentException("Invalid number of parameters (k,v,k,v,....)");
} }
final List<KeyValue> list = new ArrayList<>(); final List<KeyValue> list = new ArrayList<>();
for (int i = 0; i < s.length; i += 2) { for (int i = 0; i < s.length; i += 2) {
list.add(keyValue(s[i], s[i + 1])); list.add(keyValue(s[i], s[i + 1]));
} }
return list; return list;
} }
public static <T> List<T> listValues(Array values) throws SQLException { public static <T> List<T> listValues(Array values) throws SQLException {
if (Objects.isNull(values)) { if (Objects.isNull(values)) {
return null; return null;
} }
return Arrays return Arrays
.stream((T[]) values.getArray()) .stream((T[]) values.getArray())
.filter(Objects::nonNull) .filter(Objects::nonNull)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static Qualifier unknown(final String schemeid) { public static Qualifier unknown(final String schemeid) {
return qualifier(UNKNOWN, "Unknown", schemeid); return qualifier(UNKNOWN, "Unknown", schemeid);
} }
public static AccessRight accessRight( public static AccessRight accessRight(
final String classid, final String classid,
final String classname, final String classname,
final String schemeid) { final String schemeid) {
return accessRight(classid, classname, schemeid, null); return accessRight(classid, classname, schemeid, null);
} }
public static AccessRight accessRight( public static AccessRight accessRight(
final String classid, final String classid,
final String classname, final String classname,
final String schemeid, final String schemeid,
final OpenAccessRoute openAccessRoute) { final OpenAccessRoute openAccessRoute) {
final AccessRight accessRight = new AccessRight(); final AccessRight accessRight = new AccessRight();
accessRight.setClassid(classid); accessRight.setClassid(classid);
accessRight.setClassname(classname); accessRight.setClassname(classname);
accessRight.setSchemeid(schemeid); accessRight.setSchemeid(schemeid);
accessRight.setOpenAccessRoute(openAccessRoute); accessRight.setOpenAccessRoute(openAccessRoute);
return accessRight; return accessRight;
} }
public static Qualifier qualifier( public static Qualifier qualifier(
final String classid, final String classid,
final String classname, final String classname,
final String schemeid) { final String schemeid) {
final Qualifier q = new Qualifier(); final Qualifier q = new Qualifier();
q.setClassid(classid); q.setClassid(classid);
q.setClassname(classname); q.setClassname(classname);
q.setSchemeid(schemeid); q.setSchemeid(schemeid);
return q; return q;
} }
public static Qualifier qualifier(final Qualifier qualifier) { public static Qualifier qualifier(final Qualifier qualifier) {
final Qualifier q = new Qualifier(); final Qualifier q = new Qualifier();
q.setClassid(qualifier.getClassid()); q.setClassid(qualifier.getClassid());
q.setClassname(qualifier.getClassname()); q.setClassname(qualifier.getClassname());
q.setSchemeid(qualifier.getSchemeid()); q.setSchemeid(qualifier.getSchemeid());
return q; return q;
} }
public static Subject subject( public static Subject subject(
final String value, final String value,
final String classid, final String classid,
final String classname, final String classname,
final String schemeid, final String schemeid,
final DataInfo dataInfo) { final DataInfo dataInfo) {
return subject(value, qualifier(classid, classname, schemeid), dataInfo); return subject(value, qualifier(classid, classname, schemeid), dataInfo);
} }
public static StructuredProperty structuredProperty( public static StructuredProperty structuredProperty(
final String value, final String value,
final String classid, final String classid,
final String classname, final String classname,
final String schemeid) { final String schemeid) {
return structuredProperty(value, qualifier(classid, classname, schemeid)); return structuredProperty(value, qualifier(classid, classname, schemeid));
} }
public static Subject subject( public static Subject subject(
final String value, final String value,
final Qualifier qualifier, final Qualifier qualifier,
final DataInfo dataInfo) { final DataInfo dataInfo) {
if (value == null) { if (value == null) {
return null; return null;
} }
final Subject s = new Subject(); final Subject s = new Subject();
s.setValue(value); s.setValue(value);
s.setQualifier(qualifier); s.setQualifier(qualifier);
s.setDataInfo(dataInfo); s.setDataInfo(dataInfo);
return s; return s;
} }
public static StructuredProperty structuredProperty( public static StructuredProperty structuredProperty(
final String value, final String value,
final Qualifier qualifier) { final Qualifier qualifier) {
if (value == null) { if (value == null) {
return null; return null;
} }
final StructuredProperty sp = new StructuredProperty(); final StructuredProperty sp = new StructuredProperty();
sp.setValue(value); sp.setValue(value);
sp.setQualifier(qualifier); sp.setQualifier(qualifier);
return sp; return sp;
} }
public static Publisher publisher(final String name) { public static Publisher publisher(final String name) {
final Publisher p = new Publisher(); final Publisher p = new Publisher();
p.setName(name); p.setName(name);
return p; return p;
} }
public static License license(final String url) { public static License license(final String url) {
final License l = new License(); final License l = new License();
l.setUrl(url); l.setUrl(url);
return l; return l;
} }
public static AuthorPid authorPid( public static AuthorPid authorPid(
final String value, final String value,
final Qualifier qualifier, final Qualifier qualifier,
final DataInfo dataInfo) { final DataInfo dataInfo) {
if (value == null) { if (value == null) {
return null; return null;
} }
final AuthorPid ap = new AuthorPid(); final AuthorPid ap = new AuthorPid();
ap.setValue(value); ap.setValue(value);
ap.setQualifier(qualifier); ap.setQualifier(qualifier);
ap.setDataInfo(dataInfo); ap.setDataInfo(dataInfo);
return ap; return ap;
} }
public static AuthorPid authorPid( public static AuthorPid authorPid(
final String value, final String value,
final String classid, final String classid,
final String schemeid, final String schemeid,
final DataInfo dataInfo) { final DataInfo dataInfo) {
if (value == null) { if (value == null) {
return null; return null;
} }
final AuthorPid ap = new AuthorPid(); final AuthorPid ap = new AuthorPid();
ap.setValue(value); ap.setValue(value);
ap.setQualifier(qualifier(classid, classid, schemeid)); ap.setQualifier(qualifier(classid, classid, schemeid));
ap.setDataInfo(dataInfo); ap.setDataInfo(dataInfo);
return ap; return ap;
} }
public static ExtraInfo extraInfo( public static ExtraInfo extraInfo(
final String name, final String name,
final String value, final String value,
final String typology, final String typology,
final String provenance, final String provenance,
final String trust) { final String trust) {
final ExtraInfo info = new ExtraInfo(); final ExtraInfo info = new ExtraInfo();
info.setName(name); info.setName(name);
info.setValue(value); info.setValue(value);
info.setTypology(typology); info.setTypology(typology);
info.setProvenance(provenance); info.setProvenance(provenance);
info.setTrust(trust); info.setTrust(trust);
return info; return info;
} }
public static OAIProvenance oaiIProvenance( public static OAIProvenance oaiIProvenance(
final String identifier, final String identifier,
final String baseURL, final String baseURL,
final String metadataNamespace, final String metadataNamespace,
final Boolean altered, final Boolean altered,
final String datestamp, final String datestamp,
final String harvestDate) { final String harvestDate) {
final OriginDescription desc = new OriginDescription(); final OriginDescription desc = new OriginDescription();
desc.setIdentifier(identifier); desc.setIdentifier(identifier);
desc.setBaseURL(baseURL); desc.setBaseURL(baseURL);
desc.setMetadataNamespace(metadataNamespace); desc.setMetadataNamespace(metadataNamespace);
desc.setAltered(altered); desc.setAltered(altered);
desc.setDatestamp(datestamp); desc.setDatestamp(datestamp);
desc.setHarvestDate(harvestDate); desc.setHarvestDate(harvestDate);
final OAIProvenance p = new OAIProvenance(); final OAIProvenance p = new OAIProvenance();
p.setOriginDescription(desc); p.setOriginDescription(desc);
return p; return p;
} }
public static Journal journal( public static Journal journal(
final String name, final String name,
final String issnPrinted, final String issnPrinted,
final String issnOnline, final String issnOnline,
final String issnLinking) { final String issnLinking) {
return hasIssn(issnPrinted, issnOnline, issnLinking) ? journal( return hasIssn(issnPrinted, issnOnline, issnLinking) ? journal(
name, name,
issnPrinted, issnPrinted,
issnOnline, issnOnline,
issnLinking, issnLinking,
null, null,
null, null,
null, null,
null, null,
null, null,
null, null,
null) : null; null) : null;
} }
public static Journal journal( public static Journal journal(
final String name, final String name,
final String issnPrinted, final String issnPrinted,
final String issnOnline, final String issnOnline,
final String issnLinking, final String issnLinking,
final String ep, final String ep,
final String iss, final String iss,
final String sp, final String sp,
final String vol, final String vol,
final String edition, final String edition,
final String conferenceplace, final String conferenceplace,
final String conferencedate) { final String conferencedate) {
if (StringUtils.isNotBlank(name) || hasIssn(issnPrinted, issnOnline, issnLinking)) { if (StringUtils.isNotBlank(name) || hasIssn(issnPrinted, issnOnline, issnLinking)) {
final Journal j = new Journal(); final Journal j = new Journal();
j.setName(name); j.setName(name);
j.setIssnPrinted(issnPrinted); j.setIssnPrinted(issnPrinted);
j.setIssnOnline(issnOnline); j.setIssnOnline(issnOnline);
j.setIssnLinking(issnLinking); j.setIssnLinking(issnLinking);
j.setEp(ep); j.setEp(ep);
j.setIss(iss); j.setIss(iss);
j.setSp(sp); j.setSp(sp);
j.setVol(vol); j.setVol(vol);
j.setEdition(edition); j.setEdition(edition);
j.setConferenceplace(conferenceplace); j.setConferenceplace(conferenceplace);
j.setConferencedate(conferencedate); j.setConferencedate(conferencedate);
return j; return j;
} else { } else {
return null; return null;
} }
} }
private static boolean hasIssn(String issnPrinted, String issnOnline, String issnLinking) { private static boolean hasIssn(String issnPrinted, String issnOnline, String issnLinking) {
return StringUtils.isNotBlank(issnPrinted) return StringUtils.isNotBlank(issnPrinted)
|| StringUtils.isNotBlank(issnOnline) || StringUtils.isNotBlank(issnOnline)
|| StringUtils.isNotBlank(issnLinking); || StringUtils.isNotBlank(issnLinking);
} }
public static DataInfo dataInfo( public static DataInfo dataInfo(
final float trust, final float trust,
final String inferenceprovenance, final String inferenceprovenance,
final boolean inferred, final boolean inferred,
final Qualifier provenanceaction) { final Qualifier provenanceaction) {
final DataInfo d = new DataInfo(); final DataInfo d = new DataInfo();
d.setTrust(trust); d.setTrust(trust);
d.setInferenceprovenance(inferenceprovenance); d.setInferenceprovenance(inferenceprovenance);
d.setInferred(inferred); d.setInferred(inferred);
d.setProvenanceaction(provenanceaction); d.setProvenanceaction(provenanceaction);
return d; return d;
} }
public static EntityDataInfo dataInfo( public static EntityDataInfo dataInfo(
final boolean invisible, final boolean invisible,
final boolean deletedbyinference, final boolean deletedbyinference,
final float trust, final float trust,
final String inferenceprovenance, final String inferenceprovenance,
final boolean inferred, final boolean inferred,
final Qualifier provenanceaction) { final Qualifier provenanceaction) {
final EntityDataInfo d = new EntityDataInfo(); final EntityDataInfo d = new EntityDataInfo();
d.setTrust(trust); d.setTrust(trust);
d.setInvisible(invisible); d.setInvisible(invisible);
d.setDeletedbyinference(deletedbyinference); d.setDeletedbyinference(deletedbyinference);
d.setInferenceprovenance(inferenceprovenance); d.setInferenceprovenance(inferenceprovenance);
d.setInferred(inferred); d.setInferred(inferred);
d.setProvenanceaction(provenanceaction); d.setProvenanceaction(provenanceaction);
return d; return d;
} }
public static String asString(final Object o) { public static String asString(final Object o) {
return o == null ? "" : o.toString(); return o == null ? "" : o.toString();
} }
public static <T> Predicate<T> distinctByKey( public static <T> Predicate<T> distinctByKey(
final Function<? super T, ?> keyExtractor) { final Function<? super T, ?> keyExtractor) {
final Map<Object, Boolean> seen = new ConcurrentHashMap<>(); final Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
} }
public static Qualifier createBestAccessRights(final List<Instance> instanceList) { public static Qualifier createBestAccessRights(final List<Instance> instanceList) {
return getBestAccessRights(instanceList); return getBestAccessRights(instanceList);
} }
protected static Qualifier getBestAccessRights(final List<Instance> instanceList) { protected static Qualifier getBestAccessRights(final List<Instance> instanceList) {
if (instanceList != null) { if (instanceList != null) {
final Optional<AccessRight> min = instanceList final Optional<AccessRight> min = instanceList
.stream() .stream()
.map(Instance::getAccessright) .map(Instance::getAccessright)
.min(new AccessRightComparator<>()); .min(new AccessRightComparator<>());
final Qualifier rights = min.map(OafMapperUtils::qualifier).orElseGet(Qualifier::new); final Qualifier rights = min.map(OafMapperUtils::qualifier).orElseGet(Qualifier::new);
if (StringUtils.isBlank(rights.getClassid())) { if (StringUtils.isBlank(rights.getClassid())) {
rights.setClassid(UNKNOWN); rights.setClassid(UNKNOWN);
} }
if (StringUtils.isBlank(rights.getClassname()) if (StringUtils.isBlank(rights.getClassname())
|| UNKNOWN.equalsIgnoreCase(rights.getClassname())) { || UNKNOWN.equalsIgnoreCase(rights.getClassname())) {
rights.setClassname(NOT_AVAILABLE); rights.setClassname(NOT_AVAILABLE);
} }
if (StringUtils.isBlank(rights.getSchemeid())) { if (StringUtils.isBlank(rights.getSchemeid())) {
rights.setSchemeid(DNET_ACCESS_MODES); rights.setSchemeid(DNET_ACCESS_MODES);
} }
return rights; return rights;
} }
return null; return null;
} }
public static Measure newMeasureInstance(String id, String value, String key, DataInfo dataInfo) { public static Measure newMeasureInstance(String id, String value, String key, DataInfo dataInfo) {
Measure m = new Measure(); Measure m = new Measure();
m.setId(id); m.setId(id);
m.setUnit(Arrays.asList(unit(key, value, dataInfo))); m.setUnit(Arrays.asList(unit(key, value, dataInfo)));
return m; return m;
} }
public static MeasureUnit unit(String key, String value, DataInfo dataInfo) { public static MeasureUnit unit(String key, String value, DataInfo dataInfo) {
MeasureUnit unit = new MeasureUnit(); MeasureUnit unit = new MeasureUnit();
unit.setKey(key); unit.setKey(key);
unit.setValue(value); unit.setValue(value);
unit.setDataInfo(dataInfo); unit.setDataInfo(dataInfo);
return unit; return unit;
} }
public static Relation getRelation(final String source, public static Relation getRelation(final String source,
final String target, final String target,
final Relation.RELTYPE relType, final Relation.RELTYPE relType,
final Relation.SUBRELTYPE subRelType, final Relation.SUBRELTYPE subRelType,
final Relation.RELCLASS relClass, final Relation.RELCLASS relClass,
final Entity entity) { final Entity entity) {
return getRelation(source, target, relType, subRelType, relClass, entity, null); return getRelation(source, target, relType, subRelType, relClass, entity, null);
} }
public static Relation getRelation(final String source, public static Relation getRelation(final String source,
final String target, final String target,
final Relation.RELTYPE relType, final Relation.RELTYPE relType,
final Relation.SUBRELTYPE subRelType, final Relation.SUBRELTYPE subRelType,
final Relation.RELCLASS relClass, final Relation.RELCLASS relClass,
final Entity entity, final Entity entity,
final String validationDate) { final String validationDate) {
final List<Provenance> provenance = getProvenance( final List<Provenance> provenance = getProvenance(
entity.getCollectedfrom(), fromEntityDataInfo(entity.getDataInfo())); entity.getCollectedfrom(), fromEntityDataInfo(entity.getDataInfo()));
return getRelation( return getRelation(
source, target, relType, subRelType, relClass, provenance, validationDate, null); source, target, relType, subRelType, relClass, provenance, validationDate, null);
} }
public static Relation getRelation(final String source, public static Relation getRelation(final String source,
final String target, final String target,
final Relation.RELTYPE relType, final Relation.RELTYPE relType,
final Relation.SUBRELTYPE subRelType, final Relation.SUBRELTYPE subRelType,
final Relation.RELCLASS relClass, final Relation.RELCLASS relClass,
final List<Provenance> provenance) { final List<Provenance> provenance) {
return getRelation( return getRelation(
source, target, relType, subRelType, relClass, provenance, null, null); source, target, relType, subRelType, relClass, provenance, null, null);
} }
public static Relation getRelation(final String source, public static Relation getRelation(final String source,
final String target, final String target,
final Relation.RELTYPE relType, final Relation.RELTYPE relType,
final Relation.SUBRELTYPE subRelType, final Relation.SUBRELTYPE subRelType,
final Relation.RELCLASS relClass, final Relation.RELCLASS relClass,
final List<Provenance> provenance, final List<Provenance> provenance,
final List<KeyValue> properties) { final List<KeyValue> properties) {
return getRelation( return getRelation(
source, target, relType, subRelType, relClass, provenance, null, properties); source, target, relType, subRelType, relClass, provenance, null, properties);
} }
public static Relation getRelation(final String source, public static Relation getRelation(final String source,
final String target, final String target,
final Relation.RELTYPE relType, final Relation.RELTYPE relType,
final Relation.SUBRELTYPE subRelType, final Relation.SUBRELTYPE subRelType,
final Relation.RELCLASS relClass, final Relation.RELCLASS relClass,
final List<Provenance> provenance, final List<Provenance> provenance,
final String validationDate, final String validationDate,
final List<KeyValue> properties) { final List<KeyValue> properties) {
final Relation rel = new Relation(); final Relation rel = new Relation();
rel.setRelType(relType); rel.setRelType(relType);
rel.setSubRelType(subRelType); rel.setSubRelType(subRelType);
rel.setRelClass(relClass); rel.setRelClass(relClass);
rel.setSource(source); rel.setSource(source);
rel.setTarget(target); rel.setTarget(target);
rel.setProvenance(provenance); rel.setProvenance(provenance);
rel.setValidated(StringUtils.isNotBlank(validationDate)); rel.setValidated(StringUtils.isNotBlank(validationDate));
rel.setValidationDate(StringUtils.isNotBlank(validationDate) ? validationDate : null); rel.setValidationDate(StringUtils.isNotBlank(validationDate) ? validationDate : null);
rel.setProperties(properties); rel.setProperties(properties);
return rel; return rel;
} }
public static List<Provenance> getProvenance(final List<KeyValue> collectedfrom, final DataInfo dataInfo) { public static List<Provenance> getProvenance(final List<KeyValue> collectedfrom, final DataInfo dataInfo) {
return collectedfrom return collectedfrom
.stream() .stream()
.map(cf -> getProvenance(cf, dataInfo)) .map(cf -> getProvenance(cf, dataInfo))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static Provenance getProvenance(final KeyValue collectedfrom, final DataInfo dataInfo) { public static Provenance getProvenance(final KeyValue collectedfrom, final DataInfo dataInfo) {
final Provenance prov = new Provenance(); final Provenance prov = new Provenance();
prov.setCollectedfrom(collectedfrom); prov.setCollectedfrom(collectedfrom);
prov.setDataInfo(dataInfo); prov.setDataInfo(dataInfo);
return prov; return prov;
} }
public static String getProvenance(DataInfo dataInfo) { public static String getProvenance(DataInfo dataInfo) {
return Optional return Optional
.ofNullable(dataInfo) .ofNullable(dataInfo)
.map( .map(
d -> Optional d -> Optional
.ofNullable(d.getProvenanceaction()) .ofNullable(d.getProvenanceaction())
.map(Qualifier::getClassid) .map(Qualifier::getClassid)
.orElse("")) .orElse(""))
.orElse(""); .orElse("");
} }
public static DataInfo fromEntityDataInfo(EntityDataInfo entityDataInfo) { public static DataInfo fromEntityDataInfo(EntityDataInfo entityDataInfo) {
DataInfo dataInfo = new DataInfo(); DataInfo dataInfo = new DataInfo();
dataInfo.setTrust(entityDataInfo.getTrust()); dataInfo.setTrust(entityDataInfo.getTrust());
dataInfo.setInferenceprovenance(entityDataInfo.getInferenceprovenance()); dataInfo.setInferenceprovenance(entityDataInfo.getInferenceprovenance());
dataInfo.setInferred(entityDataInfo.getInferred()); dataInfo.setInferred(entityDataInfo.getInferred());
dataInfo.setProvenanceaction(entityDataInfo.getProvenanceaction()); dataInfo.setProvenanceaction(entityDataInfo.getProvenanceaction());
return dataInfo; return dataInfo;
} }
} }

View File

@ -1,59 +0,0 @@
package eu.dnetlib.dhp.schema.sx
import eu.dnetlib.dhp.schema.common.ModelConstants
import eu.dnetlib.dhp.schema.oaf._
object OafUtils {
def generateKeyValue(key: String, value: String): KeyValue = {
val kv: KeyValue = new KeyValue()
kv.setKey(key)
kv.setValue(value)
kv
}
def generateDataInfo(trust: Float = 0.9f, invisible: Boolean = false): DataInfo = {
val di = new DataInfo
di.setInferred(false)
di.setTrust(trust)
di.setProvenanceaction(createQualifier(ModelConstants.SYSIMPORT_ACTIONSET, ModelConstants.DNET_PROVENANCE_ACTIONS))
di
}
def createQualifier(cls: String, sch: String): Qualifier = {
createQualifier(cls, cls, sch)
}
def createQualifier(classId: String, className: String, schemeId: String): Qualifier = {
val q: Qualifier = new Qualifier
q.setClassid(classId)
q.setClassname(className)
q.setSchemeid(schemeId)
q
}
def createAccessRight(classId: String, className: String, schemeId: String): AccessRight = {
val accessRight: AccessRight = new AccessRight
accessRight.setClassid(classId)
accessRight.setClassname(className)
accessRight.setSchemeid(schemeId)
accessRight
}
def createSP(value: String, classId: String,className:String, schemeId: String): StructuredProperty = {
val sp = new StructuredProperty
sp.setQualifier(createQualifier(classId,className, schemeId))
sp.setValue(value)
sp
}
def createSP(value: String, classId: String, schemeId: String): StructuredProperty = {
val sp = new StructuredProperty
sp.setQualifier(createQualifier(classId, schemeId))
sp.setValue(value)
sp
}
}

View File

@ -1,25 +0,0 @@
package eu.dnetlib.scholexplorer.relation;
import java.io.Serializable;
public class RelInfo implements Serializable {
private String original;
private String inverse;
public String getOriginal() {
return original;
}
public void setOriginal(String original) {
this.original = original;
}
public String getInverse() {
return inverse;
}
public void setInverse(String inverse) {
this.inverse = inverse;
}
}

View File

@ -1,20 +0,0 @@
package eu.dnetlib.scholexplorer.relation;
import java.io.Serializable;
import java.util.HashMap;
import org.apache.commons.io.IOUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
public class RelationMapper extends HashMap<String, RelInfo> implements Serializable {
public static RelationMapper load() throws Exception {
final String json = IOUtils.toString(RelationMapper.class.getResourceAsStream("relations.json"));
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, RelationMapper.class);
}
}

View File

@ -36,15 +36,4 @@ public class ModelSupportTest {
} }
} }
@Nested
class InverseRelation {
@Test
void findRelations() {
assertNotNull(ModelSupport.findRelation("isMetadataFor"));
assertNotNull(ModelSupport.findRelation("ismetadatafor"));
assertNotNull(ModelSupport.findRelation("ISMETADATAFOR"));
assertNotNull(ModelSupport.findRelation("isRelatedTo"));
}
}
} }

View File

@ -1,16 +0,0 @@
package eu.dnetlib.scholexplorer.relation;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
class RelationMapperTest {
@Test
void testLoadRels() throws Exception {
RelationMapper relationMapper = RelationMapper.load();
assertFalse(relationMapper.isEmpty());
}
}

View File

@ -2,7 +2,7 @@ package eu.dnetlib.dhp.datacite
import eu.dnetlib.dhp.schema.common.ModelConstants import eu.dnetlib.dhp.schema.common.ModelConstants
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils
import eu.dnetlib.dhp.schema.oaf.{DataInfo, EntityDataInfo, KeyValue} import eu.dnetlib.dhp.schema.oaf.{DataInfo, EntityDataInfo, KeyValue, Relation}
import java.io.InputStream import java.io.InputStream
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@ -66,12 +66,13 @@ class DataciteModelConstants extends Serializable {}
object DataciteModelConstants { object DataciteModelConstants {
val REL_TYPE_VALUE: String = "resultResult" val REL_TYPE_VALUE =Relation.RELTYPE.resultResult
val DATE_RELATION_KEY = "RelationDate" val DATE_RELATION_KEY = "RelationDate"
val DATACITE_FILTER_PATH = "/eu/dnetlib/dhp/datacite/datacite_filter" val DATACITE_FILTER_PATH = "/eu/dnetlib/dhp/datacite/datacite_filter"
val DOI_CLASS = "doi"
val SUBJ_CLASS = "keywords" val SUBJ_CLASS = "keywords"
val DATACITE_NAME = "Datacite" val DATACITE_NAME = "Datacite"
val PMID = "pmid"
val ARXIV = "arxiv"
val dataInfo: EntityDataInfo = dataciteDataInfo(0.9f) val dataInfo: EntityDataInfo = dataciteDataInfo(0.9f)
val relDataInfo = OafMapperUtils.fromEntityDataInfo(dataInfo); val relDataInfo = OafMapperUtils.fromEntityDataInfo(dataInfo);
@ -138,4 +139,8 @@ object DataciteModelConstants {
Pattern.compile("(19|20)\\d\\d", Pattern.MULTILINE) Pattern.compile("(19|20)\\d\\d", Pattern.MULTILINE)
) )
def validIdentifiersInRelation(relatedIdentifierType:String):Boolean = {
relatedIdentifierType.equalsIgnoreCase(ModelConstants.DOI) || relatedIdentifierType.equalsIgnoreCase(PMID) ||
relatedIdentifierType.equalsIgnoreCase(ARXIV)
}
} }

View File

@ -100,7 +100,7 @@ object DataciteToOAFTransformation {
} }
/** This utility method indicates whether the embargo date has been reached /** This utility method indicates whether the embargo date has been reached
* @param embargo_end_date * @param embargo_end_date the end date of embargo
* @return True if the embargo date has been reached, false otherwise * @return True if the embargo date has been reached, false otherwise
*/ */
def embargo_end(embargo_end_date: String): Boolean = { def embargo_end(embargo_end_date: String): Boolean = {
@ -345,8 +345,8 @@ object DataciteToOAFTransformation {
// DOI is mapped on a PID inside a Instance object // DOI is mapped on a PID inside a Instance object
val doi_q = OafMapperUtils.qualifier( val doi_q = OafMapperUtils.qualifier(
"doi", ModelConstants.DOI,
"doi", ModelConstants.DOI,
ModelConstants.DNET_PID_TYPES ModelConstants.DNET_PID_TYPES
) )
val pid = OafMapperUtils.structuredProperty(doi, doi_q) val pid = OafMapperUtils.structuredProperty(doi, doi_q)
@ -615,44 +615,52 @@ object DataciteToOAFTransformation {
List(result) List(result)
} }
//TODO @CLAUDIO we need to define relation in which verse
/**
* This function generate unresolved relation from the original Datacite document
* @param rels the related identifier section on the document
* @param id the source record Identifier
* @param date the date of collection
* @return a List of OAF relation
*/
private def generateRelations( private def generateRelations(
rels: List[RelatedIdentifierType], rels: List[RelatedIdentifierType],
id: String, id: String,
date: String date: String
): List[Relation] = { ): List[Relation] = {
// TODO We need to check how to generate realtions
// in the previous implementation we create all Bidirection Relations
// related to a DOI pid or arxiv,
val bidirectionalRels: List[Relation] = rels val bidirectionalRels: List[Relation] = rels
.filter(r => .filter(r =>
Relation.RELCLASS.exists(r.relationType) && (r.relatedIdentifierType.equalsIgnoreCase("doi") || Relation.RELCLASS.exists(r.relationType) && validIdentifiersInRelation(r.relatedIdentifierType)
r.relatedIdentifierType.equalsIgnoreCase("pmid") ||
r.relatedIdentifierType.equalsIgnoreCase("arxiv"))
) )
.map(r => { .map(r => {
val subRelType = subRelTypeMapping(r.relationType).relType val subRelType = Relation.SUBRELTYPE.valueOf(r.relationType)
val target = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType) val target = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType)
relation(id, target, subRelType, r.relationType, date) relation(id, target, subRelType, Relation.RELCLASS.valueOf(r.relationType), date)
}) })
val citationRels: List[Relation] = rels val citationRels: List[Relation] = rels
.filter(r => .filter(r =>validIdentifiersInRelation(r.relatedIdentifierType) &&
(r.relatedIdentifierType.equalsIgnoreCase("doi") ||
r.relatedIdentifierType.equalsIgnoreCase("pmid") ||
r.relatedIdentifierType.equalsIgnoreCase("arxiv")) &&
(r.relationType.toLowerCase.contains("cite") || r.relationType.toLowerCase.contains("reference")) (r.relationType.toLowerCase.contains("cite") || r.relationType.toLowerCase.contains("reference"))
) )
.map(r => { .map(r => {
r.relationType match { r.relationType match {
case ModelConstants.CITES | ModelConstants.REFERENCES => case Relation.RELCLASS.Cites.toString | Relation.RELCLASS.References.toString =>
val target = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType) val target = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType)
relation(id, target, ModelConstants.CITATION, ModelConstants.CITES, date) relation(id, target, Relation.SUBRELTYPE.citation, Relation.RELCLASS.Cites, date)
case ModelConstants.IS_CITED_BY | ModelConstants.IS_REFERENCED_BY => case Relation.RELCLASS.IsCitedBy.toString | Relation.RELCLASS.IsReferencedBy.toString =>
val source = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType) val source = DHPUtils.generateUnresolvedIdentifier(r.relatedIdentifier, r.relatedIdentifierType)
relation(source, id, ModelConstants.CITATION, ModelConstants.CITES, date) relation(source, id, Relation.SUBRELTYPE.citation, Relation.RELCLASS.Cites, date)
} }
}) })
citationRels ::: bidirectionalRels citationRels ::: bidirectionalRels
} }
def relation(source: String, target: String, subRelType: String, relClass: String, date: String): Relation = { def relation(source: String, target: String, subRelType: Relation.SUBRELTYPE, relClass: Relation.RELCLASS, date: String): Relation = {
val rel = new Relation val rel = new Relation
rel.setProvenance(Lists.newArrayList(OafMapperUtils.getProvenance(DATACITE_COLLECTED_FROM, relDataInfo))) rel.setProvenance(Lists.newArrayList(OafMapperUtils.getProvenance(DATACITE_COLLECTED_FROM, relDataInfo)))

View File

@ -14,7 +14,7 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import eu.dnetlib.dhp.schema.oaf.common.ModelSupport; import eu.dnetlib.dhp.schema.oaf.common.ModelSupport;
import eu.dnetlib.dhp.schema.oaf.common.RelationInverse; import eu.dnetlib.dhp.schema.oaf.common.RelationLabel;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -76,30 +76,22 @@ public class ReadBlacklistFromDB implements Closeable {
public List<Relation> processBlacklistEntry(ResultSet rs) { public List<Relation> processBlacklistEntry(ResultSet rs) {
try { try {
Relation direct = new Relation(); Relation direct = new Relation();
Relation inverse = new Relation();
String source_prefix = ModelSupport.entityIdPrefix.get(rs.getString("source_type")); String source_prefix = ModelSupport.entityIdPrefix.get(rs.getString("source_type"));
String target_prefix = ModelSupport.entityIdPrefix.get(rs.getString("target_type")); String target_prefix = ModelSupport.entityIdPrefix.get(rs.getString("target_type"));
String source_direct = source_prefix + "|" + rs.getString("source"); String source_direct = source_prefix + "|" + rs.getString("source");
direct.setSource(source_direct); direct.setSource(source_direct);
inverse.setTarget(source_direct);
String target_direct = target_prefix + "|" + rs.getString("target"); String target_direct = target_prefix + "|" + rs.getString("target");
direct.setTarget(target_direct); direct.setTarget(target_direct);
inverse.setSource(target_direct);
String encoding = rs.getString("relationship"); String encoding = rs.getString("relationship");
RelationInverse ri = ModelSupport.findInverse(encoding); final RelationLabel directLabel = ModelSupport.unRel(encoding);
direct.setRelClass(ri.getRelClass()); direct.setRelClass(directLabel.getRelClass());
inverse.setRelClass(ri.getInverseRelClass()); direct.setRelType(directLabel.getRelType());
direct.setRelType(ri.getRelType()); direct.setSubRelType(directLabel.getSubReltype());
inverse.setRelType(ri.getRelType()); return Arrays.asList(direct, direct.inverse());
direct.setSubRelType(ri.getSubReltype());
inverse.setSubRelType(ri.getSubReltype());
return Arrays.asList(direct, inverse);
} catch (final SQLException e) { } catch (final SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -5,7 +5,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import eu.dnetlib.dhp.schema.oaf.common.ModelSupport; import eu.dnetlib.dhp.schema.oaf.common.ModelSupport;
import eu.dnetlib.dhp.schema.oaf.common.RelationInverse; import eu.dnetlib.dhp.schema.oaf.common.RelationLabel;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -25,7 +25,7 @@ public class BlacklistRelationTest {
"resultProject_outcome_isProducedBy"); "resultProject_outcome_isProducedBy");
rels.forEach(r -> { rels.forEach(r -> {
RelationInverse inverse = ModelSupport.relationInverseMap.get(r); RelationLabel inverse = ModelSupport.relationInverseMap.get(r);
Assertions.assertNotNull(inverse); Assertions.assertNotNull(inverse);
Assertions.assertNotNull(inverse.getRelType()); Assertions.assertNotNull(inverse.getRelType());
Assertions.assertNotNull(inverse.getSubReltype()); Assertions.assertNotNull(inverse.getSubReltype());

View File

@ -203,9 +203,9 @@ object SparkGenerateDoiBoost {
val r: Relation = new Relation val r: Relation = new Relation
r.setSource(pub.getId) r.setSource(pub.getId)
r.setTarget(affId) r.setTarget(affId)
r.setRelType(ModelConstants.RESULT_ORGANIZATION) r.setRelType(Relation.RELTYPE.resultOrganization)
r.setRelClass(ModelConstants.HAS_AUTHOR_INSTITUTION) r.setRelClass(Relation.RELCLASS.hasAuthorInstitution)
r.setSubRelType(ModelConstants.AFFILIATION) r.setSubRelType(Relation.SUBRELTYPE.affiliation)
r.setProvenance(OafMapperUtils.getProvenance(pub.getCollectedfrom, dataInfo)) r.setProvenance(OafMapperUtils.getProvenance(pub.getCollectedfrom, dataInfo))
List(r) List(r)

View File

@ -11,7 +11,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.oaf.common.ModelSupport; import eu.dnetlib.dhp.schema.oaf.common.ModelSupport;
import eu.dnetlib.dhp.schema.oaf.common.RelationInverse; import eu.dnetlib.dhp.schema.oaf.common.RelationLabel;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
@ -401,7 +401,7 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper {
protected List<Oaf> getRelations(final String reltype, final String entityId, final String otherId, protected List<Oaf> getRelations(final String reltype, final String entityId, final String otherId,
final Entity entity) { final Entity entity) {
final List<Oaf> res = new ArrayList<>(); final List<Oaf> res = new ArrayList<>();
RelationInverse rel = ModelSupport.findRelation(reltype); RelationLabel rel = ModelSupport.findRelation(reltype);
if (rel != null) { if (rel != null) {
res res
.add( .add(