forked from D-Net/dnet-hadoop
extended mapping from ODF relations (PR#251)
This commit is contained in:
parent
a929dc5fee
commit
eb45ba7af0
|
@ -72,6 +72,17 @@ public abstract class AbstractMdRecordToOafMapper {
|
|||
nsContext.put("datacite", DATACITE_SCHEMA_KERNEL_3);
|
||||
}
|
||||
|
||||
// lowercase pidTypes as keys, normal casing for the values
|
||||
protected static final Map<String, String> pidTypeWithAuthority = new HashMap<>();
|
||||
|
||||
static {
|
||||
IdentifierFactory.PID_AUTHORITY
|
||||
.keySet()
|
||||
.stream()
|
||||
.forEach(entry -> pidTypeWithAuthority.put(entry.toString().toLowerCase(), entry.toString()));
|
||||
|
||||
}
|
||||
|
||||
protected AbstractMdRecordToOafMapper(final VocabularyGroup vocs, final boolean invisible,
|
||||
final boolean shouldHashId, final boolean forceOriginalId) {
|
||||
this.vocs = vocs;
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.net.URLDecoder;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import eu.dnetlib.dhp.schema.common.ModelSupport;
|
||||
import eu.dnetlib.dhp.schema.common.RelationInverse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
@ -377,48 +379,61 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper {
|
|||
|
||||
@Override
|
||||
protected List<Oaf> addOtherResultRels(
|
||||
final Document doc,
|
||||
final OafEntity entity) {
|
||||
final Document doc,
|
||||
final OafEntity entity) {
|
||||
|
||||
final String docId = entity.getId();
|
||||
|
||||
final List<Oaf> res = new ArrayList<>();
|
||||
|
||||
for (final Object o : doc
|
||||
.selectNodes("//*[local-name()='relatedIdentifier' and ./@relatedIdentifierType='OPENAIRE']")) {
|
||||
.selectNodes("//*[local-name()='relatedIdentifier']")) {
|
||||
|
||||
final String originalId = ((Node) o).getText();
|
||||
final String originalId = ((Node) o).getText().trim();
|
||||
|
||||
if (StringUtils.isNotBlank(originalId)) {
|
||||
final String otherId = createOpenaireId(50, originalId, false);
|
||||
final String type = ((Node) o).valueOf("@relationType");
|
||||
|
||||
if (type.equalsIgnoreCase(IS_SUPPLEMENT_TO)) {
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
docId, otherId, RESULT_RESULT, SUPPLEMENT, IS_SUPPLEMENT_TO, entity));
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
otherId, docId, RESULT_RESULT, SUPPLEMENT, IS_SUPPLEMENTED_BY, entity));
|
||||
} else if (type.equalsIgnoreCase(IS_PART_OF)) {
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
docId, otherId, RESULT_RESULT, PART, IS_PART_OF, entity));
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
otherId, docId, RESULT_RESULT, PART, HAS_PART, entity));
|
||||
} else {
|
||||
// TODO catch more semantics
|
||||
final String idType = ((Node) o).valueOf("@relatedIdentifierType");
|
||||
final String relType = ((Node) o).valueOf("@relationType");
|
||||
String otherId = guessRelatedIdentifier(idType, originalId);
|
||||
if (StringUtils.isNotBlank(otherId)) {
|
||||
res.addAll(getRelations(relType, docId, otherId, entity));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected String guessRelatedIdentifier(final String idType, final String value) {
|
||||
if (StringUtils.isBlank(idType) || StringUtils.isBlank(value))
|
||||
return null;
|
||||
if (idType.equalsIgnoreCase("OPENAIRE"))
|
||||
return createOpenaireId(50, value, false);
|
||||
if (pidTypeWithAuthority.containsKey(idType.toLowerCase())) {
|
||||
return IdentifierFactory.idFromPid("50", pidTypeWithAuthority.get(idType.toLowerCase()), value, true);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
protected List<Oaf> getRelations(final String reltype, final String entityId, final String otherId,
|
||||
final OafEntity entity) {
|
||||
final List<Oaf> res = new ArrayList<>();
|
||||
RelationInverse rel = ModelSupport.findRelation(reltype);
|
||||
if (rel != null) {
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
entityId, otherId, rel.getRelType(), rel.getSubReltype(), rel.getRelClass(), entity));
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
otherId, entityId, rel.getRelType(), rel.getSubReltype(), rel.getInverseRelClass(), entity));
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Qualifier prepareResourceType(final Document doc, final DataInfo info) {
|
||||
return prepareQualifier(
|
||||
|
|
|
@ -579,7 +579,7 @@ class MappersTest {
|
|||
|
||||
final List<Oaf> list = new OdfToOafMapper(vocs, false, true).processMdRecord(xml);
|
||||
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(3, list.size());
|
||||
assertTrue(list.get(0) instanceof Software);
|
||||
|
||||
final Software s = (Software) list.get(0);
|
||||
|
@ -918,7 +918,7 @@ class MappersTest {
|
|||
System.out.println("***************");
|
||||
System.out.println(new ObjectMapper().writeValueAsString(list));
|
||||
System.out.println("***************");
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(5, list.size());
|
||||
final OtherResearchProduct p = (OtherResearchProduct) list.get(0);
|
||||
assertValidId(p.getId());
|
||||
assertTrue(p.getId().startsWith("50|w3id"));
|
||||
|
@ -945,7 +945,7 @@ class MappersTest {
|
|||
System.out.println("***************");
|
||||
System.out.println(new ObjectMapper().writeValueAsString(list));
|
||||
System.out.println("***************");
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(7, list.size());
|
||||
final OtherResearchProduct p = (OtherResearchProduct) list.get(0);
|
||||
assertValidId(p.getId());
|
||||
assertValidId(p.getCollectedfrom().get(0).getKey());
|
||||
|
@ -955,7 +955,7 @@ class MappersTest {
|
|||
assertEquals("https://w3id.org/ro-id/0ab171a7-45c5-4194-82d4-850955504bca", (p.getPid().get(0).getValue()));
|
||||
|
||||
assertEquals(1, list.stream().filter(o -> o instanceof OtherResearchProduct).count());
|
||||
assertEquals(0, list.stream().filter(o -> o instanceof Relation).count());
|
||||
assertEquals(6, list.stream().filter(o -> o instanceof Relation).count());
|
||||
|
||||
for (Oaf oaf : list) {
|
||||
if (oaf instanceof Relation) {
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
</dates>
|
||||
<resourceType resourceTypeGeneral="Dataset"/>
|
||||
<relatedIdentifiers>
|
||||
<relatedIdentifier relatedIdentifierType="DOI" relationType="IsVersionOf">10.5281/zenodo.3234525</relatedIdentifier>
|
||||
<relatedIdentifier relatedIdentifierType="URL" relationType="IsPartOf">https://zenodo.org/communities/epfl</relatedIdentifier>
|
||||
</relatedIdentifiers>
|
||||
<version>1.0.0</version>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<datacite:publisher>bio.tools</datacite:publisher>
|
||||
<datacite:relatedIdentifiers>
|
||||
<datacite:relatedIdentifier relatedIdentifierType="URL" relationType="IsDocumentedBy">http://maplab.imppc.org/chainy/</datacite:relatedIdentifier>
|
||||
<datacite:relatedIdentifier relatedIdentifierType="DOI" relationType="isReferencedBy">10.1093/bioinformatics/btw839</datacite:relatedIdentifier>
|
||||
<datacite:relatedIdentifier relatedIdentifierType="DOI" relationType="isreferencedBy">10.1093/bioinformatics/btw839</datacite:relatedIdentifier>
|
||||
</datacite:relatedIdentifiers>
|
||||
<datacite:alternateIdentifiers>
|
||||
<datacite:alternateIdentifier alternateIdentifierType="LandingPage">https://bio.tools/</datacite:alternateIdentifier>
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
<datacite:relatedIdentifier relatedIdentifierType="w3id" relationType="HasPart">
|
||||
https://w3id.org/ro-id/0ab171a7-45c5-4194-82d4-850955504bca/resources/6d3427a8-352e-49f4-9796-f618c44dc16d
|
||||
</datacite:relatedIdentifier>
|
||||
<datacite:relatedIdentifier relatedIdentifierType="OPENAIRE" relationType="isSupplementedBy">
|
||||
fsh_____4119::afc7592914ae190a50570db90f55f9c3
|
||||
</datacite:relatedIdentifier>
|
||||
</datacite:relatedIdentifiers>
|
||||
<datacite:resourceType xs:anyURI="http://purl.org/coar/resource_type/c_1843">RO-crate</datacite:resourceType>
|
||||
<datacite:rightsList>
|
||||
|
|
Loading…
Reference in New Issue