no need to compute the inverse relClass, fixed text() in xpath expressions

This commit is contained in:
Claudio Atzori 2020-03-05 12:51:48 +01:00
parent 6ec04d4e02
commit 5e342a555c
2 changed files with 7 additions and 40 deletions

View File

@ -40,34 +40,6 @@ public class GraphMappingUtils {
public static Set<String> instanceFieldFilter = Sets.newHashSet("instancetype", "hostedby", "license", "accessright", "collectedfrom", "dateofacceptance", "distributionlocation"); public static Set<String> instanceFieldFilter = Sets.newHashSet("instancetype", "hostedby", "license", "accessright", "collectedfrom", "dateofacceptance", "distributionlocation");
private static BiMap<String, String> 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 final String schemeTemplate = "dnet:%s_%s_relations";
private static Map<EntityType, MainEntityType> entityMapping = Maps.newHashMap(); private static Map<EntityType, MainEntityType> entityMapping = Maps.newHashMap();

View File

@ -727,13 +727,8 @@ public class XmlRecordFactory implements Serializable {
} }
final DataInfo info = rel.getDataInfo(); final DataInfo info = rel.getDataInfo();
final String inverseRelClass = getInverseRelClass(rel.getRelClass());
final String scheme = getScheme(re.getType(), targetType); final String scheme = getScheme(re.getType(), targetType);
if (StringUtils.isBlank(inverseRelClass)) {
throw new IllegalArgumentException("missing inverse for: " + rel.getRelClass());
}
if (StringUtils.isBlank(scheme)) { if (StringUtils.isBlank(scheme)) {
throw new IllegalArgumentException(String.format("missing scheme for: <%s - %s>", re.getType(), targetType)); throw new IllegalArgumentException(String.format("missing scheme for: <%s - %s>", re.getType(), targetType));
} }
@ -747,7 +742,7 @@ public class XmlRecordFactory implements Serializable {
targetType, targetType,
rel.getTarget(), rel.getTarget(),
Sets.newHashSet(metadata), Sets.newHashSet(metadata),
inverseRelClass, rel.getRelClass(),
scheme, scheme,
info)); info));
} }
@ -961,7 +956,7 @@ public class XmlRecordFactory implements Serializable {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private String getRelFundingTree(final String xmlTree) { protected static String getRelFundingTree(final String xmlTree) {
String funding = "<funding>"; String funding = "<funding>";
try { try {
final Document ftree = new SAXReader().read(new StringReader(xmlTree)); final Document ftree = new SAXReader().read(new StringReader(xmlTree));
@ -982,11 +977,11 @@ public class XmlRecordFactory implements Serializable {
return funding; return funding;
} }
private String getFunderElement(final Document ftree) { private static String getFunderElement(final Document ftree) {
final String funderId = ftree.valueOf("//fundingtree/funder/id/text()"); final String funderId = ftree.valueOf("//fundingtree/funder/id");
final String funderShortName = ftree.valueOf("//fundingtree/funder/shortname/text()"); final String funderShortName = ftree.valueOf("//fundingtree/funder/shortname");
final String funderName = ftree.valueOf("//fundingtree/funder/name/text()"); final String funderName = ftree.valueOf("//fundingtree/funder/name");
final String funderJurisdiction = ftree.valueOf("//fundingtree/funder/jurisdiction/text()"); final String funderJurisdiction = ftree.valueOf("//fundingtree/funder/jurisdiction");
return "<funder id=\"" + escapeXml(funderId) + "\" shortname=\"" + escapeXml(funderShortName) + "\" name=\"" + escapeXml(funderName) return "<funder id=\"" + escapeXml(funderId) + "\" shortname=\"" + escapeXml(funderShortName) + "\" name=\"" + escapeXml(funderName)
+ "\" jurisdiction=\"" + escapeXml(funderJurisdiction) + "\" />"; + "\" jurisdiction=\"" + escapeXml(funderJurisdiction) + "\" />";