1
|
package eu.dnetlib.utils.ontologies;
|
2
|
|
3
|
import java.util.Map;
|
4
|
|
5
|
import com.google.gson.Gson;
|
6
|
import eu.dnetlib.data.mapreduce.util.RelDescriptor;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
|
10
|
/**
|
11
|
* Created by claudio on 12/12/2016.
|
12
|
*/
|
13
|
public class Ontology {
|
14
|
|
15
|
private static final Log log = LogFactory.getLog(Ontology.class);
|
16
|
|
17
|
private String code;
|
18
|
private String description;
|
19
|
|
20
|
private Map<String, OntologyTerm> terms;
|
21
|
|
22
|
public String getCode() {
|
23
|
return code;
|
24
|
}
|
25
|
|
26
|
public Ontology setCode(final String code) {
|
27
|
this.code = code;
|
28
|
return this;
|
29
|
}
|
30
|
|
31
|
public String getDescription() {
|
32
|
return description;
|
33
|
}
|
34
|
|
35
|
public Ontology setDescription(final String description) {
|
36
|
this.description = description;
|
37
|
return this;
|
38
|
}
|
39
|
|
40
|
public Map<String, OntologyTerm> getTerms() {
|
41
|
return terms;
|
42
|
}
|
43
|
|
44
|
public Ontology setTerms(final Map<String, OntologyTerm> terms) {
|
45
|
this.terms = terms;
|
46
|
return this;
|
47
|
}
|
48
|
|
49
|
public String inverseOf(final String termCode) {
|
50
|
if (getTerms() == null || !getTerms().containsKey(termCode)) {
|
51
|
//log.warn(String.format("unable to find inverse for term '%s', terms: %s", termCode, getTerms()));
|
52
|
return null;
|
53
|
}
|
54
|
return getTerms().get(termCode).getInverseCode();
|
55
|
}
|
56
|
|
57
|
public String inverseOf(final RelDescriptor rd) {
|
58
|
if (getTerms() == null || !getTerms().containsKey(rd.getRelClass())) {
|
59
|
return null;
|
60
|
}
|
61
|
return getTerms().get(rd.getRelClass()).getInverseCode();
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
public String toString() {
|
66
|
return new Gson().toJson(this);
|
67
|
}
|
68
|
|
69
|
}
|