diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java index 2b1c257ad4..c69a7a6ffa 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java @@ -422,7 +422,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final Relation r2 = OafMapperUtils .getRelation( - orgId, dsId, DATASOURCE_ORGANIZATION, PROVISION, PROVIDES, collectedFrom, info, lastUpdateTimestamp); + orgId, dsId, DATASOURCE_ORGANIZATION, PROVISION, PROVIDES, collectedFrom, info, + lastUpdateTimestamp); return Arrays.asList(r1, r2); } catch (final Exception e) { 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 7d615a1f09..fc063a242c 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 @@ -25,6 +25,7 @@ import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; import eu.dnetlib.dhp.schema.oaf.*; import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions; import eu.dnetlib.dhp.schema.oaf.utils.IdentifierFactory; +import eu.dnetlib.dhp.schema.oaf.utils.PidType; public class OdfToOafMapper extends AbstractMdRecordToOafMapper { @@ -391,75 +392,77 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper { final String docId = entity.getId(); final List res = new ArrayList<>(); - /* - /* - - https://w3id.org/ro-id/13c54585-362e-4925-a785-08afb591fa0d/resources/b4be0f3e-41d7-471f-b34e-f0bd54ff5698 - https://w3id.org/ro-id/13c54585-362e-4925-a785-08afb591fa0d/resources/5d6e575b-ef84-417a-9d76-61c6702f7cb2 - https://w3id.org/ro-id/13c54585-362e-4925-a785-08afb591fa0d/resources/35e01545-8c6d-49bd-ab98-5c152df69934 - - We could extend it to create the relationships targeting w3id, dois, pmcids and other pid types for which we know how to build the target openaire identifier "blindly". - - for (final Object o : doc - .selectNodes("//*[local-name()='relatedIdentifier']")) { + .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"); - switch(type){ - case IS_SUPPLEMENT_TO: - break; - case SUPPLEMENT: - break; - case IS_PART_OF: - break; - case HAS_PART: - break; + final String idType = ((Node) o).valueOf("@relatedIdentifierType"); + 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 + } + } + } - - } - - */ - - for (final Object o : doc - .selectNodes("//*[local-name()='relatedIdentifier' and ./@relatedIdentifierType='OPENAIRE']")) { - - final String originalId = ((Node) o).getText(); - - 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 } } } 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); + } else + return null; + } + @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 b163ecff3a..fbfbf5af8a 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 @@ -933,6 +933,7 @@ class MappersTest { System.out.println("***************"); System.out.println(new ObjectMapper().writeValueAsString(list)); System.out.println("***************"); + assertEquals(3, list.size()); final OtherResearchProduct p = (OtherResearchProduct) list.get(0); assertValidId(p.getId()); assertValidId(p.getCollectedfrom().get(0).getKey()); diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/rohub-modified.xml b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/rohub-modified.xml index 95d65ac8d5..ce846a2cf9 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/rohub-modified.xml +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/rohub-modified.xml @@ -30,6 +30,9 @@ https://w3id.org/ro-id/0ab171a7-45c5-4194-82d4-850955504bca/resources/6d3427a8-352e-49f4-9796-f618c44dc16d + + fsh_____4119::afc7592914ae190a50570db90f55f9c3 + RO-crate