diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java index bb5472a882..5f185444f2 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java @@ -69,14 +69,16 @@ public abstract class AbstractMdRecordToOafMapper { nsContext.put("datacite", DATACITE_SCHEMA_KERNEL_3); } - protected static final Set pidTypeWithAuthority = new HashSet<>(); + // lowercase pidTypes as keys, normal casing for the values + protected static final Map 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, final boolean shouldHashId, final boolean forceOriginalId) { diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java index 304ec8f993..a25bcd47e8 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java @@ -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,55 +402,12 @@ 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; @@ -457,14 +416,33 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper { 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 getRelations(final String reltype, final String entityId, final String otherId, + final OafEntity entity) { + final List 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( diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java index 32b23e42f8..7552d1789c 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java @@ -579,8 +579,10 @@ class MappersTest { final List 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 @@ -945,14 +963,14 @@ class MappersTest { assertEquals(1, list.stream().filter(o -> o instanceof OtherResearchProduct).count()); assertEquals(6, list.stream().filter(o -> o instanceof Relation).count()); - for(Oaf oaf : list){ - if(oaf instanceof Relation){ + for (Oaf oaf : list) { + if (oaf instanceof Relation) { String source = ((Relation) oaf).getSource(); String target = ((Relation) oaf).getTarget(); assertNotEquals(source, target); assertTrue(source.equals(p.getId()) || target.equals(p.getId())); assertNotNull(((Relation) oaf).getSubRelType()); - assertNotNull( ((Relation) oaf).getRelClass()); + assertNotNull(((Relation) oaf).getRelClass()); assertNotNull(((Relation) oaf).getRelType()); } } diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_dataset.xml b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_dataset.xml index 4f41ee6eac..4633d62c39 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_dataset.xml +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_dataset.xml @@ -69,7 +69,6 @@ - 10.5281/zenodo.3234525 https://zenodo.org/communities/epfl 1.0.0 diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_software.xml b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_software.xml index 6a9170ce17..387b1ee866 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_software.xml +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/odf_software.xml @@ -20,7 +20,7 @@ bio.tools http://maplab.imppc.org/chainy/ - 10.1093/bioinformatics/btw839 + 10.1093/bioinformatics/btw839 https://bio.tools/