From 5e342a555cf736b15d1c9da83e0a85e4ae8ed104 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Thu, 5 Mar 2020 12:51:48 +0100 Subject: [PATCH] no need to compute the inverse relClass, fixed text() in xpath expressions --- .../dhp/graph/utils/GraphMappingUtils.java | 28 ------------------- .../dhp/graph/utils/XmlRecordFactory.java | 19 +++++-------- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/GraphMappingUtils.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/GraphMappingUtils.java index 2069ad9f7..bd1896b75 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/GraphMappingUtils.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/GraphMappingUtils.java @@ -40,34 +40,6 @@ public class GraphMappingUtils { public static Set instanceFieldFilter = Sets.newHashSet("instancetype", "hostedby", "license", "accessright", "collectedfrom", "dateofacceptance", "distributionlocation"); - private static BiMap relClassMapping = HashBiMap.create(); - - static { - relClassMapping.put("isAuthorInstitutionOf", "hasAuthorInstitution"); - relClassMapping.put("isMergedIn", "merges"); - relClassMapping.put("isProducedBy", "produces"); - relClassMapping.put("hasParticipant", "isParticipant"); - relClassMapping.put("isProvidedBy", "provides"); - relClassMapping.put("isRelatedTo", "isRelatedTo"); - relClassMapping.put("isAmongTopNSimilarDocuments", "hasAmongTopNSimilarDocuments"); - relClassMapping.put("isRelatedTo", "isRelatedTo"); - relClassMapping.put("isSupplementTo", "isSupplementedBy"); - } - - public static String getInverseRelClass(final String relClass) { - String res = relClassMapping.get(relClass); - if (isNotBlank(res)) { - return res; - } - res = relClassMapping.inverse().get(relClass); - - if (isNotBlank(res)) { - return res; - } - - throw new IllegalArgumentException("unable to find an inverse relationship class for term: " + relClass); - } - private static final String schemeTemplate = "dnet:%s_%s_relations"; private static Map entityMapping = Maps.newHashMap(); diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/XmlRecordFactory.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/XmlRecordFactory.java index b8ffd7f7a..55c5c1d3c 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/XmlRecordFactory.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/graph/utils/XmlRecordFactory.java @@ -727,13 +727,8 @@ public class XmlRecordFactory implements Serializable { } final DataInfo info = rel.getDataInfo(); - - final String inverseRelClass = getInverseRelClass(rel.getRelClass()); final String scheme = getScheme(re.getType(), targetType); - if (StringUtils.isBlank(inverseRelClass)) { - throw new IllegalArgumentException("missing inverse for: " + rel.getRelClass()); - } if (StringUtils.isBlank(scheme)) { throw new IllegalArgumentException(String.format("missing scheme for: <%s - %s>", re.getType(), targetType)); } @@ -747,7 +742,7 @@ public class XmlRecordFactory implements Serializable { targetType, rel.getTarget(), Sets.newHashSet(metadata), - inverseRelClass, + rel.getRelClass(), scheme, info)); } @@ -961,7 +956,7 @@ public class XmlRecordFactory implements Serializable { @SuppressWarnings("unchecked") - private String getRelFundingTree(final String xmlTree) { + protected static String getRelFundingTree(final String xmlTree) { String funding = ""; try { final Document ftree = new SAXReader().read(new StringReader(xmlTree)); @@ -982,11 +977,11 @@ public class XmlRecordFactory implements Serializable { return funding; } - private String getFunderElement(final Document ftree) { - final String funderId = ftree.valueOf("//fundingtree/funder/id/text()"); - final String funderShortName = ftree.valueOf("//fundingtree/funder/shortname/text()"); - final String funderName = ftree.valueOf("//fundingtree/funder/name/text()"); - final String funderJurisdiction = ftree.valueOf("//fundingtree/funder/jurisdiction/text()"); + private static String getFunderElement(final Document ftree) { + final String funderId = ftree.valueOf("//fundingtree/funder/id"); + final String funderShortName = ftree.valueOf("//fundingtree/funder/shortname"); + final String funderName = ftree.valueOf("//fundingtree/funder/name"); + final String funderJurisdiction = ftree.valueOf("//fundingtree/funder/jurisdiction"); return "";