From 3b5b4c565b6fdf84021de394d66fa85308346726 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Wed, 26 Apr 2023 16:00:41 +0200 Subject: [PATCH] WIP: model simplification --- .../eu/dnetlib/dhp/schema/oaf/Dataset.java | 4 +- .../dhp/schema/oaf/OtherResearchProduct.java | 4 +- .../eu/dnetlib/dhp/schema/oaf/Provenance.java | 4 +- .../dnetlib/dhp/schema/oaf/Publication.java | 4 +- .../eu/dnetlib/dhp/schema/oaf/Relation.java | 409 +++++++++++++----- .../eu/dnetlib/dhp/schema/oaf/Result.java | 13 +- .../eu/dnetlib/dhp/schema/oaf/Software.java | 4 +- .../dhp/schema/action/AtomicActionTest.java | 6 +- 8 files changed, 323 insertions(+), 125 deletions(-) diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java index e529c20..13f0193 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Dataset.java @@ -6,8 +6,6 @@ import java.util.List; public class Dataset extends Result implements Serializable { - private static final String DATASET_RESULTTYPE = "dataset"; - private String storagedate; // candidate for removal @@ -24,7 +22,7 @@ public class Dataset extends Result implements Serializable { private List geolocation; public Dataset() { - setResulttype(DATASET_RESULTTYPE); + setResulttype(RESULTTYPE.dataset); } public String getStoragedate() { diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/OtherResearchProduct.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/OtherResearchProduct.java index daa56b2..f5ab72c 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/OtherResearchProduct.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/OtherResearchProduct.java @@ -6,8 +6,6 @@ import java.util.List; public class OtherResearchProduct extends Result implements Serializable { - private static final String ORP_RESULTTYPE = "otherresearchproduct"; - private List contactperson; private List contactgroup; @@ -15,7 +13,7 @@ public class OtherResearchProduct extends Result implements Serializable { private List tool; public OtherResearchProduct() { - setResulttype(ORP_RESULTTYPE); + setResulttype(RESULTTYPE.otherresearchproduct); } public List getContactperson() { diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Provenance.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Provenance.java index fd15386..c8a70ef 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Provenance.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Provenance.java @@ -1,6 +1,8 @@ package eu.dnetlib.dhp.schema.oaf; -public class Provenance { +import java.io.Serializable; + +public class Provenance implements Serializable { private KeyValue collectedfrom; diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Publication.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Publication.java index cb8ce53..e8e41b6 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Publication.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Publication.java @@ -5,10 +5,8 @@ import java.io.Serializable; public class Publication extends Result implements Serializable { - private static final String PUBLICATION_RESULTTYPE = "publication"; - public Publication() { - setResulttype(PUBLICATION_RESULTTYPE); + setResulttype(RESULTTYPE.publication); } } diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java index b03bf6f..17f1378 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java @@ -1,6 +1,7 @@ package eu.dnetlib.dhp.schema.oaf; +import java.beans.Transient; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -14,139 +15,335 @@ import java.util.Objects; */ public class Relation extends Oaf implements Serializable { - /** - * Main relationship classifier, values include 'resultResult', 'resultProject', 'resultOrganization', etc. - */ - private String relType; + public enum RELTYPE { + resultResult, + resultProject, + resultOrganization, + projectOrganization, + datasourceOrganization + } - /** - * Further classifies a relationship, values include 'affiliation', 'similarity', 'supplement', etc. - */ - private String subRelType; + public enum SUBRELTYPE { + affiliation, + citation, + dedup, + outcome, + part, + participation, + provision, + relationship, + review, + similarity, + supplement, + version; - /** - * Indicates the direction of the relationship, values include 'isSupplementTo', 'isSupplementedBy', 'merges, - * 'isMergedIn'. - */ - private String relClass; + public boolean exists(String subreltype) { + try { + SUBRELTYPE.valueOf(subreltype); + return true; + } catch (IllegalArgumentException | NullPointerException e) { + return false; + } + } + } - /** - * The source entity id. - */ - private String source; + public enum RELCLASS { + IsVersionOf, + IsSourceOf, + isMergedIn, + IsIdenticalTo, + Documents, + IsAmongTopNSimilarDocuments, + IsSupplementedBy, + IsObsoletedBy, + Continues, + IsParentOf, + IsReferencedBy, + IsCitedBy, + Compiles, + IsPreviousVersionOf, + HasPart, + IsDocumentedBy, + HasAmongTopNSimilarDocuments, + isParticipant, + hasAuthorInstitution, + IsRelatedTo, + Requires, + Describes, + IsReviewedBy, + IsContinuedBy, + provides, + IsChildOf, + IsDescribedBy, + IsNewVersionOf, + IsPartOf, + HasVersion, + hasParticipant, + isAuthorInstitutionOf, + IsVariantFormOf, + isProducedBy, + IsMetadataFor, + Cites, + IsRequiredBy, + IsOriginalFormOf, + IsSupplementTo, + IsMetadataOf, + References, + IsCompiledBy, + isProvidedBy, + merges, + IsDerivedFrom, + Obsoletes, + Reviews, + produces; - /** - * The target entity id. - */ - private String target; + public static boolean exists(String relclass) { + try { + RELCLASS.valueOf(relclass); + return true; + } catch (IllegalArgumentException | NullPointerException e) { + return false; + } + } - /** - * Was this relationship authoritatively validated? - */ - private Boolean validated; + @Transient + public RELCLASS getInverse() { + switch (this) { + case IsVersionOf: + return HasVersion; + case IsSourceOf: + return IsDerivedFrom; + case isMergedIn: + return merges; + case IsIdenticalTo: + return IsIdenticalTo; + case Documents: + return IsDocumentedBy; + case IsAmongTopNSimilarDocuments: + return HasAmongTopNSimilarDocuments; + case IsSupplementedBy: + return IsSupplementTo; + case IsObsoletedBy: + return Obsoletes; + case Continues: + return IsContinuedBy; + case IsParentOf: + return IsChildOf; + case IsReferencedBy: + return References; + case IsCitedBy: + return Cites; + case Compiles: + return IsCompiledBy; + case IsPreviousVersionOf: + return IsNewVersionOf; + case HasPart: + return IsPartOf; + case IsDocumentedBy: + return Documents; + case HasAmongTopNSimilarDocuments: + return IsAmongTopNSimilarDocuments; + case isParticipant: + return hasParticipant; + case hasAuthorInstitution: + return isAuthorInstitutionOf; + case IsRelatedTo: + return IsRelatedTo; + case Requires: + return IsRequiredBy; + case Describes: + return IsDescribedBy; + case IsReviewedBy: + return Reviews; + case IsContinuedBy: + return Continues; + case provides: + return isProvidedBy; + case IsChildOf: + return IsParentOf; + case IsDescribedBy: + return Describes; + case IsNewVersionOf: + return IsPreviousVersionOf; + case IsPartOf: + return HasPart; + case HasVersion: + return IsVersionOf; + case hasParticipant: + return isParticipant; + case isAuthorInstitutionOf: + return hasAuthorInstitution; + case IsVariantFormOf: + return IsOriginalFormOf; + case isProducedBy: + return produces; + case IsMetadataFor: + return IsMetadataOf; + case Cites: + return IsCitedBy; + case IsRequiredBy: + return Requires; + case IsOriginalFormOf: + return IsVariantFormOf; + case IsSupplementTo: + return IsSupplementedBy; + case IsMetadataOf: + return IsMetadataFor; + case References: + return IsReferencedBy; + case IsCompiledBy: + return Compiles; + case isProvidedBy: + return provides; + case merges: + return isMergedIn; + case IsDerivedFrom: + return IsSourceOf; + case Obsoletes: + return IsObsoletedBy; + case Reviews: + return IsReviewedBy; + case produces: + return isProducedBy; + } + // makes the compiler happy + throw new IllegalArgumentException("missing inverse mapping for" + this); + } + } - /** - * When was this relationship authoritatively validated. - */ - private String validationDate; + /** + * Main relationship classifier, values include 'resultResult', 'resultProject', 'resultOrganization', etc. + */ + private RELTYPE relType; - private List provenance; + /** + * Further classifies a relationship, values include 'affiliation', 'similarity', 'supplement', etc. + */ + private SUBRELTYPE subRelType; - /** - * List of relation specific properties. Values include 'similarityLevel', indicating the similarity score between a - * pair of publications. - */ - private List properties = new ArrayList<>(); + /** + * Indicates the direction of the relationship, values include 'isSupplementTo', 'isSupplementedBy', 'merges, + * 'isMergedIn'. + */ + private RELCLASS relClass; - public String getRelType() { - return relType; - } + /** + * The source entity id. + */ + private String source; - public void setRelType(final String relType) { - this.relType = relType; - } + /** + * The target entity id. + */ + private String target; - public String getSubRelType() { - return subRelType; - } + /** + * Was this relationship authoritatively validated? + */ + private Boolean validated; - public void setSubRelType(final String subRelType) { - this.subRelType = subRelType; - } + /** + * When was this relationship authoritatively validated. + */ + private String validationDate; - public String getRelClass() { - return relClass; - } + private List provenance; - public void setRelClass(final String relClass) { - this.relClass = relClass; - } + /** + * List of relation specific properties. Values include 'similarityLevel', indicating the similarity score between a + * pair of publications. + */ + private List properties = new ArrayList<>(); - public String getSource() { - return source; - } + public RELTYPE getRelType() { + return relType; + } - public void setSource(final String source) { - this.source = source; - } + public void setRelType(final RELTYPE relType) { + this.relType = relType; + } - public String getTarget() { - return target; - } + public SUBRELTYPE getSubRelType() { + return subRelType; + } - public void setTarget(final String target) { - this.target = target; - } + public void setSubRelType(final SUBRELTYPE subRelType) { + this.subRelType = subRelType; + } - public List getProperties() { - return properties; - } + public RELCLASS getRelClass() { + return relClass; + } - public void setProperties(List properties) { - this.properties = properties; - } + public void setRelClass(final RELCLASS relClass) { + this.relClass = relClass; + } - public Boolean getValidated() { - return Objects.nonNull(validated) && validated; - } + public String getSource() { + return source; + } - public void setValidated(Boolean validated) { - this.validated = validated; - } + public void setSource(final String source) { + this.source = source; + } - public String getValidationDate() { - return validationDate; - } + public String getTarget() { + return target; + } - public void setValidationDate(String validationDate) { - this.validationDate = validationDate; - } + public void setTarget(final String target) { + this.target = target; + } - public List getProvenance() { - return provenance; - } + public List getProperties() { + return properties; + } - public void setProvenance(List provenance) { - this.provenance = provenance; - } + public void setProperties(List properties) { + this.properties = properties; + } - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Relation relation = (Relation) o; - return relType.equals(relation.relType) - && subRelType.equals(relation.subRelType) - && relClass.equals(relation.relClass) - && source.equals(relation.source) - && target.equals(relation.target); - } + public Boolean getValidated() { + return Objects.nonNull(validated) && validated; + } - @Override - public int hashCode() { - return Objects.hash(relType, subRelType, relClass, source, target, provenance); - } + public void setValidated(Boolean validated) { + this.validated = validated; + } + + public String getValidationDate() { + return validationDate; + } + + public void setValidationDate(String validationDate) { + this.validationDate = validationDate; + } + + public List getProvenance() { + return provenance; + } + + public void setProvenance(List provenance) { + this.provenance = provenance; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Relation relation = (Relation) o; + return relType.equals(relation.relType) + && subRelType.equals(relation.subRelType) + && relClass.equals(relation.relClass) + && source.equals(relation.source) + && target.equals(relation.target); + } + + @Override + public int hashCode() { + return Objects.hash(relType, subRelType, relClass, source, target, provenance); + } } diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java index 07bc153..10c3d1c 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java @@ -9,6 +9,13 @@ import java.util.List; */ public class Result extends Entity implements Serializable { + public enum RESULTTYPE { + publication, + dataset, + software, + otherresearchproduct + } + /** * ( article | book ) processing charges. */ @@ -27,7 +34,7 @@ public class Result extends Entity implements Serializable { /** * The Resulttype. It allows subclassing results into publications | datasets | software | orp */ - private String resulttype; + private RESULTTYPE resulttype; /** * The Language. @@ -172,7 +179,7 @@ public class Result extends Entity implements Serializable { * * @return the resulttype */ - public String getResulttype() { + public RESULTTYPE getResulttype() { return resulttype; } @@ -181,7 +188,7 @@ public class Result extends Entity implements Serializable { * * @param resulttype the resulttype */ - public void setResulttype(String resulttype) { + public void setResulttype(RESULTTYPE resulttype) { this.resulttype = resulttype; } diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Software.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Software.java index c927891..bcdb906 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Software.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Software.java @@ -6,8 +6,6 @@ import java.util.List; public class Software extends Result implements Serializable { - private static final String SOFTWARE_RESULTTYPE = "software"; - private List documentationUrl; // candidate for removal @@ -16,7 +14,7 @@ public class Software extends Result implements Serializable { private Qualifier programmingLanguage; public Software() { - setResulttype(SOFTWARE_RESULTTYPE); + setResulttype(RESULTTYPE.software); } public List getDocumentationUrl() { diff --git a/src/test/java/eu/dnetlib/dhp/schema/action/AtomicActionTest.java b/src/test/java/eu/dnetlib/dhp/schema/action/AtomicActionTest.java index a586067..2e3da10 100644 --- a/src/test/java/eu/dnetlib/dhp/schema/action/AtomicActionTest.java +++ b/src/test/java/eu/dnetlib/dhp/schema/action/AtomicActionTest.java @@ -22,9 +22,9 @@ class AtomicActionTest { Relation rel = new Relation(); rel.setSource("1"); rel.setTarget("2"); - rel.setRelType("resultResult"); - rel.setSubRelType("dedup"); - rel.setRelClass("merges"); + rel.setRelType(Relation.RELTYPE.resultResult); + rel.setSubRelType(Relation.SUBRELTYPE.dedup); + rel.setRelClass(Relation.RELCLASS.merges); AtomicAction aa1 = new AtomicAction(Relation.class, rel);