package tudelft.healthpsychology.traumaontologies.owltree; import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import tudelft.healthpsychology.traumaontologies.answerstate.Property; import tudelft.healthpsychology.traumaontologies.questiontypes.Bool; import tudelft.healthpsychology.traumaontologies.questiontypes.Int; import tudelft.healthpsychology.traumaontologies.questiontypes.Text; import tudelft.healthpsychology.traumaontologies.questiontypes.TypedQuestion; import uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyImpl; /** * adapter for {@link OWLDataPropertyDomainAxiom} that makes it conform our * abstractionlayer {@link Property}. immutable. */ public class OwlProperty implements Property { private final String range; private final String comment; private final String id; // must be unique for each property. /** * @param range the indicated range of the property. Allowed are * http://www.w3.org/2001/XMLSchema#boolean, * http://www.w3.org/2001/XMLSchema#int or * http://www.w3.org/2001/XMLSchema#string * @param comment the comment text attached to the property. * @param id unique ID referring to the OWL file property ID */ @JsonCreator public OwlProperty(@JsonProperty("range") String range, @JsonProperty("comment") String comment, @JsonProperty("id") String id) { this.range = range; this.comment = comment; this.id = id; } /** * Convenience constructor that uses the OWL objects. * * @param dp a specific property like #Locatie_meubel * @param reasoner our reasoner */ public OwlProperty(OWLDataPropertyDomainAxiom axiom, OwlTreeReasoner reasoner) { this(reasoner.getRange(axiom), reasoner.getComment(axiom), ((OWLDataPropertyImpl) axiom.getProperty()).getIRI() .getFragment()); } @Override public TypedQuestion getQuestionType() { return createAnswer(range, comment, id); } @Override public String toString() { return "OWLProperty[" + id + "," + comment + "]"; } /** * Factory method, mainly for testing this. See * {@link QuestionTypeFactory#create(String, String)} * * @param type the type as in the range field of the owl file: * http://www.w3.org/2001/XMLSchema#string, #int and * #boolean * @param question the question string, typically as in the comment field of * the owl file. * @param id the node id * @return a proper answertype for this question and type */ protected TypedQuestion createAnswer(String type, String question, String id) { switch (type) { case "http://www.w3.org/2001/XMLSchema#boolean": return new Bool(question, id); case "http://www.w3.org/2001/XMLSchema#int": return new Int(question, id); case "http://www.w3.org/2001/XMLSchema#string": return new Text(question, id); default: throw new IllegalArgumentException( "Unknown/Unsupported type: " + type); } } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; OwlProperty other = (OwlProperty) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }