source: TraumaOntologies/src/main/java/tudelft/healthpsychology/traumaontologies/owltree/OWLProperty.java@ 7

Last change on this file since 7 was 4, checked in by Bart Vastenhouw, 5 years ago

Added traumaontologies

File size: 3.5 KB
Line 
1package tudelft.healthpsychology.traumaontologies.owltree;
2
3import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
4
5import com.fasterxml.jackson.annotation.JsonCreator;
6import com.fasterxml.jackson.annotation.JsonProperty;
7
8import tudelft.healthpsychology.traumaontologies.answerstate.Property;
9import tudelft.healthpsychology.traumaontologies.questiontypes.Bool;
10import tudelft.healthpsychology.traumaontologies.questiontypes.Int;
11import tudelft.healthpsychology.traumaontologies.questiontypes.QuestionType;
12import tudelft.healthpsychology.traumaontologies.questiontypes.Text;
13import uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyImpl;
14
15/**
16 * adapter for {@link OWLDataPropertyDomainAxiom} that makes it conform our
17 * abstractionlayer {@link Property}. immutable.
18 */
19public class OWLProperty implements Property {
20
21 private final String range;
22 private final String comment;
23 private final String id; // must be unique for each property.
24
25 /**
26 * @param range the indicated range of the property. Allowed are
27 * http://www.w3.org/2001/XMLSchema#boolean,
28 * http://www.w3.org/2001/XMLSchema#int or
29 * http://www.w3.org/2001/XMLSchema#string
30 * @param comment the comment text attached to the property.
31 * @param id unique ID referring to the OWL file property ID
32 */
33 @JsonCreator
34 public OWLProperty(@JsonProperty("range") String range,
35 @JsonProperty("comment") String comment,
36 @JsonProperty("id") String id) {
37 this.range = range;
38 this.comment = comment;
39 this.id = id;
40 }
41
42 /**
43 * Convenience constructor that uses the OWL objects.
44 *
45 * @param dp a specific property like #Locatie_meubel
46 * @param reasoner our reasoner
47 */
48 public OWLProperty(OWLDataPropertyDomainAxiom axiom,
49 OwlTreeReasoner reasoner) {
50 this(reasoner.getRange(axiom), reasoner.getComment(axiom),
51 ((OWLDataPropertyImpl) axiom.getProperty()).getIRI()
52 .getFragment());
53 }
54
55 @Override
56 public QuestionType getQuestionType() {
57 return createAnswer(range, comment, id);
58 }
59
60 @Override
61 public String toString() {
62 return "OWLProperty[" + id + "," + comment + "]";
63 }
64
65 /**
66 * Factory method, mainly for testing this. See
67 * {@link QuestionTypeFactory#create(String, String)}
68 *
69 * @param type the type as in the range field of the owl file:
70 * http://www.w3.org/2001/XMLSchema#string, #int and
71 * #boolean
72 * @param question the question string, typically as in the comment field of
73 * the owl file.
74 * @param id the node id
75 * @return a proper answertype for this question and type
76 */
77 protected QuestionType createAnswer(String type, String question,
78 String id) {
79 switch (type) {
80 case "http://www.w3.org/2001/XMLSchema#boolean":
81 return new Bool(question, id);
82 case "http://www.w3.org/2001/XMLSchema#int":
83 return new Int(question, id);
84
85 case "http://www.w3.org/2001/XMLSchema#string":
86 return new Text(question, id);
87 default:
88 throw new IllegalArgumentException(
89 "Unknown/Unsupported type: " + type);
90 }
91 }
92
93 @Override
94 public int hashCode() {
95 final int prime = 31;
96 int result = 1;
97 result = prime * result + ((id == null) ? 0 : id.hashCode());
98 return result;
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj)
104 return true;
105 if (obj == null)
106 return false;
107 if (getClass() != obj.getClass())
108 return false;
109 OWLProperty other = (OWLProperty) obj;
110 if (id == null) {
111 if (other.id != null)
112 return false;
113 } else if (!id.equals(other.id))
114 return false;
115 return true;
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.