-Renamed RelationInverse into RelationLabel.
-Removed findRelation from ModelSupport -code formatted
This commit is contained in:
parent
8c9a77d7eb
commit
f8f4b9a018
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue