forked from antonis.lempesis/dnet-hadoop
added new information in support of blacklist reader
This commit is contained in:
parent
6a47e6191d
commit
564e5d6279
|
@ -1,364 +1,431 @@
|
||||||
|
|
||||||
package eu.dnetlib.dhp.schema.common;
|
package eu.dnetlib.dhp.schema.common;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import eu.dnetlib.dhp.schema.oaf.*;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.*;
|
||||||
|
|
||||||
/** Oaf model utility methods. */
|
/** Oaf model utility methods. */
|
||||||
public class ModelSupport {
|
public class ModelSupport {
|
||||||
|
|
||||||
/** Defines the mapping between the actual entity type and the main entity type */
|
/** Defines the mapping between the actual entity type and the main entity type */
|
||||||
private static Map<EntityType, MainEntityType> entityMapping = Maps.newHashMap();
|
private static Map<EntityType, MainEntityType> entityMapping = Maps.newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
entityMapping.put(EntityType.publication, MainEntityType.result);
|
entityMapping.put(EntityType.publication, MainEntityType.result);
|
||||||
entityMapping.put(EntityType.dataset, MainEntityType.result);
|
entityMapping.put(EntityType.dataset, MainEntityType.result);
|
||||||
entityMapping.put(EntityType.otherresearchproduct, MainEntityType.result);
|
entityMapping.put(EntityType.otherresearchproduct, MainEntityType.result);
|
||||||
entityMapping.put(EntityType.software, MainEntityType.result);
|
entityMapping.put(EntityType.software, MainEntityType.result);
|
||||||
entityMapping.put(EntityType.datasource, MainEntityType.datasource);
|
entityMapping.put(EntityType.datasource, MainEntityType.datasource);
|
||||||
entityMapping.put(EntityType.organization, MainEntityType.organization);
|
entityMapping.put(EntityType.organization, MainEntityType.organization);
|
||||||
entityMapping.put(EntityType.project, MainEntityType.project);
|
entityMapping.put(EntityType.project, MainEntityType.project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the mapping between the actual entity types and the relative classes implementing them
|
* Defines the mapping between the actual entity types and the relative classes implementing them
|
||||||
*/
|
*/
|
||||||
public static final Map<EntityType, Class> entityTypes = Maps.newHashMap();
|
public static final Map<EntityType, Class> entityTypes = Maps.newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
entityTypes.put(EntityType.datasource, Datasource.class);
|
entityTypes.put(EntityType.datasource, Datasource.class);
|
||||||
entityTypes.put(EntityType.organization, Organization.class);
|
entityTypes.put(EntityType.organization, Organization.class);
|
||||||
entityTypes.put(EntityType.project, Project.class);
|
entityTypes.put(EntityType.project, Project.class);
|
||||||
entityTypes.put(EntityType.dataset, Dataset.class);
|
entityTypes.put(EntityType.dataset, Dataset.class);
|
||||||
entityTypes.put(EntityType.otherresearchproduct, OtherResearchProduct.class);
|
entityTypes.put(EntityType.otherresearchproduct, OtherResearchProduct.class);
|
||||||
entityTypes.put(EntityType.software, Software.class);
|
entityTypes.put(EntityType.software, Software.class);
|
||||||
entityTypes.put(EntityType.publication, Publication.class);
|
entityTypes.put(EntityType.publication, Publication.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Map<String, Class> oafTypes = Maps.newHashMap();
|
public static final Map<String, Class> oafTypes = Maps.newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
oafTypes.put("datasource", Datasource.class);
|
oafTypes.put("datasource", Datasource.class);
|
||||||
oafTypes.put("organization", Organization.class);
|
oafTypes.put("organization", Organization.class);
|
||||||
oafTypes.put("project", Project.class);
|
oafTypes.put("project", Project.class);
|
||||||
oafTypes.put("dataset", Dataset.class);
|
oafTypes.put("dataset", Dataset.class);
|
||||||
oafTypes.put("otherresearchproduct", OtherResearchProduct.class);
|
oafTypes.put("otherresearchproduct", OtherResearchProduct.class);
|
||||||
oafTypes.put("software", Software.class);
|
oafTypes.put("software", Software.class);
|
||||||
oafTypes.put("publication", Publication.class);
|
oafTypes.put("publication", Publication.class);
|
||||||
oafTypes.put("relation", Relation.class);
|
oafTypes.put("relation", Relation.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Map<String, String> entityIdPrefix = Maps.newHashMap();
|
public static final Map<String, String> entityIdPrefix = Maps.newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
entityIdPrefix.put("datasource", "10");
|
entityIdPrefix.put("datasource", "10");
|
||||||
entityIdPrefix.put("organization", "20");
|
entityIdPrefix.put("organization", "20");
|
||||||
entityIdPrefix.put("project", "40");
|
entityIdPrefix.put("project", "40");
|
||||||
entityIdPrefix.put("result","50");
|
entityIdPrefix.put("result", "50");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Map<String, RelationInverse> relationInverseMap = Maps.newHashMap();
|
public static final Map<String, RelationInverse> relationInverseMap = Maps.newHashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
relationInverseMap.put("personResult_authorship_isAuthorOf", new RelationInverse()
|
relationInverseMap
|
||||||
.setRelation("isAuthorOf")
|
.put(
|
||||||
.setInverse("hasAuthor")
|
"personResult_authorship_isAuthorOf", new RelationInverse()
|
||||||
.setRelType("personResult")
|
.setRelation("isAuthorOf")
|
||||||
.setSubReltype("authorship"));
|
.setInverse("hasAuthor")
|
||||||
relationInverseMap.put("personResult_authorship_hasAuthor", new RelationInverse()
|
.setRelType("personResult")
|
||||||
.setInverse("isAuthorOf")
|
.setSubReltype("authorship"));
|
||||||
.setRelation("hasAuthor")
|
relationInverseMap
|
||||||
.setRelType("personResult")
|
.put(
|
||||||
.setSubReltype("authorship"));
|
"personResult_authorship_hasAuthor", new RelationInverse()
|
||||||
relationInverseMap.put("projectOrganization_participation_isParticipant", new RelationInverse()
|
.setInverse("isAuthorOf")
|
||||||
.setRelation("isParticipant")
|
.setRelation("hasAuthor")
|
||||||
.setInverse("hasParticipant")
|
.setRelType("personResult")
|
||||||
.setRelType("projectOrganization")
|
.setSubReltype("authorship"));
|
||||||
.setSubReltype("participation"));
|
relationInverseMap
|
||||||
relationInverseMap.put("projectOrganization_participation_hasParticipant", new RelationInverse()
|
.put(
|
||||||
.setInverse("isParticipant")
|
"projectOrganization_participation_isParticipant", new RelationInverse()
|
||||||
.setRelation("hasParticipant")
|
.setRelation("isParticipant")
|
||||||
.setRelType("projectOrganization")
|
.setInverse("hasParticipant")
|
||||||
.setSubReltype("participation"));
|
.setRelType("projectOrganization")
|
||||||
relationInverseMap.put("resultOrganization_affiliation_hasAuthorInstitution", new RelationInverse()
|
.setSubReltype("participation"));
|
||||||
.setRelation("hasAuthorInstitution")
|
relationInverseMap
|
||||||
.setInverse("isAuthorInstitutionOf")
|
.put(
|
||||||
.setRelType("resultOrganization")
|
"projectOrganization_participation_hasParticipant", new RelationInverse()
|
||||||
.setSubReltype("affiliation"));
|
.setInverse("isParticipant")
|
||||||
relationInverseMap.put("resultOrganization_affiliation_isAuthorInstitutionOf", new RelationInverse()
|
.setRelation("hasParticipant")
|
||||||
.setInverse("hasAuthorInstitution")
|
.setRelType("projectOrganization")
|
||||||
.setRelation("isAuthorInstitutionOf")
|
.setSubReltype("participation"));
|
||||||
.setRelType("resultOrganization")
|
relationInverseMap
|
||||||
.setSubReltype("affiliation"));
|
.put(
|
||||||
relationInverseMap.put("organizationOrganization_dedup_merges", new RelationInverse()
|
"resultOrganization_affiliation_hasAuthorInstitution", new RelationInverse()
|
||||||
.setRelation("merges")
|
.setRelation("hasAuthorInstitution")
|
||||||
.setInverse("isMergedIn")
|
.setInverse("isAuthorInstitutionOf")
|
||||||
.setRelType("organizationOrganization")
|
.setRelType("resultOrganization")
|
||||||
.setSubReltype("dedup"));
|
.setSubReltype("affiliation"));
|
||||||
relationInverseMap.put("organizationOrganization_dedup_isMergedIn", new RelationInverse()
|
relationInverseMap
|
||||||
.setInverse("merges")
|
.put(
|
||||||
.setRelation("isMergedIn")
|
"resultOrganization_affiliation_isAuthorInstitutionOf", new RelationInverse()
|
||||||
.setRelType("organizationOrganization")
|
.setInverse("hasAuthorInstitution")
|
||||||
.setSubReltype("dedup"));
|
.setRelation("isAuthorInstitutionOf")
|
||||||
relationInverseMap.put("organizationOrganization_dedupSimilarity_isSimilarTo", new RelationInverse()
|
.setRelType("resultOrganization")
|
||||||
.setInverse("isSimilarTo")
|
.setSubReltype("affiliation"));
|
||||||
.setRelation("isSimilarTo")
|
relationInverseMap
|
||||||
.setRelType("organizationOrganization")
|
.put(
|
||||||
.setSubReltype("dedupSimilarity"));
|
"organizationOrganization_dedup_merges", new RelationInverse()
|
||||||
|
.setRelation("merges")
|
||||||
|
.setInverse("isMergedIn")
|
||||||
|
.setRelType("organizationOrganization")
|
||||||
|
.setSubReltype("dedup"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"organizationOrganization_dedup_isMergedIn", new RelationInverse()
|
||||||
|
.setInverse("merges")
|
||||||
|
.setRelation("isMergedIn")
|
||||||
|
.setRelType("organizationOrganization")
|
||||||
|
.setSubReltype("dedup"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"organizationOrganization_dedupSimilarity_isSimilarTo", new RelationInverse()
|
||||||
|
.setInverse("isSimilarTo")
|
||||||
|
.setRelation("isSimilarTo")
|
||||||
|
.setRelType("organizationOrganization")
|
||||||
|
.setSubReltype("dedupSimilarity"));
|
||||||
|
|
||||||
relationInverseMap.put("resultProject_outcome_isProducedBy", new RelationInverse()
|
relationInverseMap
|
||||||
.setRelation("isProducedBy")
|
.put(
|
||||||
.setInverse("produces")
|
"resultProject_outcome_isProducedBy", new RelationInverse()
|
||||||
.setRelType("resultProject")
|
.setRelation("isProducedBy")
|
||||||
.setSubReltype("outcome"));
|
.setInverse("produces")
|
||||||
relationInverseMap.put("resultProject_outcome_produces", new RelationInverse()
|
.setRelType("resultProject")
|
||||||
.setInverse("isProducedBy")
|
.setSubReltype("outcome"));
|
||||||
.setRelation("produces")
|
relationInverseMap
|
||||||
.setRelType("resultProject")
|
.put(
|
||||||
.setSubReltype("outcome"));
|
"resultProject_outcome_produces", new RelationInverse()
|
||||||
relationInverseMap.put("projectPerson_contactPerson_isContact", new RelationInverse()
|
.setInverse("isProducedBy")
|
||||||
.setRelation("isContact")
|
.setRelation("produces")
|
||||||
.setInverse("hasContact")
|
.setRelType("resultProject")
|
||||||
.setRelType("projectPerson")
|
.setSubReltype("outcome"));
|
||||||
.setSubReltype("contactPerson"));
|
relationInverseMap
|
||||||
relationInverseMap.put("projectPerson_contactPerson_hasContact", new RelationInverse()
|
.put(
|
||||||
.setInverse("isContact")
|
"projectPerson_contactPerson_isContact", new RelationInverse()
|
||||||
.setRelation("hasContact")
|
.setRelation("isContact")
|
||||||
.setRelType("personPerson")
|
.setInverse("hasContact")
|
||||||
.setSubReltype("coAuthorship"));
|
.setRelType("projectPerson")
|
||||||
relationInverseMap.put("personPerson_coAuthorship_isCoauthorOf", new RelationInverse()
|
.setSubReltype("contactPerson"));
|
||||||
.setInverse("isCoAuthorOf")
|
relationInverseMap
|
||||||
.setRelation("isCoAuthorOf")
|
.put(
|
||||||
.setRelType("personPerson")
|
"projectPerson_contactPerson_hasContact", new RelationInverse()
|
||||||
.setSubReltype("coAuthorship"));
|
.setInverse("isContact")
|
||||||
relationInverseMap.put("personPerson_dedup_merges", new RelationInverse()
|
.setRelation("hasContact")
|
||||||
.setInverse("isMergedIn")
|
.setRelType("personPerson")
|
||||||
.setRelation("merges")
|
.setSubReltype("coAuthorship"));
|
||||||
.setRelType("personPerson")
|
relationInverseMap
|
||||||
.setSubReltype("dedup"));
|
.put(
|
||||||
relationInverseMap.put("personPerson_dedup_isMergedIn", new RelationInverse()
|
"personPerson_coAuthorship_isCoauthorOf", new RelationInverse()
|
||||||
.setInverse("merges")
|
.setInverse("isCoAuthorOf")
|
||||||
.setRelation("isMergedIn")
|
.setRelation("isCoAuthorOf")
|
||||||
.setRelType("personPerson")
|
.setRelType("personPerson")
|
||||||
.setSubReltype("dedup"));
|
.setSubReltype("coAuthorship"));
|
||||||
relationInverseMap.put("personPerson_dedupSimilarity_isSimilarTo", new RelationInverse()
|
relationInverseMap
|
||||||
.setInverse("isSimilarTo")
|
.put(
|
||||||
.setRelation("isSimilarTo")
|
"personPerson_dedup_merges", new RelationInverse()
|
||||||
.setRelType("personPerson")
|
.setInverse("isMergedIn")
|
||||||
.setSubReltype("dedupSimilarity"));
|
.setRelation("merges")
|
||||||
relationInverseMap.put("datasourceOrganization_provision_isProvidedBy", new RelationInverse()
|
.setRelType("personPerson")
|
||||||
.setInverse("provides")
|
.setSubReltype("dedup"));
|
||||||
.setRelation("isProvidedBy")
|
relationInverseMap
|
||||||
.setRelType("datasourceOrganization")
|
.put(
|
||||||
.setSubReltype("provision"));
|
"personPerson_dedup_isMergedIn", new RelationInverse()
|
||||||
relationInverseMap.put("datasourceOrganization_provision_provides", new RelationInverse()
|
.setInverse("merges")
|
||||||
.setInverse("isProvidedBy")
|
.setRelation("isMergedIn")
|
||||||
.setRelation("provides")
|
.setRelType("personPerson")
|
||||||
.setRelType("datasourceOrganization")
|
.setSubReltype("dedup"));
|
||||||
.setSubReltype("provision"));
|
relationInverseMap
|
||||||
relationInverseMap.put("resultResult_similarity_hasAmongTopNSimilarDocuments", new RelationInverse()
|
.put(
|
||||||
.setInverse("isAmongTopNSimilarDocuments")
|
"personPerson_dedupSimilarity_isSimilarTo", new RelationInverse()
|
||||||
.setRelation("hasAmongTopNSimilarDocuments")
|
.setInverse("isSimilarTo")
|
||||||
.setRelType("resultResult")
|
.setRelation("isSimilarTo")
|
||||||
.setSubReltype("similarity"));
|
.setRelType("personPerson")
|
||||||
relationInverseMap.put("resultResult_similarity_isAmongTopNSimilarDocuments", new RelationInverse()
|
.setSubReltype("dedupSimilarity"));
|
||||||
.setInverse("hasAmongTopNSimilarDocuments")
|
relationInverseMap
|
||||||
.setRelation("isAmongTopNSimilarDocuments")
|
.put(
|
||||||
.setRelType("resultResult")
|
"datasourceOrganization_provision_isProvidedBy", new RelationInverse()
|
||||||
.setSubReltype("similarity"));
|
.setInverse("provides")
|
||||||
relationInverseMap.put("resultResult_relationship_isRelatedTo", new RelationInverse()
|
.setRelation("isProvidedBy")
|
||||||
.setInverse("isRelatedTo")
|
.setRelType("datasourceOrganization")
|
||||||
.setRelation("isRelatedTo")
|
.setSubReltype("provision"));
|
||||||
.setRelType("resultResult")
|
relationInverseMap
|
||||||
.setSubReltype("relationship"));
|
.put(
|
||||||
relationInverseMap.put("resultResult_similarity_isAmongTopNSimilarDocuments", new RelationInverse()
|
"datasourceOrganization_provision_provides", new RelationInverse()
|
||||||
.setInverse("hasAmongTopNSimilarDocuments")
|
.setInverse("isProvidedBy")
|
||||||
.setRelation("isAmongTopNSimilarDocuments")
|
.setRelation("provides")
|
||||||
.setRelType("resultResult")
|
.setRelType("datasourceOrganization")
|
||||||
.setSubReltype("similarity"));
|
.setSubReltype("provision"));
|
||||||
relationInverseMap.put("resultResult_supplement_isSupplementTo", new RelationInverse()
|
relationInverseMap
|
||||||
.setInverse("isSupplementedBy")
|
.put(
|
||||||
.setRelation("isSupplementTo")
|
"resultResult_similarity_hasAmongTopNSimilarDocuments", new RelationInverse()
|
||||||
.setRelType("resultResult")
|
.setInverse("isAmongTopNSimilarDocuments")
|
||||||
.setSubReltype("supplement"));
|
.setRelation("hasAmongTopNSimilarDocuments")
|
||||||
relationInverseMap.put("resultResult_supplement_isSupplementedBy", new RelationInverse()
|
.setRelType("resultResult")
|
||||||
.setInverse("isSupplementTo")
|
.setSubReltype("similarity"));
|
||||||
.setRelation("isSupplementedBy")
|
relationInverseMap
|
||||||
.setRelType("resultResult")
|
.put(
|
||||||
.setSubReltype("supplement"));
|
"resultResult_similarity_isAmongTopNSimilarDocuments", new RelationInverse()
|
||||||
relationInverseMap.put("resultResult_part_isPartOf", new RelationInverse()
|
.setInverse("hasAmongTopNSimilarDocuments")
|
||||||
.setInverse("hasPart")
|
.setRelation("isAmongTopNSimilarDocuments")
|
||||||
.setRelation("isPartOf")
|
.setRelType("resultResult")
|
||||||
.setRelType("resultResult")
|
.setSubReltype("similarity"));
|
||||||
.setSubReltype("part"));
|
relationInverseMap
|
||||||
relationInverseMap.put("resultResult_part_hasPart", new RelationInverse()
|
.put(
|
||||||
.setInverse("isPartOf")
|
"resultResult_relationship_isRelatedTo", new RelationInverse()
|
||||||
.setRelation("hasPart")
|
.setInverse("isRelatedTo")
|
||||||
.setRelType("resultResult")
|
.setRelation("isRelatedTo")
|
||||||
.setSubReltype("part"));
|
.setRelType("resultResult")
|
||||||
relationInverseMap.put("resultResult_dedup_merges", new RelationInverse()
|
.setSubReltype("relationship"));
|
||||||
.setInverse("isMergedIn")
|
relationInverseMap
|
||||||
.setRelation("merges")
|
.put(
|
||||||
.setRelType("resultResult")
|
"resultResult_similarity_isAmongTopNSimilarDocuments", new RelationInverse()
|
||||||
.setSubReltype("dedup"));
|
.setInverse("hasAmongTopNSimilarDocuments")
|
||||||
relationInverseMap.put("resultResult_dedup_isMergedIn", new RelationInverse()
|
.setRelation("isAmongTopNSimilarDocuments")
|
||||||
.setInverse("merges")
|
.setRelType("resultResult")
|
||||||
.setRelation("isMergedIn")
|
.setSubReltype("similarity"));
|
||||||
.setRelType("resultResult")
|
relationInverseMap
|
||||||
.setSubReltype("dedup"));
|
.put(
|
||||||
relationInverseMap.put("resultResult_dedupSimilarity_isSimilarTo", new RelationInverse()
|
"resultResult_supplement_isSupplementTo", new RelationInverse()
|
||||||
.setInverse("isSimilarTo")
|
.setInverse("isSupplementedBy")
|
||||||
.setRelation("isSimilarTo")
|
.setRelation("isSupplementTo")
|
||||||
.setRelType("resultResult")
|
.setRelType("resultResult")
|
||||||
.setSubReltype("dedupSimilarity"));
|
.setSubReltype("supplement"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_supplement_isSupplementedBy", new RelationInverse()
|
||||||
|
.setInverse("isSupplementTo")
|
||||||
|
.setRelation("isSupplementedBy")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("supplement"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_part_isPartOf", new RelationInverse()
|
||||||
|
.setInverse("hasPart")
|
||||||
|
.setRelation("isPartOf")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("part"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_part_hasPart", new RelationInverse()
|
||||||
|
.setInverse("isPartOf")
|
||||||
|
.setRelation("hasPart")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("part"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_dedup_merges", new RelationInverse()
|
||||||
|
.setInverse("isMergedIn")
|
||||||
|
.setRelation("merges")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("dedup"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_dedup_isMergedIn", new RelationInverse()
|
||||||
|
.setInverse("merges")
|
||||||
|
.setRelation("isMergedIn")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("dedup"));
|
||||||
|
relationInverseMap
|
||||||
|
.put(
|
||||||
|
"resultResult_dedupSimilarity_isSimilarTo", new RelationInverse()
|
||||||
|
.setInverse("isSimilarTo")
|
||||||
|
.setRelation("isSimilarTo")
|
||||||
|
.setRelType("resultResult")
|
||||||
|
.setSubReltype("dedupSimilarity"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String schemeTemplate = "dnet:%s_%s_relations";
|
private static final String schemeTemplate = "dnet:%s_%s_relations";
|
||||||
|
|
||||||
private ModelSupport() {}
|
private ModelSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks subclass-superclass relationship.
|
* Checks subclass-superclass relationship.
|
||||||
*
|
*
|
||||||
* @param subClazzObject Subclass object instance
|
* @param subClazzObject Subclass object instance
|
||||||
* @param superClazzObject Superclass object instance
|
* @param superClazzObject Superclass object instance
|
||||||
* @param <X> Subclass type
|
* @param <X> Subclass type
|
||||||
* @param <Y> Superclass type
|
* @param <Y> Superclass type
|
||||||
* @return True if X is a subclass of Y
|
* @return True if X is a subclass of Y
|
||||||
*/
|
*/
|
||||||
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
||||||
X subClazzObject, Y superClazzObject) {
|
X subClazzObject, Y superClazzObject) {
|
||||||
return isSubClass(subClazzObject.getClass(), superClazzObject.getClass());
|
return isSubClass(subClazzObject.getClass(), superClazzObject.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks subclass-superclass relationship.
|
* Checks subclass-superclass relationship.
|
||||||
*
|
*
|
||||||
* @param subClazzObject Subclass object instance
|
* @param subClazzObject Subclass object instance
|
||||||
* @param superClazz Superclass class
|
* @param superClazz Superclass class
|
||||||
* @param <X> Subclass type
|
* @param <X> Subclass type
|
||||||
* @param <Y> Superclass type
|
* @param <Y> Superclass type
|
||||||
* @return True if X is a subclass of Y
|
* @return True if X is a subclass of Y
|
||||||
*/
|
*/
|
||||||
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
||||||
X subClazzObject, Class<Y> superClazz) {
|
X subClazzObject, Class<Y> superClazz) {
|
||||||
return isSubClass(subClazzObject.getClass(), superClazz);
|
return isSubClass(subClazzObject.getClass(), superClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks subclass-superclass relationship.
|
* Checks subclass-superclass relationship.
|
||||||
*
|
*
|
||||||
* @param subClazz Subclass class
|
* @param subClazz Subclass class
|
||||||
* @param superClazz Superclass class
|
* @param superClazz Superclass class
|
||||||
* @param <X> Subclass type
|
* @param <X> Subclass type
|
||||||
* @param <Y> Superclass type
|
* @param <Y> Superclass type
|
||||||
* @return True if X is a subclass of Y
|
* @return True if X is a subclass of Y
|
||||||
*/
|
*/
|
||||||
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
public static <X extends Oaf, Y extends Oaf> Boolean isSubClass(
|
||||||
Class<X> subClazz, Class<Y> superClazz) {
|
Class<X> subClazz, Class<Y> superClazz) {
|
||||||
return superClazz.isAssignableFrom(subClazz);
|
return superClazz.isAssignableFrom(subClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all the OAF model classes
|
* Lists all the OAF model classes
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static <T extends Oaf> Class<T>[] getOafModelClasses() {
|
public static <T extends Oaf> Class<T>[] getOafModelClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Author.class,
|
Author.class,
|
||||||
Context.class,
|
Context.class,
|
||||||
Country.class,
|
Country.class,
|
||||||
DataInfo.class,
|
DataInfo.class,
|
||||||
Dataset.class,
|
Dataset.class,
|
||||||
Datasource.class,
|
Datasource.class,
|
||||||
ExternalReference.class,
|
ExternalReference.class,
|
||||||
ExtraInfo.class,
|
ExtraInfo.class,
|
||||||
Field.class,
|
Field.class,
|
||||||
GeoLocation.class,
|
GeoLocation.class,
|
||||||
Instance.class,
|
Instance.class,
|
||||||
Journal.class,
|
Journal.class,
|
||||||
KeyValue.class,
|
KeyValue.class,
|
||||||
Oaf.class,
|
Oaf.class,
|
||||||
OafEntity.class,
|
OafEntity.class,
|
||||||
OAIProvenance.class,
|
OAIProvenance.class,
|
||||||
Organization.class,
|
Organization.class,
|
||||||
OriginDescription.class,
|
OriginDescription.class,
|
||||||
OtherResearchProduct.class,
|
OtherResearchProduct.class,
|
||||||
Project.class,
|
Project.class,
|
||||||
Publication.class,
|
Publication.class,
|
||||||
Qualifier.class,
|
Qualifier.class,
|
||||||
Relation.class,
|
Relation.class,
|
||||||
Result.class,
|
Result.class,
|
||||||
Software.class,
|
Software.class,
|
||||||
StructuredProperty.class
|
StructuredProperty.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMainType(final EntityType type) {
|
public static String getMainType(final EntityType type) {
|
||||||
return entityMapping.get(type).name();
|
return entityMapping.get(type).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isResult(EntityType type) {
|
public static boolean isResult(EntityType type) {
|
||||||
return MainEntityType.result.name().equals(getMainType(type));
|
return MainEntityType.result.name().equals(getMainType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getScheme(final String sourceType, final String targetType) {
|
public static String getScheme(final String sourceType, final String targetType) {
|
||||||
return String.format(
|
return String
|
||||||
schemeTemplate,
|
.format(
|
||||||
entityMapping.get(EntityType.valueOf(sourceType)).name(),
|
schemeTemplate,
|
||||||
entityMapping.get(EntityType.valueOf(targetType)).name());
|
entityMapping.get(EntityType.valueOf(sourceType)).name(),
|
||||||
}
|
entityMapping.get(EntityType.valueOf(targetType)).name());
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends Oaf> Function<T, String> idFn() {
|
public static <T extends Oaf> Function<T, String> idFn() {
|
||||||
return x -> {
|
return x -> {
|
||||||
if (isSubClass(x, Relation.class)) {
|
if (isSubClass(x, Relation.class)) {
|
||||||
return idFnForRelation(x);
|
return idFnForRelation(x);
|
||||||
}
|
}
|
||||||
return idFnForOafEntity(x);
|
return idFnForOafEntity(x);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends Oaf> String idFnForRelation(T t) {
|
private static <T extends Oaf> String idFnForRelation(T t) {
|
||||||
Relation r = (Relation) t;
|
Relation r = (Relation) t;
|
||||||
return Optional.ofNullable(r.getSource())
|
return Optional
|
||||||
.map(
|
.ofNullable(r.getSource())
|
||||||
source ->
|
.map(
|
||||||
Optional.ofNullable(r.getTarget())
|
source -> Optional
|
||||||
.map(
|
.ofNullable(r.getTarget())
|
||||||
target ->
|
.map(
|
||||||
Optional.ofNullable(r.getRelType())
|
target -> Optional
|
||||||
.map(
|
.ofNullable(r.getRelType())
|
||||||
relType ->
|
.map(
|
||||||
Optional.ofNullable(r.getSubRelType())
|
relType -> Optional
|
||||||
.map(
|
.ofNullable(r.getSubRelType())
|
||||||
subRelType ->
|
.map(
|
||||||
Optional.ofNullable(r.getRelClass())
|
subRelType -> Optional
|
||||||
.map(
|
.ofNullable(r.getRelClass())
|
||||||
relClass ->
|
.map(
|
||||||
String.join(
|
relClass -> String
|
||||||
source,
|
.join(
|
||||||
target,
|
source,
|
||||||
relType,
|
target,
|
||||||
subRelType,
|
relType,
|
||||||
relClass))
|
subRelType,
|
||||||
.orElse(
|
relClass))
|
||||||
String.join(
|
.orElse(
|
||||||
source,
|
String
|
||||||
target,
|
.join(
|
||||||
relType,
|
source,
|
||||||
subRelType)))
|
target,
|
||||||
.orElse(String.join(source, target, relType)))
|
relType,
|
||||||
.orElse(String.join(source, target)))
|
subRelType)))
|
||||||
.orElse(source))
|
.orElse(String.join(source, target, relType)))
|
||||||
.orElse(null);
|
.orElse(String.join(source, target)))
|
||||||
}
|
.orElse(source))
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
private static <T extends Oaf> String idFnForOafEntity(T t) {
|
private static <T extends Oaf> String idFnForOafEntity(T t) {
|
||||||
return ((OafEntity) t).getId();
|
return ((OafEntity) t).getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,46 @@
|
||||||
|
|
||||||
package eu.dnetlib.dhp.schema.common;
|
package eu.dnetlib.dhp.schema.common;
|
||||||
|
|
||||||
public class RelationInverse {
|
public class RelationInverse {
|
||||||
private String relation;
|
private String relation;
|
||||||
private String inverse;
|
private String inverse;
|
||||||
private String relType;
|
private String relType;
|
||||||
private String subReltype;
|
private String subReltype;
|
||||||
|
|
||||||
public String getRelType() {
|
public String getRelType() {
|
||||||
return relType;
|
return relType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationInverse setRelType(String relType) {
|
public RelationInverse setRelType(String relType) {
|
||||||
this.relType = relType;
|
this.relType = relType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubReltype() {
|
public String getSubReltype() {
|
||||||
return subReltype;
|
return subReltype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationInverse setSubReltype(String subReltype) {
|
public RelationInverse setSubReltype(String subReltype) {
|
||||||
this.subReltype = subReltype;
|
this.subReltype = subReltype;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRelation() {
|
public String getRelation() {
|
||||||
return relation;
|
return relation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationInverse setRelation(String relation) {
|
public RelationInverse setRelation(String relation) {
|
||||||
this.relation = relation;
|
this.relation = relation;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInverse() {
|
public String getInverse() {
|
||||||
return inverse;
|
return inverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelationInverse setInverse(String inverse) {
|
|
||||||
this.inverse = inverse;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public RelationInverse setInverse(String inverse) {
|
||||||
|
this.inverse = inverse;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue