forked from D-Net/dnet-hadoop
Mapping all relationships supported in ModelConstants and ModelSupport
This commit is contained in:
parent
c5eb722170
commit
fd63e9bfac
|
@ -69,13 +69,15 @@ public abstract class AbstractMdRecordToOafMapper {
|
|||
nsContext.put("datacite", DATACITE_SCHEMA_KERNEL_3);
|
||||
}
|
||||
|
||||
protected static final Set<String> pidTypeWithAuthority = new HashSet<>();
|
||||
// lowercase pidTypes as keys, normal casing for the values
|
||||
protected static final Map<String, String> pidTypeWithAuthority = new HashMap<>();
|
||||
|
||||
static {
|
||||
pidTypeWithAuthority.addAll(IdentifierFactory.PID_AUTHORITY.keySet().stream()
|
||||
.map(PidType::toString)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toCollection(HashSet::new)));
|
||||
IdentifierFactory.PID_AUTHORITY
|
||||
.keySet()
|
||||
.stream()
|
||||
.forEach(entry -> pidTypeWithAuthority.put(entry.toString().toLowerCase(), entry.toString()));
|
||||
|
||||
}
|
||||
|
||||
protected AbstractMdRecordToOafMapper(final VocabularyGroup vocs, final boolean invisible,
|
||||
|
|
|
@ -22,6 +22,8 @@ import com.google.common.collect.Lists;
|
|||
|
||||
import eu.dnetlib.dhp.common.PacePerson;
|
||||
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
|
||||
import eu.dnetlib.dhp.schema.common.ModelSupport;
|
||||
import eu.dnetlib.dhp.schema.common.RelationInverse;
|
||||
import eu.dnetlib.dhp.schema.oaf.*;
|
||||
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
|
||||
import eu.dnetlib.dhp.schema.oaf.utils.IdentifierFactory;
|
||||
|
@ -400,71 +402,47 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper {
|
|||
|
||||
if (StringUtils.isNotBlank(originalId)) {
|
||||
final String idType = ((Node) o).valueOf("@relatedIdentifierType");
|
||||
final String reltype = ((Node) o).valueOf("@relationType");
|
||||
final String relType = ((Node) o).valueOf("@relationType");
|
||||
String otherId = guessRelatedIdentifier(idType, originalId);
|
||||
if (StringUtils.isNotBlank(otherId)) {
|
||||
if (reltype.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 (reltype.equalsIgnoreCase(IS_SUPPLEMENTED_BY)) {
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
otherId, docId, RESULT_RESULT, SUPPLEMENT, IS_SUPPLEMENT_TO, entity));
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
docId, otherId, RESULT_RESULT, SUPPLEMENT, IS_SUPPLEMENTED_BY, entity));
|
||||
} else {
|
||||
if (reltype.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 {
|
||||
if (reltype.equalsIgnoreCase(HAS_PART)) {
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
otherId, docId, RESULT_RESULT, PART, IS_PART_OF, entity));
|
||||
res
|
||||
.add(
|
||||
getRelation(
|
||||
docId, otherId, RESULT_RESULT, PART, HAS_PART, entity));
|
||||
}
|
||||
// else TODO catch more semantics
|
||||
}
|
||||
}
|
||||
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.contains(idType.toLowerCase())){
|
||||
return IdentifierFactory.idFromPid("50", idType, value, true);
|
||||
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,8 +579,10 @@ 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);
|
||||
assertTrue(list.get(1) instanceof Relation);
|
||||
assertTrue(list.get(2) instanceof Relation);
|
||||
|
||||
final Software s = (Software) list.get(0);
|
||||
|
||||
|
@ -590,6 +592,22 @@ class MappersTest {
|
|||
assertTrue(s.getAuthor().size() > 0);
|
||||
assertTrue(s.getSubject().size() > 0);
|
||||
assertTrue(s.getInstance().size() > 0);
|
||||
|
||||
final Relation r1 = (Relation) list.get(1);
|
||||
final Relation r2 = (Relation) list.get(2);
|
||||
|
||||
assertEquals(s.getId(), r1.getSource());
|
||||
assertEquals("50|doi_________::b453e7b4b2130ace57ff0c3db470a982", r1.getTarget());
|
||||
assertEquals(ModelConstants.RESULT_RESULT, r1.getRelType());
|
||||
assertEquals(ModelConstants.RELATIONSHIP, r1.getSubRelType());
|
||||
assertEquals(ModelConstants.IS_REFERENCED_BY, r1.getRelClass());
|
||||
|
||||
assertEquals(s.getId(), r2.getTarget());
|
||||
assertEquals("50|doi_________::b453e7b4b2130ace57ff0c3db470a982", r2.getSource());
|
||||
assertEquals(ModelConstants.RESULT_RESULT, r2.getRelType());
|
||||
assertEquals(ModelConstants.RELATIONSHIP, r2.getSubRelType());
|
||||
assertEquals(ModelConstants.REFERENCES, r2.getRelClass());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue