added new relation labels in the relationInverseMap

This commit is contained in:
Claudio Atzori 2021-10-18 12:07:29 +02:00
parent c6efa75fbb
commit bc7828cdee
2 changed files with 71 additions and 213 deletions

View File

@ -2,6 +2,7 @@
package eu.dnetlib.dhp.schema.common; package eu.dnetlib.dhp.schema.common;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static eu.dnetlib.dhp.schema.common.ModelConstants.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -98,211 +99,68 @@ public class ModelSupport {
public static final Map<String, RelationInverse> relationInverseMap = Maps.newHashMap(); public static final Map<String, RelationInverse> relationInverseMap = Maps.newHashMap();
static { static {
relationInverseMap set(relationInverseMap, PROJECT_ORGANIZATION, PARTICIPATION, IS_PARTICIPANT, HAS_PARTICIPANT);
.put(
"personResult_authorship_isAuthorOf", new RelationInverse()
.setRelation("isAuthorOf")
.setInverse("hasAuthor")
.setRelType("personResult")
.setSubReltype("authorship"));
relationInverseMap
.put(
"personResult_authorship_hasAuthor", new RelationInverse()
.setInverse("isAuthorOf")
.setRelation("hasAuthor")
.setRelType("personResult")
.setSubReltype("authorship"));
relationInverseMap
.put(
"projectOrganization_participation_isParticipant", new RelationInverse()
.setRelation(ModelConstants.IS_PARTICIPANT)
.setInverse(ModelConstants.HAS_PARTICIPANT)
.setRelType(ModelConstants.PROJECT_ORGANIZATION)
.setSubReltype(ModelConstants.PARTICIPATION));
relationInverseMap
.put(
"projectOrganization_participation_hasParticipant", new RelationInverse()
.setInverse(ModelConstants.IS_PARTICIPANT)
.setRelation(ModelConstants.HAS_PARTICIPANT)
.setRelType(ModelConstants.PROJECT_ORGANIZATION)
.setSubReltype(ModelConstants.PARTICIPATION));
relationInverseMap
.put(
"resultOrganization_affiliation_hasAuthorInstitution", new RelationInverse()
.setRelation(ModelConstants.HAS_AUTHOR_INSTITUTION)
.setInverse(ModelConstants.IS_AUTHOR_INSTITUTION_OF)
.setRelType(ModelConstants.RESULT_ORGANIZATION)
.setSubReltype(ModelConstants.AFFILIATION));
relationInverseMap
.put(
"resultOrganization_affiliation_isAuthorInstitutionOf", new RelationInverse()
.setInverse(ModelConstants.HAS_AUTHOR_INSTITUTION)
.setRelation(ModelConstants.IS_AUTHOR_INSTITUTION_OF)
.setRelType(ModelConstants.RESULT_ORGANIZATION)
.setSubReltype(ModelConstants.AFFILIATION));
relationInverseMap
.put(
"organizationOrganization_dedup_merges", new RelationInverse()
.setRelation(ModelConstants.MERGES)
.setInverse(ModelConstants.IS_MERGED_IN)
.setRelType(ModelConstants.ORG_ORG_RELTYPE)
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"organizationOrganization_dedup_isMergedIn", new RelationInverse()
.setInverse(ModelConstants.MERGES)
.setRelation(ModelConstants.IS_MERGED_IN)
.setRelType(ModelConstants.ORG_ORG_RELTYPE)
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"organizationOrganization_dedupSimilarity_isSimilarTo", new RelationInverse()
.setInverse(ModelConstants.IS_SIMILAR_TO)
.setRelation(ModelConstants.IS_SIMILAR_TO)
.setRelType(ModelConstants.ORG_ORG_RELTYPE)
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap set(relationInverseMap, RESULT_ORGANIZATION, AFFILIATION, IS_AUTHOR_INSTITUTION_OF, HAS_AUTHOR_INSTITUTION);
.put(
"resultProject_outcome_isProducedBy", new RelationInverse()
.setRelation(ModelConstants.IS_PRODUCED_BY)
.setInverse(ModelConstants.PRODUCES)
.setRelType(ModelConstants.RESULT_PROJECT)
.setSubReltype(ModelConstants.OUTCOME));
relationInverseMap
.put(
"resultProject_outcome_produces", new RelationInverse()
.setInverse(ModelConstants.IS_PRODUCED_BY)
.setRelation(ModelConstants.PRODUCES)
.setRelType(ModelConstants.RESULT_PROJECT)
.setSubReltype(ModelConstants.OUTCOME));
relationInverseMap
.put(
"projectPerson_contactPerson_isContact", new RelationInverse()
.setRelation("isContact")
.setInverse("hasContact")
.setRelType("projectPerson")
.setSubReltype("contactPerson"));
relationInverseMap
.put(
"projectPerson_contactPerson_hasContact", new RelationInverse()
.setInverse("isContact")
.setRelation("hasContact")
.setRelType("personPerson")
.setSubReltype("coAuthorship"));
relationInverseMap
.put(
"personPerson_coAuthorship_isCoauthorOf", new RelationInverse()
.setInverse("isCoAuthorOf")
.setRelation("isCoAuthorOf")
.setRelType("personPerson")
.setSubReltype("coAuthorship"));
relationInverseMap
.put(
"personPerson_dedup_merges", new RelationInverse()
.setInverse(ModelConstants.IS_MERGED_IN)
.setRelation(ModelConstants.MERGES)
.setRelType("personPerson")
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"personPerson_dedup_isMergedIn", new RelationInverse()
.setInverse(ModelConstants.MERGES)
.setRelation(ModelConstants.IS_MERGED_IN)
.setRelType("personPerson")
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"personPerson_dedupSimilarity_isSimilarTo", new RelationInverse()
.setInverse(ModelConstants.IS_SIMILAR_TO)
.setRelation(ModelConstants.IS_SIMILAR_TO)
.setRelType("personPerson")
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"datasourceOrganization_provision_isProvidedBy", new RelationInverse()
.setInverse(ModelConstants.PROVIDES)
.setRelation(ModelConstants.IS_PROVIDED_BY)
.setRelType(ModelConstants.DATASOURCE_ORGANIZATION)
.setSubReltype(ModelConstants.PROVISION));
relationInverseMap
.put(
"datasourceOrganization_provision_provides", new RelationInverse()
.setInverse(ModelConstants.IS_PROVIDED_BY)
.setRelation(ModelConstants.PROVIDES)
.setRelType(ModelConstants.DATASOURCE_ORGANIZATION)
.setSubReltype(ModelConstants.PROVISION));
relationInverseMap
.put(
"resultResult_similarity_hasAmongTopNSimilarDocuments", new RelationInverse()
.setInverse("isAmongTopNSimilarDocuments")
.setRelation("hasAmongTopNSimilarDocuments")
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.SIMILARITY));
relationInverseMap
.put(
"resultResult_similarity_isAmongTopNSimilarDocuments", new RelationInverse()
.setInverse("hasAmongTopNSimilarDocuments")
.setRelation("isAmongTopNSimilarDocuments")
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.SIMILARITY));
relationInverseMap
.put(
"resultResult_relationship_isRelatedTo", new RelationInverse()
.setInverse(ModelConstants.IS_RELATED_TO)
.setRelation(ModelConstants.IS_RELATED_TO)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.RELATIONSHIP));
relationInverseMap
.put(
"resultResult_supplement_isSupplementTo", new RelationInverse()
.setInverse(ModelConstants.IS_SUPPLEMENTED_BY)
.setRelation(ModelConstants.IS_SUPPLEMENT_TO)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.SUPPLEMENT));
relationInverseMap
.put(
"resultResult_supplement_isSupplementedBy", new RelationInverse()
.setInverse(ModelConstants.IS_SUPPLEMENT_TO)
.setRelation(ModelConstants.IS_SUPPLEMENTED_BY)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.SUPPLEMENT));
relationInverseMap
.put(
"resultResult_part_isPartOf", new RelationInverse()
.setInverse(ModelConstants.HAS_PART)
.setRelation(ModelConstants.IS_PART_OF)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.PART));
relationInverseMap
.put(
"resultResult_part_hasPart", new RelationInverse()
.setInverse(ModelConstants.IS_PART_OF)
.setRelation(ModelConstants.HAS_PART)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.PART));
relationInverseMap
.put(
"resultResult_dedup_merges", new RelationInverse()
.setInverse(ModelConstants.IS_MERGED_IN)
.setRelation(ModelConstants.MERGES)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"resultResult_dedup_isMergedIn", new RelationInverse()
.setInverse(ModelConstants.MERGES)
.setRelation(ModelConstants.IS_MERGED_IN)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.DEDUP));
relationInverseMap
.put(
"resultResult_dedupSimilarity_isSimilarTo", new RelationInverse()
.setInverse(ModelConstants.IS_SIMILAR_TO)
.setRelation(ModelConstants.IS_SIMILAR_TO)
.setRelType(ModelConstants.RESULT_RESULT)
.setSubReltype(ModelConstants.DEDUP));
set(relationInverseMap, ORG_ORG_RELTYPE, DEDUP, IS_MERGED_IN, MERGES);
set(relationInverseMap, ORG_ORG_RELTYPE, DEDUP, IS_SIMILAR_TO, IS_SIMILAR_TO);
set(relationInverseMap, RESULT_PROJECT, OUTCOME, IS_PRODUCED_BY, PRODUCES);
set(relationInverseMap, DATASOURCE_ORGANIZATION, PROVISION, IS_PROVIDED_BY, PROVIDES);
set(relationInverseMap, RESULT_RESULT, SIMILARITY, IS_AMONG_TOP_N_SIMILAR_DOCS, HAS_AMONG_TOP_N_SIMILAR_DOCS);
set(relationInverseMap, RESULT_RESULT, SUPPLEMENT, IS_SUPPLEMENT_TO, IS_SUPPLEMENTED_BY);
set(relationInverseMap, RESULT_RESULT, PART, IS_PART_OF, HAS_PART);
set(relationInverseMap, RESULT_RESULT, DEDUP, IS_MERGED_IN, MERGES);
set(relationInverseMap, RESULT_RESULT, DEDUP, IS_SIMILAR_TO, IS_SIMILAR_TO);
set(relationInverseMap, RESULT_RESULT, CITATION, IS_CITED_BY, CITES);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_IDENTICAL_TO, IS_IDENTICAL_TO);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_REFERENCED_BY, REFERENCES);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_CONTINUED_BY, CONTINUES);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_DOCUMENTED_BY, DOCUMENTS);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_DERIVED_FROM, IS_SOURCE_OF);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO, IS_RELATED_TO);
set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_COMPILED_BY, COMPILES);
set(relationInverseMap, RESULT_RESULT, VERSION, IS_PREVIOUS_VERSION_OF, IS_NEW_VERSION_OF);
set(relationInverseMap, RESULT_RESULT, VERSION, IS_VARIANT_FORM_OF, IS_ORIGINAL_FORM_OF);
set(relationInverseMap, RESULT_RESULT, VERSION, IS_OBSOLETED_BY, OBSOLETES);
set(relationInverseMap, RESULT_RESULT, VERSION, IS_VERSION_OF, HAS_VERSION);
set(relationInverseMap, RESULT_RESULT, REVIEW, IS_REVIEWED_BY, REVIEWS);
}
private static void set(Map<String, RelationInverse> relationInverseMap, String relType, String subRelType, String relClass, String inverseRelClass) {
relationInverseMap
.put(
rel(relType, subRelType, relClass), new RelationInverse()
.setInverseRelClass(inverseRelClass)
.setRelClass(relClass)
.setRelType(relType)
.setSubReltype(subRelType));
if (!relClass.equals(inverseRelClass)) {
relationInverseMap
.put(
rel(relType, subRelType, inverseRelClass), new RelationInverse()
.setInverseRelClass(relClass)
.setRelClass(inverseRelClass)
.setRelType(relType)
.setSubReltype(subRelType));
}
}
/**
* Helper method: combines the relation attributes
* @param relType
* @param subRelType
* @param relClass
* @return
*/
public static String rel(String relType, String subRelType, String relClass) {
return String.format("%-%-%", relType, subRelType, relClass);
} }
private static final String schemeTemplate = "dnet:%s_%s_relations"; private static final String schemeTemplate = "dnet:%s_%s_relations";

View File

@ -2,8 +2,8 @@
package eu.dnetlib.dhp.schema.common; package eu.dnetlib.dhp.schema.common;
public class RelationInverse { public class RelationInverse {
private String relation; private String relClass;
private String inverse; private String inverseRelClass;
private String relType; private String relType;
private String subReltype; private String subReltype;
@ -25,21 +25,21 @@ public class RelationInverse {
return this; return this;
} }
public String getRelation() { public String getRelClass() {
return relation; return relClass;
} }
public RelationInverse setRelation(String relation) { public RelationInverse setRelClass(String relClass) {
this.relation = relation; this.relClass = relClass;
return this; return this;
} }
public String getInverse() { public String getInverseRelClass() {
return inverse; return inverseRelClass;
} }
public RelationInverse setInverse(String inverse) { public RelationInverse setInverseRelClass(String inverseRelClass) {
this.inverse = inverse; this.inverseRelClass = inverseRelClass;
return this; return this;
} }