2020-04-27 14:52:31 +02:00
2019-10-24 11:39:41 +02:00
package eu.dnetlib.dhp.schema.oaf ;
2021-02-16 11:49:23 +01:00
import eu.dnetlib.dhp.schema.common.ModelSupport ;
2020-04-18 12:42:58 +02:00
import static com.google.common.base.Preconditions.checkArgument ;
2021-02-16 11:49:23 +01:00
import java.text.ParseException ;
2020-04-01 18:28:23 +02:00
import java.util.* ;
2020-02-19 17:29:05 +01:00
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
2019-10-24 11:39:41 +02:00
2020-05-04 16:00:48 +02:00
/ * *
2020-06-16 16:54:44 +02:00
* Relation models any edge between two nodes in the OpenAIRE graph . It has a source id and a target id pointing to
* graph node identifiers and it is further characterised by the semantic of the link through the fields relType ,
* subRelType and relClass . Provenance information is modeled according to the dataInfo element and collectedFrom , while
* individual relationship types can provide extra information via the properties field .
2020-05-04 16:00:48 +02:00
* /
2019-10-25 18:10:30 +02:00
public class Relation extends Oaf {
2019-10-24 11:39:41 +02:00
2020-05-04 16:00:48 +02:00
/ * *
* Main relationship classifier , values include ' resultResult ' , ' resultProject ' , ' resultOrganization ' , etc .
* /
2020-04-27 14:52:31 +02:00
private String relType ;
2020-05-04 16:00:48 +02:00
/ * *
* Further classifies a relationship , values include ' affiliation ' , ' similarity ' , ' supplement ' , etc .
* /
2020-04-27 14:52:31 +02:00
private String subRelType ;
2020-05-04 16:00:48 +02:00
/ * *
2020-06-16 16:54:44 +02:00
* Indicates the direction of the relationship , values include ' isSupplementTo ' , ' isSupplementedBy ' , ' merges ,
* ' isMergedIn ' .
2020-05-04 16:00:48 +02:00
* /
2020-04-27 14:52:31 +02:00
private String relClass ;
2020-05-04 16:00:48 +02:00
/ * *
* The source entity id .
* /
2020-04-27 14:52:31 +02:00
private String source ;
2020-05-04 16:00:48 +02:00
/ * *
* The target entity id .
* /
2020-04-27 14:52:31 +02:00
private String target ;
2020-05-04 16:47:07 +02:00
/ * *
* Was this relationship authoritatively validated ?
* /
private Boolean validated ;
/ * *
* When was this relationship authoritatively validated .
* /
private String validationDate ;
/ * *
2020-06-16 16:54:44 +02:00
* List of relation specific properties . Values include ' similarityLevel ' , indicating the similarity score between a
* pair of publications .
2020-05-04 16:47:07 +02:00
* /
private List < KeyValue > properties = new ArrayList < > ( ) ;
2020-04-27 14:52:31 +02:00
public String getRelType ( ) {
return relType ;
}
public void setRelType ( final String relType ) {
this . relType = relType ;
}
public String getSubRelType ( ) {
return subRelType ;
}
public void setSubRelType ( final String subRelType ) {
this . subRelType = subRelType ;
}
public String getRelClass ( ) {
return relClass ;
}
public void setRelClass ( final String relClass ) {
this . relClass = relClass ;
}
public String getSource ( ) {
return source ;
}
public void setSource ( final String source ) {
this . source = source ;
}
public String getTarget ( ) {
return target ;
}
public void setTarget ( final String target ) {
this . target = target ;
}
2020-05-04 16:47:07 +02:00
public List < KeyValue > getProperties ( ) {
return properties ;
}
public void setProperties ( List < KeyValue > properties ) {
this . properties = properties ;
}
public Boolean getValidated ( ) {
2021-02-16 11:49:23 +01:00
return Objects . nonNull ( validated ) & & validated ;
2020-05-04 16:47:07 +02:00
}
public void setValidated ( Boolean validated ) {
this . validated = validated ;
}
public String getValidationDate ( ) {
return validationDate ;
}
public void setValidationDate ( String validationDate ) {
this . validationDate = validationDate ;
}
2020-04-27 14:52:31 +02:00
public void mergeFrom ( final Relation r ) {
checkArgument ( Objects . equals ( getSource ( ) , r . getSource ( ) ) , " source ids must be equal " ) ;
checkArgument ( Objects . equals ( getTarget ( ) , r . getTarget ( ) ) , " target ids must be equal " ) ;
checkArgument ( Objects . equals ( getRelType ( ) , r . getRelType ( ) ) , " relType(s) must be equal " ) ;
checkArgument (
Objects . equals ( getSubRelType ( ) , r . getSubRelType ( ) ) , " subRelType(s) must be equal " ) ;
checkArgument ( Objects . equals ( getRelClass ( ) , r . getRelClass ( ) ) , " relClass(es) must be equal " ) ;
2021-02-16 11:49:23 +01:00
setValidated ( getValidated ( ) | | r . getValidated ( ) ) ;
try {
setValidationDate ( ModelSupport . oldest ( getValidationDate ( ) , r . getValidationDate ( ) ) ) ;
} catch ( ParseException e ) {
throw new IllegalArgumentException ( String . format ( " invalid validation date format in relation [s:%s, t:%s]: %s " , getSource ( ) , getTarget ( ) , getValidationDate ( ) ) ) ;
}
2020-12-09 18:01:45 +01:00
super . mergeFrom ( r ) ;
2020-04-27 14:52:31 +02:00
}
@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 , collectedfrom ) ;
}
2020-05-04 16:47:07 +02:00
2019-10-24 11:39:41 +02:00
}