| ObjectPropertyImpl.java |
1 /*
2 * ObjectPropertyImpl.java
3 *
4 * Copyright (c) 2002, The University of Sheffield.
5 *
6 * This file is part of GATE (see http://gate.ac.uk/), and is free
7 * software, licenced under the GNU Library General Public License,
8 * Version 2, June1991.
9 *
10 * A copy of this licence is included in the distribution in the file
11 * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
12 *
13 * Kalina Bontcheva 11/2003
14 *
15 *
16 * $Id: ObjectPropertyImpl.java,v 1.7 2005/12/14 14:28:58 julien_nioche Exp $
17 */
18 package gate.creole.ontology;
19
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Set;
23 import com.ontotext.gate.ontology.OntologyImpl;
24
25 public class ObjectPropertyImpl extends PropertyImpl implements ObjectProperty {
26 protected Set inversePropertiesSet;
27
28 /**
29 * Convenience constructor for simple cases where the domain and range are
30 * single classes.
31 *
32 * @param aName
33 * the name of the property.
34 * @param aDomainClass
35 * the class representing the domain.
36 * @param aRange
37 * the class representing the range.
38 * @param anOntology
39 * the ontology this property belongs to.
40 */
41 public ObjectPropertyImpl(String name, String comment, OClass aDomainClass,
42 OClass aRange, Ontology anOntology) {
43 super(name, comment, aDomainClass, aRange, anOntology);
44 inversePropertiesSet = new HashSet();
45 }
46
47 /**
48 * Constructor for this property.
49 *
50 * @param aName
51 * the name of the property.
52 * @param aDomain
53 * the set of domain restrictions for this property. A set of
54 * {@link OClass} values.
55 * @param aRange
56 * the set of range restrictions for this property. A set of
57 * {@link OClass} values.
58 * @param anOntology
59 * the ontology this property belongs to.
60 */
61 public ObjectPropertyImpl(String name, String comment, Set aDomain,
62 Set aRange, Ontology anOntology) {
63 super(name, comment, aDomain, aRange, anOntology);
64 inversePropertiesSet = new HashSet();
65 }
66
67 public void addSuperProperty(Property property) {
68 super.addSuperProperty(property);
69 // add restrictions from super-property to the range set
70 range.addAll(property.getRange());
71 OntologyImpl.reduceToMostSpecificClasses(range);
72 // propagate the changes to sub properties
73 Iterator subPropIter = getSubProperties(TRANSITIVE_CLOSURE).iterator();
74 while(subPropIter.hasNext()) {
75 Property aSubProperty = (Property)subPropIter.next();
76 if(aSubProperty instanceof ObjectPropertyImpl) {
77 ((ObjectPropertyImpl)aSubProperty).recalculateRange();
78 }
79 }
80 }
81
82 /**
83 * @param instance
84 * @return true if this value is compatible with the range restrictions on the
85 * property. False otherwise.
86 */
87 public boolean isValidRange(OInstance instance) {
88 return super.isValidRange(instance);
89 }
90
91 public Set getRange() {
92 return range;
93 }
94
95 public Set getInverseProperties() {
96 return this.inversePropertiesSet;
97 }
98
99 public void setInverseOf(Property theInverse) {
100 this.inversePropertiesSet.add(theInverse);
101 }
102 }