1   /* Ontology.java
2    *
3    * Copyright (c) 1998-2005, The University of Sheffield.
4    *
5    * This file is part of GATE (see http://gate.ac.uk/), and is free
6    * software, licenced under the GNU Library General Public License,
7    * Version 2, June1991.
8    *
9    * A copy of this licence is included in the distribution in the file
10   * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
11   *
12   * Kalina Bontcheva 03/2003
13   *
14   *
15   *  $Id: Ontology.java,v 1.14 2005/12/14 14:28:58 julien_nioche Exp $
16   */
17  package gate.creole.ontology;
18  
19  import java.util.Set;
20  
21  /**
22   * This is the base interface for all concrete implementations of ontologies.
23   */
24  public interface Ontology extends Taxonomy {
25    /**
26     * Adds an instance to the ontology.
27     * 
28     * @param name
29     *          the name for the new instance
30     * @param theClass
31     *          the class to which the instance belongs
32     * @return the OInstance that has been added to the ontology
33     */
34    public OInstance addInstance(String name, OClass theClass);
35  
36    /**
37     * Adds a preconstructed instance to the ontology.
38     */
39    public void addInstance(OInstance theInstance);
40  
41    /**
42     * Removes the instance from the ontology.
43     * 
44     * @param theInstance
45     *          to be removed
46     */
47    public void removeInstance(OInstance theInstance);
48  
49    /**
50     * Gets all instances in the ontology.
51     * 
52     * @return a {@link Set} of OInstance objects
53     */
54    public Set getInstances();
55  
56    /**
57     * Gets all instances in the ontology, which belong to this class, including
58     * instances of sub-classes. If only the instances of the given class are
59     * needed, then use getDirectInstances.
60     * 
61     * @param theClass
62     *          the class of the instances
63     * @return {@link Set} of OInstance objects
64     */
65    public Set getInstances(OClass theClass);
66  
67    /**
68     * Gets all instances in the ontology, which belong to the given class only.
69     * 
70     * @param theClass
71     *          the class of the instances
72     * @return {@link Set} of OInstance objects
73     */
74    public Set getDirectInstances(OClass theClass);
75  
76    /**
77     * Gets the instance with the given name.
78     * 
79     * @param instanceName
80     *          the instance name
81     * @return the OInstance object with this name
82     */
83    public OInstance getInstanceByName(String instanceName);
84  
85    /**
86     * Creates a new Datatype property in this ontology where the domain consists
87     * of a single {@link OClass}.
88     * 
89     * @param name
90     *          the name for the new property.
91     * @param comment
92     *          the comment for the new property.
93     * @param domain
94     *          the {@link OClass} to which this property applies.
95     * @param range
96     *          the {@link Class} specifying the types of Java objects that this
97     *          property has as values.
98     * @return the newly created property.
99     */
100   public DatatypeProperty addDatatypeProperty(String name, String comment,
101           OClass domain, Class range);
102 
103   /**
104    * Create a DatatypeProperty with the given domain and range.
105    * 
106    * @param name
107    *          the name for the new property.
108    * @param comment
109    *          the comment for the new property.
110    * @param domain
111    *          the set of ontology classes (i.e. {@link OClass} objects} that
112    *          constitutes the range for the new property. The property only
113    *          applies to instances that belong to <b>all</b> classes included
114    *          in its domain. An empty set means that the property applies to
115    *          instances of any class.
116    * @param range
117    *          the {@link Class} specifying the types of Java objects that this
118    *          property has as values.
119    * @return the newly created property.
120    */
121   public DatatypeProperty addDatatypeProperty(String name, String comment,
122           Set domain, Class range);
123 
124   /**
125    * Creates a new generic property that is neither datatype or object property.
126    * This can be for instance a RDF property.
127    * 
128    * @param name
129    *          the name for the new property.
130    * @param comment
131    *          the comment for the new property.
132    * @param domain
133    *          the set of ontology classes (i.e. {@link OClass} objects} that
134    *          constitutes the range for the new property. The property only
135    *          applies to instances that belong to <b>all</b> classes included
136    *          in its domain. An empty set means that the property applies to
137    *          instances of any class.
138    * @param range
139    *          the set of ontology classes (i.e. {@link OClass} objects} that
140    *          constitutes the range for the new property.
141    * @return the newly created property.
142    */
143   public Property addProperty(String name, String comment, Set domain, Set range);
144 
145   /**
146    * Creates a new generic property that is neither datatype or object property.
147    * This can be for instance a RDF property.
148    * 
149    * @param name
150    *          the name for the new property.
151    * @param comment
152    *          the comment for the new property.
153    * @param domain
154    *          the {@link OClass} defining the type of instances this property
155    *          can apply to.
156    * @param range
157    *          Java {@link Class} defining the type of values this proeprty can
158    *          take.
159    * @return the newly created property.
160    */
161   public Property addProperty(String name, String comment, OClass domain,
162           Class range);
163 
164   /**
165    * Creates a new object property (a property that takes instances as values).
166    * 
167    * @param name
168    *          the name for the new property.
169    * @param comment
170    *          the comment for the new property.
171    * @param domain
172    *          the set of ontology classes (i.e. {@link OClass} objects} that
173    *          constitutes the range for the new property. The property only
174    *          applies to instances that belong to <b>all</b> classes included
175    *          in its domain. An empty set means that the property applies to
176    *          instances of any class.
177    * @param range
178    *          the set of ontology classes (i.e. {@link OClass} objects} that
179    *          constitutes the range for the new property.
180    * @return the newly created property.
181    */
182   public ObjectProperty addObjectProperty(String name, String comment,
183           Set domain, Set range);
184 
185   /**
186    * Creates a new object property (a property that takes instances as values).
187    * 
188    * @param name
189    *          the name for the new property.
190    * @param comment
191    *          the comment for the new property.
192    * @param domain
193    *          the {@link OClass} to which this property applies.
194    * @param range
195    *          the {@link OClass} specifying the types of instances that this
196    *          property can take as values.
197    * @return the newly created property.
198    */
199   public ObjectProperty addObjectProperty(String name, String comment,
200           OClass domain, OClass range);
201 
202   /**
203    * Creates a new symmetric property (an object property that is symmetric).
204    * 
205    * @param name
206    *          the name for the new property.
207    * @param comment
208    *          the comment for the new property.
209    * @param domain
210    *          the set of ontology classes (i.e. {@link OClass} objects} that
211    *          constitutes the range for the new property. The property only
212    *          applies to instances that belong to <b>all</b> classes included
213    *          in its domain. An empty set means that the property applies to
214    *          instances of any class.
215    * @param range
216    *          the set of ontology classes (i.e. {@link OClass} objects} that
217    *          constitutes the range for the new property.
218    * @return the newly created property.
219    */
220   public SymmetricProperty addSymmetricProperty(String name, String comment,
221           Set domain, Set range);
222 
223   /**
224    * Creates a new symmetric property.
225    * 
226    * @param name
227    *          the name for the new property.
228    * @param comment
229    *          the comment for the new property.
230    * @param domain
231    *          the {@link OClass} to which this property applies.
232    * @param range
233    *          the {@link OClass} specifying the types of instances that this
234    *          property can take as values.
235    * @return the newly created property.
236    */
237   public SymmetricProperty addSymmetricProperty(String name, String comment,
238           OClass domain, OClass range);
239 
240   /**
241    * Creates a new transitive property (an object property that is transitive).
242    * 
243    * @param name
244    *          the name for the new property.
245    * @param comment
246    *          the comment for the new property.
247    * @param domain
248    *          the set of ontology classes (i.e. {@link OClass} objects} that
249    *          constitutes the range for the new property. The property only
250    *          applies to instances that belong to <b>all</b> classes included
251    *          in its domain. An empty set means that the property applies to
252    *          instances of any class.
253    * @param range
254    *          the set of ontology classes (i.e. {@link OClass} objects} that
255    *          constitutes the range for the new property.
256    * @return the newly created property.
257    */
258   public TransitiveProperty addTransitiveProperty(String name, String comment,
259           Set domain, Set range);
260 
261   /**
262    * Creates a new transitive property.
263    * 
264    * @param name
265    *          the name for the new property.
266    * @param comment
267    *          the comment for the new property.
268    * @param domain
269    *          the {@link OClass} to which this property applies.
270    * @param range
271    *          the {@link OClass} specifying the types of instances that this
272    *          property can take as values.
273    * @return the newly created property.
274    */
275   public TransitiveProperty addTransitiveProperty(String name, String comment,
276           OClass domain, OClass range);
277 
278   /**
279    * Gets the set of all known property definitions in this ontology.
280    * 
281    * @return a {@link Set} of {@link Property} objects.
282    */
283   public Set getPropertyDefinitions();
284 
285   /**
286    * Returns the property definition for a given property.
287    * 
288    * @param name
289    *          the name for which the definition is sought.
290    * @return a{@link Property} object.
291    */
292   public Property getPropertyDefinitionByName(String name);
293 }